You are here

function theme_quiz_jumper in Quiz 7.4

Same name and namespace in other branches
  1. 8.4 quiz.pages.inc \theme_quiz_jumper()
  2. 6.4 quiz.pages.inc \theme_quiz_jumper()
  3. 7 quiz.pages.inc \theme_quiz_jumper()

@todo Please document this function.

See also

http://drupal.org/node/1354

1 theme call to theme_quiz_jumper()
theme_quiz_progress in ./quiz.pages.inc
Theme a progress indicator for use during a quiz.

File

./quiz.pages.inc, line 500
User pages.

Code

function theme_quiz_jumper($variables) {
  $current = $variables['current'];
  $num_questions = $variables['num_questions'];
  $output = '<select name="quiz-jumper" class="form-select" id="quiz-jumper">';
  for ($i = 1; $i <= $num_questions; $i++) {
    $extra = $i == $current ? ' selected="selected"' : '';
    $output .= '<option value="' . $i . '"' . $extra . '>' . $i . '</option>';
  }
  $output .= '</select><span id="quiz-jumper-no-js">' . $current . '</span>';
  drupal_add_js('
    (function ($) {
      Drupal.behaviors.quizJumper = {
        attach: function(context, settings) {
          $("#quiz-jumper:not(.quizJumper-processed)", context).show().addClass("quizJumper-processed").change(function(){
            $("[name=jump_to_question]").val($(this).val());
            $("#edit-submit").trigger("click");
          });
          $("#quiz-jumper-no-js:not(.quizJumper-processed)").hide().addClass("quizJumper-processed");
        }
      };
    })(jQuery);
  ', array(
    'type' => 'inline',
    'scope' => JS_DEFAULT,
  ));
  return $output;
}