forked from h5p/h5p-image-hotspots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrades.js
72 lines (65 loc) · 1.98 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
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.ImageHotspots'] = (function ($) {
return {
1: {
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support ImageHotspots 1.1.
*
* Moves the fields named x and y into the position group
*
* @params {Object} parameters
* @params {function} finished
*/
1: function (parameters, finished) {
// Move x and y
if (parameters.hotspots !== undefined) {
for (var i = 0; i < parameters.hotspots.length; i++) {
parameters.hotspots[i].position = {
x: parameters.hotspots[i].x || 0,
y: parameters.hotspots[i].y || 0
};
delete parameters.hotspots[i].x;
delete parameters.hotspots[i].y;
}
}
finished(null, parameters);
},
/**
* Upgrades content parameters to support ImageHotspots 1.3
*
* Moves hotspot content into list
*
* @param parameters
* @param finished
*/
3: function (parameters, finished) {
if (parameters.hotspots !== undefined) {
parameters.hotspots.forEach(function (hotspot) {
if (hotspot.action) {
hotspot.content = [];
hotspot.content.push(hotspot.action);
delete hotspot.action;
}
});
}
finished(null, parameters);
},
/**
* Upgrades content parameters to support ImageHotspots 1.4
*
* Adds '#' in front of hex color provided from color selector widget
*
* @param parameters
* @param finished
*/
4: function (parameters, finished) {
// Old content has specified a color, opposed to using the default
if (parameters.color.charAt(0) !== '#') {
parameters.color = '#' + parameters.color;
}
finished(null, parameters);
},
}
};
})(H5P.jQuery);