]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6194 @4:00 compte à rebours
authorsoufiane <soufiane@cubedesigners.com>
Mon, 21 Aug 2023 17:49:33 +0000 (19:49 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 21 Aug 2023 17:49:33 +0000 (19:49 +0200)
js/quiz.countdown.js [new file with mode: 0644]
js/quiz.js
js/quiz.screens.js
views/footer.blade.php

diff --git a/js/quiz.countdown.js b/js/quiz.countdown.js
new file mode 100644 (file)
index 0000000..d5864f0
--- /dev/null
@@ -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;
index ace99fc0b158db789884449c9508ee4fc3511a90..5ed1d1ed544f0975022336cfa20b0fd56380b5de 100644 (file)
@@ -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 () {
 
     }
index 300af609c1595ba0f7be19860115021dafbdb66a..30fd1232e03562e06a7477854f2e67697bdda945 100644 (file)
@@ -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;
index 27cf49bb1fffff878f5f33e5079ad45f1c7c781f..f630c6a90798e058ef9ebdf3edc902bc53ed367b 100644 (file)
@@ -5,7 +5,7 @@
             <span class="access">R</span>
         </a>
     @endisset
-    <a class="btn primary action validate" aria-keyshortcuts="Space">
+    <a class="btn primary action validate {{$question['countdown_enable'] ? 'countdown' : ''}}" aria-keyshortcuts="Space">
         <span class="text">Validate answer</span>
         <span class="access space">space</span>
         @isset($time)