]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6184 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Jul 2023 14:52:44 +0000 (16:52 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Jul 2023 14:52:44 +0000 (16:52 +0200)
resources/quizv2/js/quiz.animations.js
resources/quizv2/js/quiz.js
resources/quizv2/js/quiz.resize.js
resources/quizv2/js/quiz.score.js [new file with mode: 0644]

index 94e87a686396ae032e9d78dd6096f5561b286902..8ebdb988ab92635c8181ef397bffb51c9fbb3af1 100644 (file)
@@ -10,7 +10,6 @@ QuizAnimations.prototype = {
     load: function (name, container, replace) {
         let json = this.quiz.data.animations[name];
         $.each(replace, function (k, v) {
-            console.log(k, v);
             json = json.replace(new RegExp(k, 'g'), v);
         });
 
index 5c4efd3d7cfa2faa6691fd5e0bcc3da8bb95fca1..8a59325bb596f2a2a4fdd7f8b0c7eb4485420495 100644 (file)
@@ -6,6 +6,7 @@ import lottie from "lottie-web";
 
 import QuizResize from "./quiz.resize";
 import QuizAnimations from "./quiz.animations";
+import QuizScore from './quiz.score';
 
 window.cubeSCORM = new CubeSCORM();
 window.$ = window.jQuery = $;
index 44d4f7679f032a477e43776f9e61602f260d556d..b68ab5a8d53693b8a28b56a5efc498e165f590e0 100644 (file)
@@ -7,7 +7,7 @@ QuizResize.prototype = {
         this.ww = $(window).width();
         this.hh = $(window).height();
 
-        // Exécuter ici toutes opérations qui doivent intervenir lorsque la fenêtre est redimensionnée par le système ou l'utiisateur
+        // Exécuter ici toutes opérations qui doivent intervenir lorsque la fenêtre est redimensionnée par le système ou l'utilisateur
     },
 }
 
diff --git a/resources/quizv2/js/quiz.score.js b/resources/quizv2/js/quiz.score.js
new file mode 100644 (file)
index 0000000..db77ee2
--- /dev/null
@@ -0,0 +1,90 @@
+const $ = require("cash-dom");
+
+function QuizScore(quiz) {
+    this.quiz = quiz;
+    this.logQuestions=[];
+    this.score=0;
+    this.questionStatus=[];
+    this.init();
+}
+
+QuizScore.prototype = {
+
+    init: function () {
+
+    },
+
+    updateScore: function () {
+        this.score = 0;
+        var answers = [];
+        var qn = 1;
+        this.logQuestions = [];
+
+        let $this=this;
+
+        $('.question').each(function () {
+            var a = [];
+            var ok = true;
+            var count = $(this).attr('data-count') == '1';
+            var log = {
+                'count': count,
+            };
+
+            if ($(this).data('type') === 'multiple') {
+                var min_score = parseInt($(this).data('min-score'));
+                if (min_score === 0) {
+                    min_score = $(this).find('.answer[data-correct="1"]').length;
+                }
+                var this_score = 0;
+                $(this).find('.answer').each(function () {
+                    if ($(this).hasClass('active')) {
+                        var correct = $(this).attr('data-correct') == '1';
+                        this_score += correct ? 1 : -1;
+                        a.push($(this).data('a'))
+                    }
+                });
+                ok = this_score >= min_score;
+
+                answers.push(a);
+                log.answer = a;
+            } else {
+                log.answer = $(this).find('input,textarea,select').val();
+            }
+
+            if (!count) {
+                ok = null;
+            }
+
+            $this.questionStatus[qn] = ok;
+
+            var b = $("#correction .correction[data-i='" + qn + "'] .badge");
+            $(b).removeClass('correct').removeClass('incorrect');
+            if (ok === true) {
+                $(b).addClass('correct');
+            } else if (ok === false) {
+                $(b).addClass('incorrect');
+            }
+            if (ok && count) {
+                $this.score++;
+                log.score = 1;
+            } else {
+                log.score = 0;
+            }
+            $this.logQuestions[qn] = log;
+            qn++;
+        });
+
+
+        var state = {
+            q: $(".answer.active").last().closest('.question').data('q') + 1, a: answers
+        };
+
+        if (cubeSCORM.SCORM) {
+            cubeSCORM.setSCORMLocation(state);
+        }
+    },
+
+};
+
+module.exports = QuizScore;
+