MDL-77127 quiz: allow students to hide timer

This commit is contained in:
Philipp Imhof 2023-09-11 21:30:25 +02:00
parent b4c6ed3650
commit f85aa04def
No known key found for this signature in database
GPG Key ID: B0855563879F8BC9
3 changed files with 34 additions and 0 deletions

View File

@ -1620,6 +1620,8 @@ function quiz_get_js_module() {
['functiondisabledbysecuremode', 'quiz'],
['startattempt', 'quiz'],
['timesup', 'quiz'],
['show', 'moodle'],
['hide', 'moodle'],
],
];
}

View File

@ -82,6 +82,34 @@ M.mod_quiz.timer = {
require(['core_form/changechecker'], function(FormChangeChecker) {
M.mod_quiz.timer.FormChangeChecker = FormChangeChecker;
});
Y.one('#toggle-timer').on('click', function() {
M.mod_quiz.timer.toggleVisibility();
});
},
/**
* Hide or show the timer.
* @param {boolean} whether we are ultimately displaying the timer and disabling the button
*/
toggleVisibility: function(finalShow = false) {
var Y = M.mod_quiz.timer.Y;
var timer = Y.one('#quiz-time-left');
var button = Y.one('#toggle-timer');
// When time is running out, we show the timer and disable the button.
if (finalShow) {
timer.show();
button.setContent(M.util.get_string('hide', 'moodle'));
button.setAttribute('disabled', true);
return;
}
timer.toggleView();
if (timer.getAttribute('hidden') === 'hidden') {
button.setContent(M.util.get_string('show', 'moodle'));
} else {
button.setContent(M.util.get_string('hide', 'moodle'));
}
},
/**
@ -129,6 +157,7 @@ M.mod_quiz.timer = {
Y.one('#quiz-timer').removeClass('timeleft' + (secondsleft + 2))
.removeClass('timeleft' + (secondsleft + 1))
.addClass('timeleft' + secondsleft);
M.mod_quiz.timer.toggleVisibility(true);
}
// Update the time display.

View File

@ -28,4 +28,7 @@
{{#str}} timeleft, quiz {{/str}}
<span id="quiz-time-left"></span>
</div>
<button type="button" class="btn btn-secondary btn-small" id="toggle-timer" aria-controls="quiz-timer" aria-describedby="quiz-timer">
{{#str}} hide, core {{/str}}
</button>
</div>