-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (88 loc) · 2.73 KB
/
index.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(function() {
'use strict';
var isArray = function isArray(x) {
return Array.isArray(x);
};
var isDefined = function isDefined(x) {
return 'undefined' !== typeof x;
};
var isInstance = function isInstance(x, of ) {
return x && isSet( of ) && x instanceof of ;
};
var isNull = function isNull(x) {
return null === x;
};
var isObject = function isObject(x, isPlain) {
if (isPlain === void 0) {
isPlain = true;
}
if ('object' !== typeof x) {
return false;
}
return isPlain ? isInstance(x, Object) : true;
};
var isSet = function isSet(x) {
return isDefined(x) && !isNull(x);
};
var toCount = function toCount(x) {
return x.length;
};
var D = document;
var W = window;
var R = D.documentElement;
var getElements = function getElements(query, scope) {
return (scope || D).querySelectorAll(query);
};
var letClasses = function letClasses(node, classes) {
if (isArray(classes)) {
return classes.forEach(function(name) {
return node.classList.remove(name);
}), node;
}
if (isObject(classes)) {
for (var name in classes) {
classes[name] && node.classList.remove(name);
}
return node;
}
return node.className = "", node;
};
var setClass = function setClass(node, value) {
return node.classList.add(value), node;
};
var offEvent = function offEvent(name, node, then) {
node.removeEventListener(name, then);
};
var offEvents = function offEvents(names, node, then) {
names.forEach(function(name) {
return offEvent(name, node, then);
});
};
var onEvent = function onEvent(name, node, then, options) {
if (options === void 0) {
options = false;
}
node.addEventListener(name, then, options);
};
var onEvents = function onEvents(names, node, then, options) {
if (options === void 0) {
options = false;
}
names.forEach(function(name) {
return onEvent(name, node, then, options);
});
};
function onChange() {
let toggles = getElements('[name="state[x][panel][skin][variant]"]:not(:disabled)');
toCount(toggles) && toggles.forEach(toggle => {
offEvents(['blur', 'change'], toggle, onChangeToggle);
onEvents(['blur', 'change'], toggle, onChangeToggle);
});
}
onChange();
function onChangeToggle() {
letClasses(R, ['is:dark', 'is:light']);
setClass(R, 'is:' + this.value);
}
W._.on('change', onChange);
})();