From: Vincent Vanwaelscappel Date: Fri, 28 Jul 2023 14:52:44 +0000 (+0200) Subject: wip #6184 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=27af8aac8ddb35e98db71419fd417baf0f8ed0e7;p=fluidbook-toolbox.git wip #6184 @0.5 --- diff --git a/resources/quizv2/js/quiz.animations.js b/resources/quizv2/js/quiz.animations.js index 94e87a686..8ebdb988a 100644 --- a/resources/quizv2/js/quiz.animations.js +++ b/resources/quizv2/js/quiz.animations.js @@ -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); }); diff --git a/resources/quizv2/js/quiz.js b/resources/quizv2/js/quiz.js index 5c4efd3d7..8a59325bb 100644 --- a/resources/quizv2/js/quiz.js +++ b/resources/quizv2/js/quiz.js @@ -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 = $; diff --git a/resources/quizv2/js/quiz.resize.js b/resources/quizv2/js/quiz.resize.js index 44d4f7679..b68ab5a8d 100644 --- a/resources/quizv2/js/quiz.resize.js +++ b/resources/quizv2/js/quiz.resize.js @@ -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 index 000000000..db77ee2cf --- /dev/null +++ b/resources/quizv2/js/quiz.score.js @@ -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; +