-
Notifications
You must be signed in to change notification settings - Fork 59
/
upgrades.js
75 lines (68 loc) · 2.51 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
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.Dialogcards'] = (function () {
return {
1: {
/**
* Asynchronous content upgrade hook.
* Upgrades content parameters to support DQ 1.4.
*
* Converts text and answer into rich text.
* Escapes 'dangerous' symbols.
*
* @param {Object} parameters
* @param {function} finished
*/
4: function (parameters, finished) {
// The old default was to scale the text and not the card
parameters.behaviour = {
scaleTextNotCard: true
};
// Complete
finished(null, parameters);
},
7: function (parameters, finished, extras) {
var extrasOut = extras || {};
// Copy html-free title to new metadata structure if present
var title = parameters.title || ((extras && extras.metadata) ? extras.metadata.title : undefined);
if (title) {
title = title.replace(/<[^>]*>?/g, '');
}
extrasOut.metadata = {
title: title
};
finished(null, parameters, extrasOut);
},
9: function (parameters, finished, extras) {
if (parameters && parameters.dialogs && Array.isArray(parameters.dialogs)) {
/*
* Regardless of what alignment was set in the editor, the stylesheet
* would always center the text. For not breaking the view of existing
* content, set all text to be centered in params - can be changed by
* user in the editor after upgrade.
*/
parameters.dialogs.forEach(function (dialog) {
// Update text on front
if (typeof dialog.text === 'string') {
if (dialog.text.substr(0, 2) !== '<p') {
dialog.text = '<p style="text-align: center;">' + dialog.text + '</p>'; // was plain text
}
else {
dialog.text = dialog.text.replace(/<p[^>]*>/g, '<p style="text-align: center;">');
}
}
// Update text on back
if (typeof dialog.answer === 'string') {
if (dialog.answer.substr(0, 2) !== '<p') {
dialog.answer = '<p style="text-align: center;">' + dialog.answer + '</p>'; // was plain text
}
else {
dialog.answer = dialog.answer.replace(/<p[^>]*>/g, '<p style="text-align: center;">');
}
}
});
}
finished(null, parameters, extras);
}
}
};
})();