-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathboolean.js
More file actions
39 lines (32 loc) · 731 Bytes
/
boolean.js
File metadata and controls
39 lines (32 loc) · 731 Bytes
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
import Setting from './setting.js';
export default class extends Setting {
constructor(name = 'boolean') { // Allows extension
super(name);
}
value(val, { extraValue } = {}) {
if (typeof val === 'boolean') return val;
return ['1', 'true', 1, `${extraValue}`].includes(val);
}
element(value, update, {
remove = false,
}) {
return $(`<input type="checkbox">`)
.prop('checked', value)
.on('change.script', (e) => update(getValue(e.target, remove)));
}
default() {
return false;
}
labelFirst() {
return false;
}
get isBasic() {
return true;
}
}
function getValue(el, remove = false) {
if (el.checked) {
return 1;
}
return remove ? undefined : 0;
}