-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-input.js
More file actions
44 lines (36 loc) · 1.45 KB
/
sample-input.js
File metadata and controls
44 lines (36 loc) · 1.45 KB
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
/**
* @author André Storhaug <andr3.storhaug@gmail.com> and Hans Georg Schaathun <hasc@ntnu.no>
* @copyright 2018 NTNU
*/
define(['qtype_sample/visual-math-input'], function (VisualMath) {
return {
initialize: () => {
let readOnly = false;
let $shortanswerInput = $('.sample .answer input');
// Remove class "d-inline" added in shortanswer renderer class, which prevents input from being hidden.
$shortanswerInput.removeClass('d-inline');
let input = new VisualMath.Input($shortanswerInput, '.answer');
input.$input.hide();
if (!input.$input.prop('readonly')) {
input.onEdit = ($input, field) => {
// $input.val(field.latex());
$input.val('\\[' + field.latex() + '\\]');
console.log($input.val());
$input.get(0).dispatchEvent(new Event('change')); // Event firing needs to be on a vanilla dom object.
};
} else {
readOnly = true;
input.disable();
}
if ($shortanswerInput.val()) {
input.field.write(
$shortanswerInput.val().slice(2,-2)
);
}
if (!readOnly) {
let controls = new VisualMath.ControlList('#controls_wrapper');
controls.enableAll();
}
}
};
});