-
Notifications
You must be signed in to change notification settings - Fork 31
/
upgrades.js
49 lines (43 loc) · 1.21 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
/*global H5P*/
/** @namespace H5PUpgrades */
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.Link'] = (function () {
return {
1: {
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support link v1.1.
*
* Sets protocol to none.
*
* @params {Object} parameters
* @params {function} finished
*/
1: function (parameters, finished) {
var allowedProtocols = ['http://', 'https://', '/'];
var urlProtocol;
var url = parameters.url || '';
// Check if url had any allowed protocols
allowedProtocols.forEach(function (protocol) {
if (url.substr(0, protocol.length) === protocol) {
urlProtocol = protocol;
url = url.substr(protocol.length);
}
});
// Set new link widget parameters
parameters.linkWidget = {
url: url
};
if (urlProtocol) {
parameters.linkWidget.protocol = urlProtocol;
} else {
parameters.linkWidget.protocol = 'other';
}
//Remove old url
delete parameters.url;
// Done
finished(null, parameters);
}
}
};
})();