From 3ee3e2e7e145a8c94eb7b3ad18c3c25a826fdf1b Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Mon, 6 Jul 2020 12:04:09 +0200 Subject: [PATCH] Stop giving away correct answers in page source --- scripts/single-choice-alternative.js | 2 +- scripts/single-choice-set.js | 2 +- scripts/single-choice.js | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/single-choice-alternative.js b/scripts/single-choice-alternative.js index 3c143fa..f4324e0 100644 --- a/scripts/single-choice-alternative.js +++ b/scripts/single-choice-alternative.js @@ -25,7 +25,7 @@ H5P.SingleChoiceSet.Alternative = (function ($, EventDispatcher) { }; this.$alternative = $('
  • ', { - 'class': 'h5p-sc-alternative h5p-sc-is-' + (this.options.correct ? 'correct' : 'wrong'), + 'class': 'h5p-sc-alternative', 'role': 'button', 'tabindex': -1, 'on': { diff --git a/scripts/single-choice-set.js b/scripts/single-choice-set.js index 609ce4c..90be7fe 100644 --- a/scripts/single-choice-set.js +++ b/scripts/single-choice-set.js @@ -790,7 +790,7 @@ H5P.SingleChoiceSet = (function ($, UI, Question, SingleChoice, SolutionView, Re this.solutionView.hide(); // Reset the user's answers - var classes = ['h5p-sc-reveal-wrong', 'h5p-sc-reveal-correct', 'h5p-sc-selected', 'h5p-sc-drummed', 'h5p-sc-correct-answer']; + var classes = ['h5p-sc-reveal-wrong', 'h5p-sc-reveal-correct', 'h5p-sc-selected', 'h5p-sc-drummed', 'h5p-sc-correct-answer', 'h5p-sc-is-correct', 'h5p-sc-is-wrong']; for (var i = 0; i < classes.length; i++) { this.$choices.find('.' + classes[i]).removeClass(classes[i]); } diff --git a/scripts/single-choice.js b/scripts/single-choice.js index d7d8c5c..c70aacd 100644 --- a/scripts/single-choice.js +++ b/scripts/single-choice.js @@ -211,7 +211,10 @@ H5P.SingleChoiceSet.SingleChoice = (function ($, EventDispatcher, Alternative) { SingleChoice.prototype.showResult = function (correct, answerIndex) { var self = this; - var $correctAlternative = self.$choice.find('.h5p-sc-is-correct'); + const $correctAlternative = self.alternatives.filter(function (alternative) { + return alternative.options.correct; + })[0].$alternative; + $correctAlternative.addClass('h5p-sc-is-correct'); H5P.Transition.onTransitionEnd($correctAlternative, function () { self.trigger('finished', { @@ -222,7 +225,15 @@ H5P.SingleChoiceSet.SingleChoice = (function ($, EventDispatcher, Alternative) { }, 600); // Reveal corrects and wrong - self.$choice.find('.h5p-sc-is-wrong').addClass('h5p-sc-reveal-wrong'); + const wrongAlternatives = self.alternatives + .filter(function (alternative) { + return !alternative.options.correct; + }) + .forEach(function (alternative) { + alternative.$alternative.addClass('h5p-sc-reveal-wrong'); + alternative.$alternative.addClass('h5p-sc-is-wrong'); + }); + $correctAlternative.addClass('h5p-sc-reveal-correct'); };