From: soufiane Date: Mon, 21 Aug 2023 17:49:33 +0000 (+0200) Subject: wip #6194 @4:00 compte à rebours X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f04de30c7b8dc9f2a13f4cc354a57530a6c4b10d;p=fluidbook-toolbox-quiz.git wip #6194 @4:00 compte à rebours --- diff --git a/js/quiz.countdown.js b/js/quiz.countdown.js new file mode 100644 index 0000000..d5864f0 --- /dev/null +++ b/js/quiz.countdown.js @@ -0,0 +1,13 @@ +import QuizQuestion from "./quiz.question"; + +function QuizCountdown(quiz) { + this.quiz = quiz; + this.question = new QuizQuestion() + this.intervalCountDown = false +} + +QuizCountdown.prototype = { + +} + +export default QuizCountdown; diff --git a/js/quiz.js b/js/quiz.js index ace99fc..5ed1d1e 100644 --- a/js/quiz.js +++ b/js/quiz.js @@ -17,6 +17,7 @@ window.cubeSCORM = new CubeSCORM(); window.$ = window.jQuery = $; import ResizeObserver from 'resize-observer-polyfill'; +import QuizCountdown from "./quiz.countdown"; window.ResizeObserver = ResizeObserver; @@ -46,10 +47,6 @@ Quiz.prototype = { // ICI tout commence vraiment console.log(this.data.theme) - this.timeoutAnimation = false - this.intervalCountDown = false - this.timeoutCountdown = false - // $("#quiz").css("background-image", "url(" + this.data.theme.backgroundImage + ")") @@ -88,25 +85,6 @@ Quiz.prototype = { this.resize.resize(); }, - countdown: function(res) { - const time = this.question.current().countdown_time*1000 - if(this.question.current().countdown_enable) { - let value = 100 - let this_ = this - this.intervalCountDown = setInterval(function () { - value -= (10 / time) * 100 - document.documentElement.style.setProperty("--width-bg-countdown", value + "%") - }, 10) - - this.timeoutCountdown = setTimeout(function () { - clearInterval(this_.intervalCountDown) - this_.validateResponse(res); - this_.updateBtnValidation("validated") - return false - }, time) - } - }, - restart: function () { } diff --git a/js/quiz.screens.js b/js/quiz.screens.js index 300af60..30fd123 100644 --- a/js/quiz.screens.js +++ b/js/quiz.screens.js @@ -8,6 +8,7 @@ function QuizScreens(quiz) { this.activeScreen = null; this.currentQuestionAnswers = []; + this.intervalCountDown = 0; this.intro = new QuizScreenIntro(this); this.outro = new QuizScreenOutro(this); @@ -106,6 +107,7 @@ QuizScreens.prototype = { }, sendUserAnswers: function () { + clearInterval(this.intervalCountDown) return this.quiz.score.setAnswer(this.quiz.question.currentPosition(), this.currentQuestionAnswers) }, @@ -135,6 +137,12 @@ QuizScreens.prototype = { $this.resetForm(); $this.currentQuestionAnswers = []; $this.quiz.progressbar.update(); + + // if countdown enable + if(parseInt($this.quiz.question.current().countdown_enable)) { + $this.countdown() + } + if (screen === 'outro') { $this.outro.show(); } @@ -161,6 +169,7 @@ QuizScreens.prototype = { * @param callback */ hideCurrentScreen: function (callback) { + const $this = this; let cb = function (screen) { if (screen.length > 0) { $(screen).removeClass("next active-screen").addClass("none"); @@ -181,6 +190,31 @@ QuizScreens.prototype = { cb(currentScreen); } }, + + countdown: function() { + const $this = this; + const time = this.quiz.question.current().countdown_time*1000 + let value = 100 + this.intervalCountDown = setInterval(function () { + value -= (10 / time) * 100 + document.documentElement.style.setProperty("--width-bg-countdown", value + "%") + if(value <= 0) { + clearInterval($this.intervalCountDown) + /** + * + * provisoire + */ + let review = $this.sendUserAnswers(); + // Si la revue instantanée est activée, on affiche les résultats + if ($this.quiz.data.instantReview) { + $this.instantReview(review); + } else { + // Sinon, on passe directement à la question suivante + $this.nextQuestion(); + } + } + }, 10) + }, }; export default QuizScreens; diff --git a/views/footer.blade.php b/views/footer.blade.php index 27cf49b..f630c6a 100644 --- a/views/footer.blade.php +++ b/views/footer.blade.php @@ -5,7 +5,7 @@ R @endisset - + Validate answer space @isset($time)