Skip to content

Commit ff5b4a3

Browse files
authoredJun 20, 2019
Merge pull request #3 from h5p/master
f
2 parents caf81cb + 67a4d1f commit ff5b4a3

35 files changed

+4353
-2771
lines changed
 

‎js/multichoice.js

+28-33
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*global EJS*/
12
// Will render a Question with multiple choices for answers.
23

34
// Options format:
@@ -55,6 +56,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
5556
return new H5P.MultiChoice(options, contentId, contentData);
5657
var self = this;
5758
this.contentId = contentId;
59+
this.contentData = contentData;
5860
H5P.Question.call(self, 'multichoice');
5961
var $ = H5P.jQuery;
6062

@@ -92,7 +94,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
9294
checkAnswerButton: 'Check',
9395
showSolutionButton: 'Show solution',
9496
tryAgainButton: 'Try again',
95-
scoreBarLabel: 'Score',
97+
scoreBarLabel: 'You got :num out of :total points',
9698
tipAvailable: "Tip available",
9799
feedbackAvailable: "Feedback available",
98100
readFeedback: 'Read feedback',
@@ -103,11 +105,11 @@ H5P.MultiChoice = function (options, contentId, contentData) {
103105
behaviour: {
104106
enableRetry: true,
105107
enableSolutionsButton: true,
108+
enableCheckButton: true,
106109
type: 'auto',
107110
singlePoint: true,
108111
randomAnswers: false,
109112
showSolutionsRequiresInput: true,
110-
disableImageZooming: false,
111113
autoCheck: false,
112114
passPercentage: 100,
113115
showScorePoints: true
@@ -197,21 +199,23 @@ H5P.MultiChoice = function (options, contentId, contentData) {
197199
* Register the different parts of the task with the H5P.Question structure.
198200
*/
199201
self.registerDomElements = function () {
200-
if (params.media && params.media.library) {
201-
var type = params.media.library.split(' ')[0];
202+
var media = params.media.type;
203+
if (media && media.library) {
204+
var type = media.library.split(' ')[0];
202205
if (type === 'H5P.Image') {
203-
if (params.media.params.file) {
206+
if (media.params.file) {
204207
// Register task image
205-
self.setImage(params.media.params.file.path, {
206-
disableImageZooming: params.behaviour.disableImageZooming,
207-
alt: params.media.params.alt
208+
self.setImage(media.params.file.path, {
209+
disableImageZooming: params.media.disableImageZooming || false,
210+
alt: media.params.alt,
211+
title: media.params.title
208212
});
209213
}
210214
}
211215
else if (type === 'H5P.Video') {
212-
if (params.media.params.sources) {
216+
if (media.params.sources) {
213217
// Register task video
214-
self.setVideo(params.media);
218+
self.setVideo(media);
215219
}
216220
}
217221
}
@@ -505,7 +509,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
505509
* Hide solution for the given answer(s)
506510
*
507511
* @private
508-
* @param {H5P.jQuery} $answer
512+
* @param {H5P.jQuery} $answer
509513
*/
510514
var hideSolution = function ($answer) {
511515
$answer
@@ -575,13 +579,13 @@ H5P.MultiChoice = function (options, contentId, contentData) {
575579
// Remove all tip dialogs
576580
removeFeedbackDialog();
577581

578-
self.hideButton('check-answer');
579582
if (params.behaviour.enableSolutionsButton) {
580583
self.showButton('show-solution');
581584
}
582585
if (params.behaviour.enableRetry) {
583586
self.showButton('try-again');
584587
}
588+
self.hideButton('check-answer');
585589

586590
self.showCheckSolution();
587591
disableInput();
@@ -590,7 +594,6 @@ H5P.MultiChoice = function (options, contentId, contentData) {
590594
addQuestionToXAPI(xAPIEvent);
591595
addResponseToXAPI(xAPIEvent);
592596
self.trigger(xAPIEvent);
593-
self.trigger('resize');
594597
};
595598

596599
/**
@@ -639,7 +642,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
639642
}, false);
640643

641644
// Check solution button
642-
if (!params.behaviour.autoCheck || !params.behaviour.singleAnswer) {
645+
if (params.behaviour.enableCheckButton && (!params.behaviour.autoCheck || !params.behaviour.singleAnswer)) {
643646
self.addButton('check-answer', params.UI.checkAnswerButton,
644647
function () {
645648
self.answered = true;
@@ -670,7 +673,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
670673
self.answered = false;
671674
if (params.behaviour.randomAnswers) {
672675
// reshuffle answers
673-
oldIdMap = idMap;
676+
var oldIdMap = idMap;
674677
idMap = getShuffleMap();
675678
var answersDisplayed = $myDom.find('.h5p-answer');
676679
// remember tips
@@ -790,27 +793,20 @@ H5P.MultiChoice = function (options, contentId, contentData) {
790793
// Determine feedback
791794
var max = self.getMaxScore();
792795

793-
// Show feedback
794-
if (!skipFeedback) {
795-
this.setFeedback(getFeedbackText(score, max), score, max, params.UI.scoreBarLabel);
796-
}
797-
798796
// Disable task if maxscore is achieved
799797
var fullScore = (score === max);
798+
800799
if (fullScore) {
801-
finishedTask();
800+
self.hideButton('check-answer');
801+
self.hideButton('try-again');
802+
self.hideButton('show-solution');
802803
}
803804

804-
self.trigger('resize');
805-
};
805+
// Show feedback
806+
if (!skipFeedback) {
807+
this.setFeedback(getFeedbackText(score, max), score, max, params.UI.scoreBarLabel);
808+
}
806809

807-
/**
808-
* Method to use when the task is correctly answered, removes all buttons and disables input.
809-
*/
810-
var finishedTask = function () {
811-
self.hideButton('check-answer');
812-
self.hideButton('try-again');
813-
self.hideButton('show-solution');
814810
self.trigger('resize');
815811
};
816812

@@ -968,7 +964,6 @@ H5P.MultiChoice = function (options, contentId, contentData) {
968964
* @return {number[]} map pointing from original answers to shuffled answers
969965
*/
970966
var getShuffleMap = function() {
971-
var origOrder = $.extend([], params.answers);
972967
params.answers = H5P.shuffleArray(params.answers);
973968

974969
// Create a map from the new id to the old one
@@ -977,7 +972,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
977972
idMap[i] = params.answers[i].originalOrder;
978973
}
979974
return idMap;
980-
}
975+
};
981976

982977
// Initialization code
983978
// Randomize order, if requested
@@ -1099,7 +1094,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
10991094
};
11001095

11011096
this.getTitle = function () {
1102-
return H5P.createTitle(params.question);
1097+
return H5P.createTitle((this.contentData && this.contentData.metadata && this.contentData.metadata.title) ? this.contentData.metadata.title : 'Multiple Choice');
11031098
};
11041099
};
11051100

‎language/.en.json

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
{
77
"label": "Type",
88
"description": "Optional media to display above the question."
9+
},
10+
{
11+
"label": "Disable image zooming"
912
}
1013
]
1114
},
@@ -91,8 +94,9 @@
9194
"default": "Show tip"
9295
},
9396
{
94-
"label": "Score Bar Label",
95-
"default": "Score"
97+
"label": "Textual representation of the score bar for those using a readspeaker",
98+
"description": "Available variables are :num and :total",
99+
"default": "You got :num out of :total points"
96100
},
97101
{
98102
"label": "Tip Available (not displayed)",
@@ -143,10 +147,12 @@
143147
{
144148
"label": "Enable \"Show Solution\" button"
145149
},
150+
{
151+
"label": "Enable \"Check\" button"
152+
},
146153
{
147154
"label": "Question Type",
148155
"description": "Select the look and behaviour of the question.",
149-
"default": "auto",
150156
"options": [
151157
{
152158
"label": "Automatic"
@@ -165,14 +171,11 @@
165171
},
166172
{
167173
"label": "Randomize answers",
168-
"description": "Enable to randomize the order of questions on display."
174+
"description": "Enable to randomize the order of the answers on display."
169175
},
170176
{
171177
"label": "Require answer before the solution can be viewed"
172178
},
173-
{
174-
"label": "Disable image zooming for question image"
175-
},
176179
{
177180
"label": "Show confirmation dialog on \"Check\""
178181
},
@@ -236,4 +239,4 @@
236239
]
237240
}
238241
]
239-
}
242+
}

0 commit comments

Comments
 (0)
Please sign in to comment.