-
Notifications
You must be signed in to change notification settings - Fork 173
/
editor.js
50 lines (43 loc) · 1.25 KB
/
editor.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
(function($) {
/**
* Get closest row of element
*
* @param {jQuery} $el
* @returns {jQuery}
*/
function getRow($el) {
return $el.closest('.fitem');
}
/**
* Initializes editor
*/
function init() {
var $editor = $('.h5p-editor');
var $fileField = $('input[name="h5pfile"]');
if (H5PIntegration.hubIsEnabled) {
// TODO: This can easily break in new themes. Improve robustness of this
// by not including h5paction in form, when it should not be used.
$('input[name="h5paction"]').parents('.fitem').last().hide();
}
const mformId = H5PIntegration.editor && H5PIntegration.editor.formId !== null
? H5PIntegration.editor.formId
: 'mform1';
// Cancel validation and submission of form if clicking cancel button
const cancelSubmitCallback = function ($button) {
return $button.is('[name="cancel"]');
};
H5PEditor.init(
$('#' + mformId),
$('input[name="h5paction"]'),
getRow($fileField),
getRow($editor),
$editor,
$('input[name="h5plibrary"]'),
$('input[name="h5pparams"]'),
$('input[name="h5pmaxscore"]'),
$('input[name="name"]'),
cancelSubmitCallback
);
}
$(document).ready(init);
})(H5P.jQuery);