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