From: soufiane Date: Thu, 5 Oct 2023 16:04:29 +0000 (+0200) Subject: wip #6342 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f090bbc9d7eef85e22f984a1c0ea443210ed85f4;p=fluidbook-toolbox-quiz.git wip #6342 --- diff --git a/js/quiz.accessibility.js b/js/quiz.accessibility.js index c0380fc..37b0c5e 100644 --- a/js/quiz.accessibility.js +++ b/js/quiz.accessibility.js @@ -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; + } + }); + } }); }, } diff --git a/js/quiz.screens.js b/js/quiz.screens.js index dbdc84d..f90791b 100644 --- a/js/quiz.screens.js +++ b/js/quiz.screens.js @@ -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;