-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (39 loc) · 1.22 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
(function () {
'use strict';
var toCount = function toCount(x) {
return x.length;
};
var D = document;
var R = D.documentElement;
var getElements = function getElements(query, scope) {
return (scope || D).querySelectorAll(query);
};
var getParent = function getParent(node, query) {
if (query) {
return node.closest(query) || null;
}
return node.parentNode || null;
};
var toggleClass = function toggleClass(node, name, force) {
return node.classList.toggle(name, force), node;
};
var offEventDefault = function offEventDefault(e) {
return e && e.preventDefault();
};
var onEvent = function onEvent(name, node, then, options) {
if (options === void 0) {
options = false;
}
node.addEventListener(name, then, options);
};
var toggles = getElements('.toggle');
toCount(toggles) && toggles.forEach(function (toggle) {
onEvent('click', toggle, function (e) {
toggleClass(this, 'active');
toggleClass(R, 'is:aside-visible');
R.scrollTop = 0;
getParent(R).scrollTop = 0;
offEventDefault(e);
});
});
})();