]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6342
authorsoufiane <soufiane@cubedesigners.com>
Thu, 5 Oct 2023 16:04:29 +0000 (18:04 +0200)
committersoufiane <soufiane@cubedesigners.com>
Thu, 5 Oct 2023 16:04:29 +0000 (18:04 +0200)
js/quiz.accessibility.js
js/quiz.screens.js

index c0380fc9c565bd2c7ac22bd55eaafa2605fd6357..37b0c5eab6aa5bcf13a1018becc004bf8003dd8a 100644 (file)
@@ -8,17 +8,19 @@ QuizAccessibility.prototype = {
     initShortcuts: function () {
         let $this = this;
         $(document).on('keyup', function (e) {
-            let key = e.key.toLocaleUpperCase();
-            if (key === ' ') {
-                key = 'Space';
-            }
-
-            $('[aria-keyshortcuts="' + key + '"]').each(function () {
-                if ($this.quiz.utils.isEnabled($(this))) {
-                    $(this).get(0).click();
-                    return true;
+            if($("textarea:focus,input:focus").length < 1) {
+                let key = e.key.toLocaleUpperCase();
+                if (key === ' ') {
+                    key = 'Space';
                 }
-            });
+
+                $('[aria-keyshortcuts="' + key + '"]').each(function () {
+                    if ($this.quiz.utils.isEnabled($(this))) {
+                        $(this).get(0).click();
+                        return true;
+                    }
+                });
+            }
         });
     },
 }
index dbdc84d9315720607cf571ef86422d516eaa0b47..f90791bdd27c9176ee4cbb26a5a699bd7734d26d 100644 (file)
@@ -12,6 +12,7 @@ function QuizScreens(quiz) {
     this.intervalCountDown = 0;
     this.runningManTimeout = 0;
     this.timeline = null;
+    this.email = null;
     this.scrollBarDropdown = null;
 
     this.intro = new QuizScreenIntro(this);
@@ -23,6 +24,7 @@ QuizScreens.prototype = {
 
     initEvents: function () {
         const $this = this;
+
         // Réinitialiser les réponses
         $(document).on("click", ".btn.reset", function () {
             $this.resetForm();
@@ -36,6 +38,14 @@ QuizScreens.prototype = {
 
         // Cliquer sur le bouton suivant
         $(document).on("click", ".active-screen.next .action", function () {
+
+            if($this.getActiveScreenType() === 'email') {
+                if(!$this.validateEmail($this.activeScreen.find("input").val())) {
+                    alert('Please enter a correct format');
+                    return false;
+                }
+            }
+
             if (($this.currentQuestionAnswers.length === 0 && !parseInt($this.quiz.question.current().countdown_enable)) || (parseInt($this.quiz.question.current().countdown_enable) && $this.intervalCountDown !== 0 && $this.currentQuestionAnswers.length === 0)) {
                 alert('Please select at least one answer');
                 return false;
@@ -45,7 +55,7 @@ QuizScreens.prototype = {
             if ($(this).hasClass('validate')) {
                 let review = $this.sendUserAnswers();
                 // Si la revue instantanée est activée, on affiche les résultats
-                if ($this.quiz.data.instantReview) {
+                if ($this.quiz.data.instantReview && !['country','email','text'].includes($this.getActiveScreenType()) ) {
                     $this.instantReview(review);
                 } else {
                     // Sinon, on passe directement à la question suivante
@@ -110,9 +120,14 @@ QuizScreens.prototype = {
     updateUserAnswers: function () {
         const $this = this;
         this.currentQuestionAnswers = []
-        $(".active-screen form").find("input:checked").each(function () {
-            $this.currentQuestionAnswers.push(parseInt($(this).val()));
-        });
+
+        if(['country','email','text'].includes(this.getActiveScreenType())) {
+            this.currentQuestionAnswers = this.getActiveScreen().find(".answer-text").val()
+        } else {
+            $(".active-screen form").find("input:checked").each(function () {
+                $this.currentQuestionAnswers.push(parseInt($(this).val()));
+            });
+        }
     },
 
     /**
@@ -137,6 +152,8 @@ QuizScreens.prototype = {
                 $this.quiz.match.start()
             } else if($this.getActiveScreenType() === 'country') {
                 $this.quiz.countriesList.start()
+            } else if($this.getActiveScreenType() === 'email') {
+                $this.email = $this.activeScreen.find("input").val()
             }
 
             //
@@ -147,10 +164,10 @@ QuizScreens.prototype = {
             $this.currentQuestionAnswers = [];
             $this.quiz.progressbar.update();
 
-
             if (screen === 'outro') {
                 $this.outro.show();
             }
+
             $this.quiz.resize.resize();
         });
     },
@@ -209,6 +226,8 @@ QuizScreens.prototype = {
             this.quiz.draganddrop.reset();
         } else if(type === 'match') {
             this.quiz.match.reset();
+        } else {
+            this.getCurrentForm().find(".answer-text").val("")
         }
     },
 
@@ -286,6 +305,11 @@ QuizScreens.prototype = {
     resetCountdownBackground: function () {
         document.documentElement.style.setProperty("--width-bg-countdown", "100%")
     },
+
+    validateEmail: function(email) {
+        let re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
+        return re.test(email);
+    }
 };
 
 export default QuizScreens;