Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop giving away correct answers in page source #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/single-choice-alternative.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ H5P.SingleChoiceSet.Alternative = (function ($, EventDispatcher) {
};

this.$alternative = $('<li>', {
'class': 'h5p-sc-alternative h5p-sc-is-' + (this.options.correct ? 'correct' : 'wrong'),
'class': 'h5p-sc-alternative',
'role': 'radio',
'tabindex': -1,
'on': {
Expand Down
2 changes: 1 addition & 1 deletion scripts/single-choice-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,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]);
}
Expand Down
15 changes: 13 additions & 2 deletions scripts/single-choice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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');
};

Expand Down