forked from h5p/h5p-blanks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrades.js
124 lines (113 loc) · 3.94 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.Blanks'] = (function () {
return {
1: {
1: {
contentUpgrade: function (parameters, finished) {
// Moved all behavioural settings into "behaviour" group.
parameters.behaviour = {
enableRetry: parameters.enableTryAgain === undefined ? true : parameters.enableRetry,
enableSolutionsButton: true,
autoCheck: parameters.autoCheck === undefined ? false : parameters.autoCheck,
caseSensitive: parameters.caseSensitive === undefined ? true : parameters.caseSensitive,
showSolutionsRequiresInput: parameters.showSolutionsRequiresInput === undefined ? true : parameters.showSolutionsRequiresInput,
separateLines: parameters.separateLines === undefined ? false : parameters.separateLines
};
delete parameters.enableTryAgain;
delete parameters.enableShowSolution;
delete parameters.autoCheck;
delete parameters.caseSensitive;
delete parameters.showSolutionsRequiresInput;
delete parameters.separateLines;
delete parameters.changeAnswer;
finished(null, parameters);
}
},
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support Blanks 1.5.
*
* Converts task image into media object, adding support for video.
*
* @params {Object} parameters
* @params {function} finished
*/
5: function (parameters, finished) {
if (parameters.image) {
// Convert image field to media field
parameters.media = {
library: 'H5P.Image 1.0',
params: {
file: parameters.image
}
};
// Remove old image field
delete parameters.image;
}
// Done
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support Blanks 1.8
*
* Move old feedback message to the new overall feedback system.
*
* @param {object} parameters
* @param {function} finished
*/
8: function (parameters, finished) {
if (parameters && parameters.score) {
parameters.overallFeedback = [
{
'from': 0,
'to': 100,
'feedback': parameters.score
}
];
delete parameters.score;
}
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
*
* @param {[type]} parameters
* @param {[type]} finished
* @param {[type]} extras
* @return {[type]}
*/
11: function (parameters, finished, extras) {
// Move value from getTitle() to metadata title
if (parameters && parameters.text) {
extras = extras || {};
extras.metadata = extras.metadata || {};
extras.metadata.title = parameters.text.replace(/<[^>]*>?/g, '');
}
finished(null, parameters, extras);
},
/*
* Upgrades content parameters to support Blanks 1.9
*
* Move disableImageZooming from behaviour to media
*
* @param {object} parameters
* @param {function} finished
*/
12: function (parameters, finished) {
// If image has been used, move it down in the hierarchy and add disableImageZooming
if (parameters && parameters.media) {
parameters.media = {
type: parameters.media,
disableImageZooming: (parameters.behaviour && parameters.behaviour.disableImageZooming) ? parameters.behaviour.disableImageZooming : false
};
}
// Delete old disableImageZooming
if (parameters && parameters.behaviour) {
delete parameters.behaviour.disableImageZooming;
}
finished(null, parameters);
}
}
};
})();