forked from h5p/h5p-interactive-video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrades.js
241 lines (212 loc) · 8.86 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/** @namespace H5PUpgrades */
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.InteractiveVideo'] = (function ($) {
return {
1: {
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support IV 1.1.
*
* Moves interactions into an assets container to be able to add more
* properties to the video, i.e. a bookmark list
*
* @params {Object} parameters
* @params {function} finished
*/
1: function (parameters, finished) {
// Move interactions into assets container
parameters.interactiveVideo.assets = {
interactions: parameters.interactiveVideo.interactions,
bookmarks: []
};
delete parameters.interactiveVideo.interactions;
// Done
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support IV 1.3.
*
* Wraps summary in a container to be able to add IV specific options
* to the summary task, i.e. when to display the task.
*
* @params {Object} parameters
* @params {function} finished
*/
3: function (parameters, finished) {
// Move summary task into container
parameters.interactiveVideo.summary = {
task: parameters.interactiveVideo.summary,
displayAt: 3
};
// Done
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support IV 1.5.
*
* Adds unique identifiers to sub content?
*
* @params {Object} parameters
* @params {function} finished
*/
5: function (parameters, finished) {
if (parameters.interactiveVideo && parameters.interactiveVideo.assets && parameters.interactiveVideo.assets.interactions) {
var interactions = parameters.interactiveVideo.assets.interactions;
for (var i = 0; i < interactions.length; i++) {
if (interactions[i].action && interactions[i].action.subContentId === undefined) {
// NOTE: We avoid using H5P.createUUID since this is an upgrade script and H5P function may change in the
// future
interactions[i].action.subContentId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(char) {
var random = Math.random()*16|0, newChar = char === 'x' ? random : (random&0x3|0x8);
return newChar.toString(16);
});
}
}
}
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support IV 1.7.
*
* Groups all UI text strings to make them eaiser to translate and handle.
*
* @params {Object} parameters
* @params {function} finished
*/
7: function (parameters, finished) {
var i;
parameters.l10n = {};
var keys = ['interaction', 'play', 'pause', 'mute', 'quality', 'unmute', 'fullscreen', 'exitFullscreen', 'summary', 'bookmarks', 'defaultAdaptivitySeekLabel', 'playbackRate', 'rewind10'];
for (i = 0; i < keys.length; i++) {
var key = keys[i];
if (parameters.hasOwnProperty(key)) {
parameters.l10n[key] = parameters[key];
delete parameters[key];
}
}
/* Move displayAsButton to displayType */
if (parameters.interactiveVideo && parameters.interactiveVideo.assets && parameters.interactiveVideo.assets.interactions) {
var interactions = parameters.interactiveVideo.assets.interactions;
for (i = 0; i < interactions.length; i++) {
var interaction = interactions[i];
interaction.displayType = (interaction.displayAsButton === undefined || interaction.displayAsButton) ? 'button' : 'poster';
delete interaction.displayAsButton;
// Set links displayType to poster
if (interaction.action && interaction.action.library && interaction.action.library.split(' ')[0] === 'H5P.Link') {
interaction.displayType = 'poster';
}
}
}
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support IV 1.7.
*
* Groups all UI text strings to make them eaiser to translate and handle.
*
* @params {Object} parameters
* @params {function} finished
*/
10: function (parameters, finished) {
if (parameters.override) {
if (parameters.override.overrideButtons) {
// Set new variables
parameters.override.showSolutionButton =
(parameters.override.overrideShowSolutionButton ? 'on' : 'off');
parameters.override.retryButton =
(parameters.override.overrideRetry ? 'on' : 'off');
}
// Remove old field variables
delete parameters.override.overrideButtons;
delete parameters.override.overrideShowSolutionButton;
delete parameters.override.overrideRetry;
}
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
*
* Groups start screen options under a group, hiding nonessential
* information.
*
* Make existing posters have white background. I.e avoid existing posters
* getting the new default, which is full transparency.
*
* @params {Object} parameters
* @params {function} finished
*/
11: function (parameters, finished) {
if (parameters.interactiveVideo) {
var videoParams = parameters.interactiveVideo.video;
if (videoParams) {
videoParams.advancedSettings = {};
videoParams.startScreenOptions = videoParams.startScreenOptions || {};
videoParams.advancedSettings.startScreenOptions = videoParams.startScreenOptions;
videoParams.advancedSettings.startScreenOptions.poster = videoParams.poster;
videoParams.advancedSettings.title = videoParams.title;
videoParams.advancedSettings.copyright = videoParams.copyright;
// Remove old fields
delete videoParams.startScreenOptions;
delete videoParams.poster;
delete videoParams.title;
delete videoParams.copyright;
}
if (parameters.interactiveVideo.assets && parameters.interactiveVideo.assets.interactions) {
var interactions = parameters.interactiveVideo.assets.interactions;
for (var i = 0; i < interactions.length; i++) {
var interaction = interactions[i];
// Set white background + boxShadow for images and textual posters:
if(interaction && interaction.displayType === 'poster' && interaction.action && interaction.action.library) {
var lib = interaction.action.library.split(' ')[0];
if (['H5P.Text', 'H5P.Image', 'H5P.Table'].indexOf(lib) !== -1) {
interaction.visuals = {
backgroundColor: 'rgba(255,255,255,1)',
boxShadow: true
};
}
else if (lib === 'H5P.Link') {
interaction.visuals = {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
boxShadow: true
}
}
}
}
}
}
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
*
* Rename "Advanced settings: Interactive video" to "Start screen options"
* Remove the group inside it that says "Video start screen options" and
* puts options directly under the parent.
*
* @params {Object} parameters
* @params {function} finished
*/
12: function (parameters, finished) {
function moveOldStartScreenOptions(video) {
// Rename Advanced settings
video.startScreenOptions = video.advancedSettings;
// Remove old advanced settings
delete video.advancedSettings;
// Move old start screen options to parent
video.startScreenOptions.poster = video.startScreenOptions.startScreenOptions.poster;
video.startScreenOptions.hideStartTitle = video.startScreenOptions.startScreenOptions.hideStartTitle;
video.startScreenOptions.shortStartDescription = video.startScreenOptions.startScreenOptions.shortStartDescription;
delete video.startScreenOptions.startScreenOptions;
}
if(parameters.interactiveVideo && parameters.interactiveVideo.video){
moveOldStartScreenOptions(parameters.interactiveVideo.video);
}
finished(null, parameters);
}
}
};
})(H5P.jQuery);