Hello,

When you put the code "print $scripts;" at the end of page.tpl.php template for improving performance on a client side, there is a javascript error "Drupal is not defined".

The problem is the multichoice-alternative.tpl.php template where there is the add script for using the entire alternative row as a button.

To avoid this problem my solution is to move the template code multichoice-alternative.tpl.php line 19-37 in a file in the same place multichoice.js.

The new template-multichoice alternative.tpl.php is (line 13-18):

<?php
$p = drupal_get_path('module', 'multichoice');
drupal_add_css($p .'/theme/multichoice.css', 'module', 'all');

// Add script for using the entire alternative row as a button
drupal_add_js($p .'/theme/multichoice.js', 'module');

The file is multichoice.js:

Drupal.behaviors.multichoiceAlternativeBehavior = function(context) {
  $('.multichoice_row')
  .filter(':has(:checkbox:checked)')
  .addClass('selected')
  .end()
  .click(function(event) {
    $(this).toggleClass('selected');
    if (event.target.type !== 'checkbox') {
      $(':checkbox', this).attr('checked', function() {
        return !this.checked;
      });
      $(':radio', this).attr('checked', true);
      if ($(':radio', this).html() != null) {
        $('.multichoice_row').removeClass('selected');
    	  $(this).addClass('selected');
      }
    }
  });
};

Regards

Matthieu

PS: Sorry for my english

Comments

xMATTx’s picture

Otherwise, another solution inline javascript without having to create a new javascript file.

The new template multichoice-alternative.tpl.php is:

// Add script for using the entire alternative row as a button
$js = "Drupal.behaviors.multichoiceAlternativeBehavior = function(context) {
  $('.multichoice_row')
  .filter(':has(:checkbox:checked)')
  .addClass('selected')
  .end()
  .click(function(event) {
    $(this).toggleClass('selected');
    if (event.target.type !== 'checkbox') {
      $(':checkbox', this).attr('checked', function() {
        return !this.checked;
      });
      $(':radio', this).attr('checked', true);
      if ($(':radio', this).html() != null) {
        $('.multichoice_row').removeClass('selected');
    	  $(this).addClass('selected');
      }
    }
  });
};";
drupal_add_js($js, 'inline');
falcon’s picture

Thanks! This has been commitet.

falcon’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.