]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6194 @3:00 compte à rebours
authorsoufiane <soufiane@cubedesigners.com>
Mon, 21 Aug 2023 14:47:22 +0000 (16:47 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 21 Aug 2023 14:47:22 +0000 (16:47 +0200)
js/quiz.js
js/quiz.question.js
style/005-utilities.sass
style/100-global.sass
views/footer.blade.php

index 10dafa22b9f6d113c21f5a598c20ff1aad0dac33..1ba8e341ac9af5c3d3861a7a5ad626937ee003a8 100644 (file)
@@ -46,6 +46,8 @@ Quiz.prototype = {
         console.log(this.data.theme)
 
         this.timeoutAnimation = false
+        this.intervalCountDown = false
+        this.timeoutCountdown = false
 
         // commencer
         $(document).on("click", "#start", function() {
@@ -186,7 +188,9 @@ Quiz.prototype = {
         // dont miss to add this second condition
         if($(".active-screen form").length > 0) {
             if(status.length > 0) {
-                if(status[this.question.currentPosition()].ok === "not answered") {
+                if(status[$(".active-screen").data("position")].ok === "not answered") {
+                    clearInterval(this.intervalCountDown)
+                    clearTimeout(this.timeoutCountdown)
                     this.validateResponse(responses);
                     this.updateBtnValidation("validated")
                     return false
@@ -200,9 +204,12 @@ Quiz.prototype = {
         // pour récupérer le premier enfant de la nav
         this.activeNav(  (parseInt(this.question.currentPosition())+1)  )
         this.updateBtnValidation()
+        //
         // si c'est la dernière question a été validée alors on affiche le résultat au prochain screen
         if(this.question.last(currentPosition)) {
             this.result()
+        }else {
+            this.countdown(responses)
         }
     },
 
@@ -351,6 +358,25 @@ Quiz.prototype = {
         const simpleBar = new SimpleBar($ul.get(0))
     },
 
+    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 f659d07e05fddaa8e2224f047ad3b88601bb66b0..f60aff95c287cc84e2c9338f481270ac488dc206 100644 (file)
@@ -17,7 +17,7 @@ QuizQuestion.prototype = {
     },
 
     currentPosition: function() {
-        return $(document).find(".active-screen").data("position");
+        return quiz.score.lastAnsweredQuestion + 1;
     },
 
     current: function() {
index adc845c6b77509b733ff36788534274f23134ffd..6cb18aa9f07a4c20c803ae83b363597c3cc72a83 100644 (file)
@@ -9,4 +9,5 @@
 
 \:root
     --space-21-66: clamp(1.31rem, calc(0.29rem + 5.11vw), 4.13rem)
+    --width-bg-countdown: 100%
 
index 8707185a0ebdc4eac6ed297882e8c6c716a3ef42..41401db2d192708c1af3e138e10bbaf3d34219f7 100644 (file)
@@ -36,9 +36,21 @@ body
     &.primary
         background: radial-gradient(at 16% 6px, rgb(255, 102, 186) -7%, #D0167C 74%)
         box-shadow: 0 4px 6px rgba(0,0,0,.2)
+        overflow: hidden
+        &.countdown
+            &:after
+                content: ""
+                width: var(--width-bg-countdown)
+                height: 100%
+                position: absolute
+                right: 0
+                top: 0
+                background-color: #E062A8
         +below(993px)
             flex: 1
             margin-left: 16px
+        span
+            z-index: 1
     &.secondary
         +opacity(.16)
         padding-left: 22px
index bcadcbaa49674b1cd73db1ee5125dfc3c780bd28..32d90e35cb4c98eef34b131989ecb407ae163b9c 100644 (file)
@@ -5,7 +5,7 @@
             <span class="access">R</span>
         </a>
     @endisset
-    <a class="btn primary action" data-validation-text="Validate answer" data-continue-text="Continue">
+    <a class="btn primary action {{$data['countdown_enable'] ? 'countdown' : ''  }}" data-validation-text="Validate answer" data-continue-text="Continue">
         <span class="text">{{$text}}</span>
         <span class="access space">space</span>
         @isset($time)