forked from garemoko/h5p-multi-choice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrades.js
87 lines (79 loc) · 3.2 KB
/
upgrades.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.MultiChoice'] = (function ($) {
return {
1: {
1: {
contentUpgrade: function (parameters, finished) {
// Moved all behavioural settings into "behaviour" group.
parameters.behaviour = {
enableRetry: parameters.tryAgain === undefined ? true : parameters.tryAgain,
enableSolutionsButton: parameters.enableSolutionsButton === undefined ? true : parameters.enableSolutionsButton,
singleAnswer: parameters.singleAnswer === undefined ? true : parameters.singleAnswer,
singlePoint: parameters.singlePoint === undefined ? true : parameters.singlePoint,
randomAnswers: parameters.randomAnswers === undefined ? true : parameters.randomAnswers,
showSolutionsRequiresInput: parameters.showSolutionsRequiresInput === undefined ? true : parameters.showSolutionsRequiresInput
};
if (parameters.UI === undefined) {
parameters.UI = {};
}
parameters.UI.checkAnswerButton = 'Check';
delete parameters.tryAgain;
delete parameters.enableSolutionsButton;
delete parameters.singleAnswer;
delete parameters.singlePoint;
delete parameters.randomAnswers;
delete parameters.showSolutionsRequiresInput;
finished(null, parameters);
}
},
3: {
contentUpgrade: function (parameters, finished) {
parameters.answers.forEach(function (answer) {
// Add new place for variable and delete old.
if (answer.tipsAndFeedback === undefined) {
answer.tipsAndFeedback = {};
}
answer.tipsAndFeedback.tip = answer.tip !== undefined ? answer.tip : '';
answer.tipsAndFeedback.chosenFeedback = answer.chosenFeedback !== undefined ? answer.chosenFeedback : '';
answer.tipsAndFeedback.notChosenFeedback = answer.notChosenFeedback !== undefined ? answer.notChosenFeedback : '';
delete answer.tip;
delete answer.chosenFeedback;
delete answer.notChosenFeedback;
});
finished(null, parameters);
}
},
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support MC 1.4.
*
* Replaces the single answer checkbox with a select field.
*
* @params {Object} parameters
* @params {function} finished
*/
4: function (parameters, finished) {
// Determine number of correct choices
var numCorrect = 0;
if (parameters.answers) {
for (var i = 0; i < parameters.answers.length; i++) {
if (parameters.answers[i].correct) {
numCorrect++;
}
}
}
if (!parameters.behaviour) {
parameters.behaviour = {};
}
if (parameters.behaviour.singleAnswer) {
parameters.behaviour.type = (numCorrect === 1 ? 'auto' : 'single');
}
else {
parameters.behaviour.type = (numCorrect > 1 ? 'auto' : 'multi');
}
delete parameters.behaviour.singleAnswer;
finished(null, parameters);
}
}
};
})(H5P.jQuery);