}
protected function get_question_buttons() {
- $html = '<div class="qn_buttons">';
+ $html = '<div class="qn_buttons">' . "\n";
foreach ($this->attemptobj->get_question_iterator() as $number => $question) {
- $html .= $this->get_question_button($number, $question);
+ $html .= $this->get_question_button($number, $question) . "\n" .
+ $this->get_button_update_script($question) . "\n";
}
- $html .= '</div>';
+ $html .= "</div>\n";
return $html;
}
+ protected function get_button_id($question) {
+ // The id to put on the button element in the HTML.
+ return 'quiznavbutton' . $question->id;
+ }
+
+ protected function get_button_update_script($question) {
+ return '<script type="text/javascript">' .
+ "\nquiz_init_nav_button('" . $this->get_button_id($question) . "', " .
+ $question->id . ")\n</script>\n";
+ }
+
abstract protected function get_question_button($number, $question);
abstract protected function get_end_bits();
public function display() {
$strquiznavigation = get_string('quiznavigation', 'quiz');
- $content = $this->get_question_buttons() . '<div class="othernav">' .
- $this->get_end_bits() . '</div>';
+ $content = $this->get_question_buttons() . "\n" . '<div class="othernav">' .
+ "\n" . $this->get_end_bits() . "\n</div>\n";
print_side_block($strquiznavigation, $content, NULL, NULL, '', array('id' => 'quiznavigation'), $strquiznavigation);
}
}
}
return '<input type="submit" name="gotopage' . $question->_page .
'" value="' . $number . '" class="qnbutton ' .
- $this->get_question_state_classes($question) . '"' . $onclick . '/>';
+ $this->get_question_state_classes($question) . '" id="' .
+ $this->get_button_id($question) . '" ' . $onclick . '/>';
}
protected function get_end_bits() {
protected function get_question_button($number, $question) {
return '<a href="' . $this->attemptobj->review_url($question->id) .
- '" class="qnbutton ' . $this->get_question_state_classes($question) .
- '">' . $number . '</a>';
+ '" class="qnbutton ' . $this->get_question_state_classes($question) . '" id="' .
+ $this->get_button_id($question) . '">' . $number . '</a>';
}
protected function get_end_bits() {
}
}
+// Code for updating the countdown timer that is used on timed quizzes.
quiz_timer = {
// The outer div, so we can get at it to move it when the page scrolls.
timerouter: null,
}
};
+// Code for updating the navigation panel. At the moment it only updates
+// the flagged states of questions. This is a constructor, it takes
+function quiz_init_nav_button(buttonid, questionid) {
+ var button = document.getElementById(buttonid);
+ button.stateupdater = new quiz_nav_updater(button, questionid);
+}
+
+function quiz_nav_updater(element, questionid) {
+ this.element = element;
+ question_flag_changer.add_flag_state_listener(questionid, this);
+};
+
+quiz_nav_updater.prototype.flag_state_changed = function(newstate) {
+ this.element.className = this.element.className.replace(/\s*\bflagged\b\s*/, ' ');
+ if (newstate) {
+ this.element.className += ' flagged';
+ }
+};
+
quiz_secure_window = {
// The message displayed when the secure window interferes with the user.
protection_message: null,
// the require_js calls in get_html_head_contributions in lib/questionlib.php.
question_flag_changer = {
+ flag_state_listeners: new Object(),
+
init_flag: function(checkboxid, postdata) {
var checkbox = document.getElementById(checkboxid);
checkbox.ajaxpostdata = postdata;
checkbox.className += ' jsworking';
question_flag_changer.update_image(checkbox);
YAHOO.util.Event.addListener(checkbox, 'change', this.checkbox_state_change);
- YAHOO.util.Event.addListener(checkbox, 'focus', 'blur()');
},
checkbox_state_change: function(e) {
postdata += '&newstate=0'
}
YAHOO.util.Connect.asyncRequest('POST', qengine_config.wwwroot + '/question/toggleflag.php', null, postdata);
+ question_flag_changer.fire_state_changed(checkbox);
},
update_image: function(checkbox) {
img.alt = qengine_config.unflaggedalt;
img.title = qengine_config.flagtooltip;
}
+ },
+
+ add_flag_state_listener: function(questionid, listener) {
+ var key = 'q' + questionid;
+ if (!question_flag_changer.flag_state_listeners.hasOwnProperty(key)) {
+ question_flag_changer.flag_state_listeners[key] = [];
+ }
+ question_flag_changer.flag_state_listeners[key].push(listener);
+ },
+
+ questionid_from_cbid: function(cbid) {
+ return cbid.replace(/resp(\d+)__flagged/, '$1');
+ },
+
+ fire_state_changed: function(checkbox) {
+ var questionid = question_flag_changer.questionid_from_cbid(checkbox.id);
+ var key = 'q' + questionid;
+ if (!question_flag_changer.flag_state_listeners.hasOwnProperty(key)) {
+ return;
+ }
+ var newstate = checkbox.checked;
+ for (var i = 0; i < question_flag_changer.flag_state_listeners[key].length; i++) {
+ question_flag_changer.flag_state_listeners[key][i].flag_state_changed(newstate);
+ }
}
};