forked from h5p/h5p-video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrades.js
119 lines (103 loc) · 3.37 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
/** @namespace H5PUpgrades */
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.Video'] = (function ($) {
/**
* Help move and rename object properties.
*
* @private
* @param {Object} oldObj The object that has the property
* @param {String} oldProp The old property name
* @param {String} newProp The new property name OR the new object.
* @param {Object} [newObj] The new object for the property.
*/
var moveProp = function (oldObj, oldProp, newProp, newObj) {
if (!oldObj.hasOwnProperty(oldProp)) {
return;
}
if (!(newProp instanceof String) && typeof newProp !== 'string') {
// Allow using dropping newProp and using it as the new Object
newObj = newProp;
newProp = oldProp;
}
else if (!newObj) {
// Move on same object
newObj = oldObj;
}
newObj[newProp] = oldObj[oldProp];
delete oldObj[oldProp];
};
return {
1: {
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support Video 1.1.
*
* Renames some parameters to better suiting names, groups language
* localizations and moves copyrights to new object.
*
* @public
* @params {Object} parameters
* @params {Function} finished
*/
1: function (parameters, finished) {
// Use new names that better fits
moveProp(parameters, 'files', 'sources');
moveProp(parameters, 'fitToWrapper', 'fit');
if (parameters.contentName) {
// Create new group for language localization
parameters.l10n = {};
moveProp(parameters, 'contentName', 'name', parameters.l10n);
}
// Move old copyright properties
var source;
if (parameters.copyright && parameters.sources && parameters.sources[0]) {
source = parameters.sources[0];
}
if (source && source.copyright) {
var props = ['title', 'author', 'source', 'license'];
for (var i = 0; i < props.length; i++) {
var prop = props[i];
if (parameters.copyright[prop] && !source.copyright[prop]) {
moveProp(parameters.copyright, prop, source.copyright);
}
}
}
if (parameters.copyright) {
delete parameters.copyright;
}
// Done
finished(null, parameters);
},
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support Video 1.2.
*
* Groups visuals, playback and a11y.
*
* @public
* @params {Object} parameters
* @params {Function} finished
*/
2: function (parameters, finished) {
// Regroup to visuals
parameters.visuals = {};
parameters.visuals.poster = parameters.poster;
parameters.visuals.fit = parameters.fit;
parameters.visuals.controls = parameters.controls;
delete parameters.poster;
delete parameters.fit;
delete parameters.controls;
// Regroup to playback
parameters.playback = {};
parameters.playback.autoplay = parameters.autoplay;
parameters.playback.loop = parameters.loop;
delete parameters.autoplay;
delete parameters.loop;
// Placeholder for a11y
parameters.a11y = [];
// Done
finished(null, parameters);
}
}
};
})(H5P.jQuery);