function theme_multichoice_alternative in Quiz 8.4
1 theme call to theme_multichoice_alternative()
- MultichoiceQuestion::getAnsweringForm in question_types/
multichoice/ lib/ Drupal/ multichoice/ MultichoiceQuestion.php - Generates the question form.
File
- question_types/
multichoice/ multichoice.theme.inc, line 178 - The theme file for multichoice.
Code
function theme_multichoice_alternative($variables) {
$form = $variables['form'];
$output = '';
$p = drupal_get_path('module', 'multichoice');
drupal_add_css($p . '/css/multichoice.css');
// Add script for using the entire alternative row as a button
drupal_add_js("(function(\$) {\n Drupal.behaviors.multichoiceAlternativeBehavior = {\n attach: function(context, settings) {\n \$('.multichoice_row')\n .once()\n .filter(':has(:checkbox:checked)')\n .addClass('selected')\n .end()\n .click(function(event) {\n \$(this).toggleClass('selected');\n if (event.target.type !== 'checkbox') {\n \$(':checkbox', this).attr('checked', function() {\n return !this.checked;\n });\n \$(':radio', this).attr('checked', true);\n if (\$(':radio', this).html() != null) {\n \$('.multichoice_row').removeClass('selected');\n \$(this).addClass('selected');\n }\n }\n });\n }\n };\n })(jQuery);", 'inline');
// We want to have the checkbox in one table cell, and the title in the next. We store the checkbox and the titles
$options = $form['#options'];
$fullOptions = array();
$titles = array();
foreach ($options as $key => $value) {
$fullOptions[$key] = $form[$key];
$titles[$key] = $form[$key]['#title'];
$fullOptions[$key]['#title'] = '';
unset($form[$key]);
}
unset($form['#options']);
$output .= drupal_render_children($form);
// We use the stored checkboxes and titles to generate a table for the alternatives
foreach ($titles as $key => $value) {
$row = array();
$row[] = array(
'data' => drupal_render($fullOptions[$key]),
'width' => 35,
'class' => 'selector-td',
);
$row[] = $value;
$rows[] = array(
'data' => $row,
'class' => array(
'multichoice_row',
),
);
}
$output .= theme('table', array(
'header' => array(),
'rows' => $rows,
));
return $output;
}