From e0b8adbb9894d41435fdb183cfa4649f2b8b6e7e Mon Sep 17 00:00:00 2001 From: Philipp Imhof <52650214+PhilippImhof@users.noreply.github.com> Date: Fri, 3 Nov 2023 21:51:03 +0100 Subject: [PATCH] MDL-74378 mod_quiz: make sure timer is initialized --- mod/quiz/module.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mod/quiz/module.js b/mod/quiz/module.js index db7d3eda872..9078fcbac43 100644 --- a/mod/quiz/module.js +++ b/mod/quiz/module.js @@ -149,6 +149,13 @@ M.mod_quiz.timer = { updateEndTime: function(timeleft) { var newtimeleft = new Date().getTime() + timeleft * 1000; + // Timer might not have been initialized yet. We initialize it with + // preview = 0, because it's better to take a preview for a real quiz + // than to take a real quiz for a preview. + if (M.mod_quiz.timer.Y === null) { + M.mod_quiz.timer.init(window.Y, timeleft, 0); + } + // Only update if change is greater than the threshold, so the // time doesn't bounce around unnecessarily. if (Math.abs(newtimeleft - M.mod_quiz.timer.endtime) > M.mod_quiz.timer.threshold) {