MDL-48829 quiz nav: add a data attr to buttons giving the page

This way, if you need to know which page each button goes to in
JavaScript, you can find out.
This commit is contained in:
Tim Hunt
2015-01-15 10:20:55 +00:00
parent da0ef2e4cf
commit 2e4e8d16c7
2 changed files with 16 additions and 6 deletions
+11 -1
View File
@@ -1683,12 +1683,21 @@ class quiz_attempt {
* @since Moodle 2.1
*/
class quiz_nav_question_button implements renderable {
/** @var string id="..." to add to the HTML for this button. */
public $id;
/** @var string number to display in this button. Either the question number of 'i'. */
public $number;
/** @var string class to add to the class="" attribute to represnt the question state. */
public $stateclass;
/** @var string Textual description of the question state, e.g. to use as a tool tip. */
public $statestring;
/** @var int the page number this question is on. */
public $page;
/** @var bool true if this question is on the current page. */
public $currentpage;
/** @var bool true if this question has been flagged. */
public $flagged;
/** @var moodle_url the link this button goes to, or null if there should not be a link. */
public $url;
}
@@ -1734,7 +1743,8 @@ abstract class quiz_nav_panel_base {
$button->stateclass = 'complete';
}
$button->statestring = $this->get_state_string($qa, $showcorrectness);
$button->currentpage = $this->showall || $this->attemptobj->get_question_page($slot) == $this->page;
$button->page = $this->attemptobj->get_question_page($slot);
$button->currentpage = $this->showall || $button->page == $this->page;
$button->flagged = $qa->is_flagged();
$button->url = $this->get_question_url($slot);
$buttons[] = $button;
+5 -5
View File
@@ -335,11 +335,11 @@ class mod_quiz_renderer extends plugin_renderer_base {
*/
protected function render_quiz_nav_question_button(quiz_nav_question_button $button) {
$classes = array('qnbutton', $button->stateclass, $button->navmethod);
$attributes = array();
$extrainfo = array();
if ($button->currentpage) {
$classes[] = 'thispage';
$attributes[] = get_string('onthispage', 'quiz');
$extrainfo[] = get_string('onthispage', 'quiz');
}
// Flagged?
@@ -349,7 +349,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
} else {
$flaglabel = '';
}
$attributes[] = html_writer::tag('span', $flaglabel, array('class' => 'flagstate'));
$extrainfo[] = html_writer::tag('span', $flaglabel, array('class' => 'flagstate'));
if (is_numeric($button->number)) {
$qnostring = 'questionnonav';
@@ -359,12 +359,12 @@ class mod_quiz_renderer extends plugin_renderer_base {
$a = new stdClass();
$a->number = $button->number;
$a->attributes = implode(' ', $attributes);
$a->attributes = implode(' ', $extrainfo);
$tagcontents = html_writer::tag('span', '', array('class' => 'thispageholder')) .
html_writer::tag('span', '', array('class' => 'trafficlight')) .
get_string($qnostring, 'quiz', $a);
$tagattributes = array('class' => implode(' ', $classes), 'id' => $button->id,
'title' => $button->statestring);
'title' => $button->statestring, 'data-quiz-page' => $button->page);
if ($button->url) {
return html_writer::link($button->url, $tagcontents, $tagattributes);