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);
});
--- /dev/null
+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;
+