]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6182 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 18 Aug 2023 07:38:57 +0000 (09:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 18 Aug 2023 07:38:57 +0000 (09:38 +0200)
js/quiz.accessibility.js
js/quiz.animations.js
js/quiz.js
js/quiz.progressbar.js [new file with mode: 0644]
js/quiz.question.js
js/quiz.resize.js
js/quiz.score.js
js/quiz.scorm.js
js/quiz.screen.intro.js
js/quiz.screens.js
js/quiz.utils.js

index 6866787f1b002dfa1d0eff2edf7fca690ab60267..17a49fd701e2191ab312a956a86f636eaecec458 100644 (file)
@@ -24,5 +24,5 @@ QuizAccessibility.prototype = {
     },
 }
 
-module.exports = QuizAccessibility;
+export default QuizAccessibility;
 
index d43a719cc7e745b018ba332792042f5b76a62dd3..bd83cbaa073851ea321f1205a987031629106121 100644 (file)
@@ -34,4 +34,4 @@ QuizAnimations.prototype = {
 }
 
 
-module.exports = QuizAnimations;
+export default QuizAnimations;
index f8078e0a9016c42068969f766264c4ea2abe996d..fc6ae4f7521e40a71fd931b53e497b97a1eb1976 100644 (file)
@@ -11,6 +11,7 @@ import QuizQuestion from './quiz.question';
 import QuizAccessibility from './quiz.accessibility';
 import QuizUtils from './quiz.utils';
 import QuizScreens from './quiz.screens';
+import QuizProgressbar from "./quiz.progressbar";
 
 window.cubeSCORM = new CubeSCORM();
 window.$ = window.jQuery = $;
@@ -35,6 +36,7 @@ Quiz.prototype = {
         this.utils = new QuizUtils(this);
         this.accessibility = new QuizAccessibility(this);
         this.screens = new QuizScreens(this);
+        this.progressbar=new QuizProgressbar(this);
 
         // Ici seront injectées dans this.data toutes les données du quiz et du thème pour qu'elles soient disponibles
         // dans l'object à tout moment
@@ -46,12 +48,6 @@ Quiz.prototype = {
         console.log(this.data.theme)
 
         this.timeoutAnimation = false
-
-        // commencer
-        $(document).on("click", "#start", function () {
-            $this.start()
-        })
-
         //
         $("#quiz").css("background-image", "url(" + this.data.theme.backgroundImage + ")")
 
@@ -92,20 +88,7 @@ Quiz.prototype = {
             gsap.to($(this), {scale: 1, duration: .2});
         })
 
-        //
-        this.activeNav()
-    },
-
-    start: function () {
-        const $this = this
-        gsap.timeline().to("#welcome-screen", {
-            opacity: 0,
-            onComplete: function () {
-                let responses = $this.responses
-                $this.next(responses);
-                $("#welcome-screen").removeClass("next active-screen").addClass("none").next(".container-screen").removeClass("none").addClass("next active-screen")
-            }
-        })
+        this.progressbar.update();
     },
 
     updateIcons: function () {
@@ -132,140 +115,6 @@ Quiz.prototype = {
         this.resize.resize();
     },
 
-    next: function (responses) {
-        // on arrête l'animation si le joueur passe à la question suivante
-        this.stopAnimationValidation()
-
-        let status = quiz.score.questionStatus
-        let currentPosition = quiz.score.lastAnsweredQuestion + 1
-
-        const $el = $(".active-screen .btn.action")
-
-        quiz.score.updateScore()
-        // if form exist and responses are validated
-        // 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") {
-                    this.validateResponse(responses);
-                    this.updateBtnValidation("validated")
-                    return false
-                }
-            }
-        }
-
-        $el.parents(".container-screen").addClass("none").removeClass("next active-screen").next(".container-screen").removeClass("none").addClass("next active-screen")
-        this.resetForm()
-        // on incrémente de 1 la position actuelle de la question (qui commence à l'index zero)
-        // 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.screens.outro.show();
-        }
-    },
-
-    // marque page automatique
-    // si le joueur recharge la page, le rediriger là où il en était
-    setDisplay: function () {
-        const currentQuestion = quiz.score.lastAnsweredQuestion + 1,
-            questions = this.quiz.questions
-
-        if (questions.length > 0) {
-            if (quiz.score.lastAnsweredQuestion > -1 && questions.length <= currentQuestion) {
-                //
-            }
-        }
-    },
-
-    resetForm: () => {
-        $("form").find("input").prop("checked", false)
-    },
-
-    updateBtnValidation: function (status) {
-        let $btnAction = $(".footer-question .action"),
-            validationText = $btnAction.data("validation-text"),
-            continueText = $btnAction.data("continue-text")
-
-        $btnAction.find('.text').text(status === "validated" ? continueText : validationText)
-    },
-
-    validateResponse: function (responses) {
-        const form = $(".active-screen form")
-        const activeScreen = $(".active-screen")
-        const position = activeScreen.data("position")
-
-        if (form) {
-            if (form.length > 0) {
-                let validated = quiz.score.setAnswer(position, responses);
-                if (validated.ok === "ok") {
-                    this.animationValidation("OK")
-                } else {
-                    this.animationValidation("NOK")
-                }
-                this.resultAfterValidation(validated.status[position].answers)
-            }
-            return false
-        }
-    },
-
-    activeNav: function (position = 1) {
-        const questionStatus = quiz.score.questionStatus
-        const lastAnsweredQuestion = quiz.score.lastAnsweredQuestion
-        if ($(".active-screen").find(".progress-item").length > 0) {
-            let $el = $(".progress-container .progress-item:nth-child(" + position + ")")
-
-            $(".progress-container .progress-item").removeClass("active")
-            $el.addClass("active")
-
-            let n = (lastAnsweredQuestion + 1)
-            let $_el = $(".progress-container .progress-item:nth-child(" + n + ")")
-
-            if (lastAnsweredQuestion > -1) {
-                if (questionStatus[lastAnsweredQuestion].ok === 'ok') {
-                    $_el.addClass("ok")
-                }
-                if (questionStatus[lastAnsweredQuestion].ok === 'nok') {
-                    $_el.addClass("nok")
-                }
-            }
-        }
-    },
-
-    animationValidation: function (status) {
-        let selector = $("#anim")
-        let text = status === "NOK" ? "Not quite" : "Perfect"
-        let $this = this
-        this.animations.load(status, selector, {'\\$text': text});
-        selector.addClass("active")
-        this.timeoutAnimation = setTimeout(function (e) {
-            $this.stopAnimationValidation()
-        }, 10000)
-    },
-
-    stopAnimationValidation: function () {
-        $("#anim").removeClass("active").empty()
-        if (this.timeoutAnimation)
-            clearTimeout(this.timeoutAnimation)
-    },
-
-    resultAfterValidation: function (datas) {
-        for (let k in datas) {
-            let n = (parseInt(k) + 1)
-            let icon = getSpriteIcon("quiz-ok")
-            let $el = $(".active-screen .question-multiple .list-item:nth-of-type(" + n + ") label")
-            $el.addClass(datas[k])
-            if (datas[k] === "nok") {
-                icon = getSpriteIcon("quiz-wrong")
-            }
-            if (datas[k] !== "neutral") {
-                $el.find(".access").addClass(datas[k]).html(icon)
-            }
-        }
-    },
-
-
     restart: function () {
 
     }
diff --git a/js/quiz.progressbar.js b/js/quiz.progressbar.js
new file mode 100644 (file)
index 0000000..f0cef40
--- /dev/null
@@ -0,0 +1,30 @@
+function QuizProgressbar(quiz) {
+    this.quiz = quiz;
+}
+
+QuizProgressbar.prototype = {
+    update: function (position = 1) {
+        const questionStatus = quiz.score.questionStatus
+        const lastAnsweredQuestion = quiz.score.lastAnsweredQuestion
+        if ($(".active-screen").find(".progress-item").length > 0) {
+            let $el = $(".progress-container .progress-item:nth-child(" + position + ")")
+
+            $(".progress-container .progress-item").removeClass("active")
+            $el.addClass("active")
+
+            let n = (lastAnsweredQuestion + 1)
+            let $_el = $(".progress-container .progress-item:nth-child(" + n + ")")
+
+            if (lastAnsweredQuestion > -1) {
+                if (questionStatus[lastAnsweredQuestion].ok === 'ok') {
+                    $_el.addClass("ok")
+                }
+                if (questionStatus[lastAnsweredQuestion].ok === 'nok') {
+                    $_el.addClass("nok")
+                }
+            }
+        }
+    },
+}
+
+export default QuizProgressbar;
\ No newline at end of file
index f659d07e05fddaa8e2224f047ad3b88601bb66b0..8c90f4da931d3ed084546cf9d75a265f00796d54 100644 (file)
@@ -34,4 +34,4 @@ QuizQuestion.prototype = {
     },
 }
 
-module.exports = QuizQuestion;
+export default QuizQuestion;
index b68ab5a8d53693b8a28b56a5efc498e165f590e0..aa1c17ef1ac977b390deb5997c75d778dc40c316 100644 (file)
@@ -11,4 +11,4 @@ QuizResize.prototype = {
     },
 }
 
-module.exports = QuizResize;
+export default QuizResize;
index b3367885c3d05dccef970336b9e9fb3afc828f16..8e0284ca56fa395797f7ef86613961bfcab8a55e 100644 (file)
@@ -149,5 +149,5 @@ QuizScore.prototype = {
     },
 };
 
-module.exports = QuizScore;
+export default QuizScore;
 
index b5e5570e1f1dbb0511307d672d77bfc111d3fd64..1a6409d1830fe49338bc6707123c1dac7ddf2f9b 100644 (file)
@@ -4,4 +4,4 @@ function QuizScorm(quiz) {
 
 QuizScorm.prototype = {};
 
-module.exports = QuizScorm;
+export default QuizScorm;
index 5c37e6a50b12a7356747d2599d9fcf09330b56b0..e52ce3c94e5cf2b503fc634be11d7599a1b5b133 100644 (file)
@@ -1,15 +1,22 @@
 import gsap from "gsap";
 import SplitType from 'split-type';
 
-function QuizScreenIntro(quiz) {
-    this.quiz = quiz;
+function QuizScreenIntro(screens) {
+    this.quiz = screens.quiz;
+    this.screens = screens;
 }
 
 QuizScreenIntro.prototype = {
     show: function () {
-        console.log(':)');
+        let $this = this;
+
         $("#welcome-screen").addClass('active-screen next').removeClass('none');
         this.animate();
+
+        $(document).on("click", "#start", function () {
+            $this.screens.gotoQuestion(1);
+            return false;
+        });
     },
 
     animate: function () {
index 2d94412e82f4530fa22462fe0904914ddc921784..4e9a507301f528636aa335d08308e81f7ab38ad8 100644 (file)
+import gsap from "gsap";
+
 import QuizScreenIntro from './quiz.screen.intro';
 import QuizScreenOutro from "./quiz.screen.outro";
 
 function QuizScreens(quiz) {
     this.quiz = quiz;
-    this.intro = new QuizScreenIntro(quiz);
-    this.outro = new QuizScreenOutro(quiz);
+    this.intro = new QuizScreenIntro(this);
+    this.outro = new QuizScreenOutro(this);
 }
 
-QuizScreens.prototype = {};
+QuizScreens.prototype = {
+    gotoQuestion: function (question) {
+        const $this = this;
+        let callback = function () {
+            let responses = $this.quiz.responses
+            $this.next(responses);
+        }
+
+        let screen;
+        if (question == 1) {
+            screen = $("#welcome-screen");
+        }
+
+        this.hideScreen(screen, callback);
+    },
+
+    next: function (responses) {
+        // on arrête l'animation si le joueur passe à la question suivante
+        this.stopAnimationValidation()
+
+        let status = quiz.score.questionStatus
+        let currentPosition = quiz.score.lastAnsweredQuestion + 1
+
+        const $el = $(".active-screen .btn.action")
+
+        this.quiz.score.updateScore()
+        // if form exist and responses are validated
+        // 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") {
+                    this.validateResponse(responses);
+                    this.updateBtnValidation("validated")
+                    return false
+                }
+            }
+        }
+
+        $el.parents(".container-screen").addClass("none").removeClass("next active-screen").next(".container-screen").removeClass("none").addClass("next active-screen")
+        this.resetForm()
+        // on incrémente de 1 la position actuelle de la question (qui commence à l'index zero)
+        // pour récupérer le premier enfant de la nav
+        this.quiz.progressbar.update((parseInt(this.quiz.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.quiz.question.last(currentPosition)) {
+            this.outro.show();
+        }
+    },
+
+
+    resetForm: () => {
+        $("form").find("input").prop("checked", false)
+    },
+
+    updateBtnValidation: function (status) {
+        let $btnAction = $(".footer-question .action"), validationText = $btnAction.data("validation-text"),
+            continueText = $btnAction.data("continue-text")
+
+        $btnAction.find('.text').text(status === "validated" ? continueText : validationText)
+    },
+
+    animationValidation: function (status) {
+        let selector = $("#anim")
+        let text = status === "NOK" ? "Not quite" : "Perfect"
+        let $this = this
+        this.quiz.animations.load(status, selector, {'\\$text': text});
+        selector.addClass("active")
+        this.timeoutAnimation = setTimeout(function (e) {
+            $this.stopAnimationValidation()
+        }, 10000)
+    },
+
+    stopAnimationValidation: function () {
+        $("#anim").removeClass("active").empty()
+        if (this.timeoutAnimation) {
+            clearTimeout(this.timeoutAnimation);
+        }
+    },
+
+
+    validateResponse: function (responses) {
+        const form = $(".active-screen form")
+        const activeScreen = $(".active-screen")
+        const position = activeScreen.data("position")
+
+        if (form) {
+            if (form.length > 0) {
+                let validated = quiz.score.setAnswer(position, responses);
+                if (validated.ok === "ok") {
+                    this.animationValidation("OK")
+                } else {
+                    this.animationValidation("NOK")
+                }
+                this.resultAfterValidation(validated.status[position].answers)
+            }
+            return false
+        }
+    },
+
+
+
+    resultAfterValidation: function (datas) {
+        for (let k in datas) {
+            let n = (parseInt(k) + 1)
+            let icon = getSpriteIcon("quiz-ok")
+            let $el = $(".active-screen .question-multiple .list-item:nth-of-type(" + n + ") label")
+            $el.addClass(datas[k])
+            if (datas[k] === "nok") {
+                icon = getSpriteIcon("quiz-wrong")
+            }
+            if (datas[k] !== "neutral") {
+                $el.find(".access").addClass(datas[k]).html(icon)
+            }
+        }
+    },
+
+
+    hideScreen: function (screen, callback) {
+        let cb = function () {
+            $(screen).removeClass("next active-screen").addClass("none");
+            //next(".container-screen").removeClass("none").addClass("next active-screen");
+            callback();
+        };
+
+        if (this.quiz.utils.isVisible(screen)) {
+            gsap.timeline().to("#welcome-screen", {
+                autoAlpha: 0, onComplete: function () {
+                    cb();
+                }
+            })
+        } else {
+            cb();
+        }
+    },
+};
 
 export default QuizScreens;
\ No newline at end of file
index 2abb2ba1c7e856e83ef409606f6e0085d965a713..4e289013395786f6899d81a9153fe2714221115e 100644 (file)
@@ -12,4 +12,4 @@ QuizUtils.prototype = {
     }
 }
 
-module.exports = QuizUtils;
\ No newline at end of file
+export default QuizUtils;
\ No newline at end of file