-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathupgrades.js
48 lines (44 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
/** @namespace H5PUpgrades */
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.GuessTheAnswer'] = (function () {
/**
* Generates a new UUID
*
* @return {string}
*/
var generateUUID = function() {
return '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);
});
};
return {
1: {
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support Guess the Answer 1.2.
*
* Replace the image with optional media (both image and video)
*
* @params {Object} parameters
* @params {function} finished
*/
2: function (parameters, finished) {
if (parameters.solutionImage) {
parameters.media = {
library: 'H5P.Image 1.0',
subContentId: generateUUID(),
params: {
contentName: 'Image',
file: parameters.solutionImage,
alt:'',
title: ''
}
};
delete parameters.solutionImage
}
finished(null, parameters);
}
}
};
})();