-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (77 loc) · 2.39 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
window.addEventListener('load', function pageIsFullyLoaded () {
const html = document.documentElement;
const form = document.getElementById('faq__control-panel');
const dirControl = document.getElementById('ltr-rtl-toggle');
const animationControl = document.getElementById('animation-toggle');
const faqContainer = document.getElementById('faq__container');
const removeLocalStorageItemControl = document.getElementById('remove-local-storage-item');
const storageName = 'chrome-vertical-line-break-effect-issue-for-clip-path-property';
function toggleDir (condition) {
if (condition) {
html.setAttribute('dir', 'rtl');
}
else {
html.setAttribute('dir', 'ltr');
}
return condition;
}
function toggleAnimation (condition) {
if (condition) {
faqContainer.classList.add('faq__container--animate');
}
else {
faqContainer.classList.remove('faq__container--animate');
}
}
function getLocalStorage (sn = storageName, parse = true) {
const ls = window.localStorage.getItem(sn);
if (parse) {
return JSON.parse(ls);
}
return ls;
}
function setLocalStorage (sn = storageName, state = {}) {
return window.localStorage.setItem(sn, JSON.stringify({
...getLocalStorage(sn),
...state
}))
}
function removeLocalStorageItem(lsn = storageName) {
window.localStorage.removeItem(storageName);
}
if (!getLocalStorage(storageName, false)) {
setLocalStorage(storageName, {
animate: false,
dir: 'ltr'
});
}
else {
const { animate, dir } = getLocalStorage();
animationControl.checked = animate;
toggleAnimation(animate);
dirControl.checked = (dir === 'rtl');
toggleDir(dir === 'rtl');
}
dirControl.onchange = function dirControlOnChange() {
setLocalStorage(storageName, {dir: this.checked ? 'rtl' : 'ltr'})
return toggleDir(this.checked)
};
animationControl.onchange = function animationControlOnChange() {
setLocalStorage(storageName, {animate: this.checked})
return toggleAnimation(this.checked);
};
removeLocalStorageItemControl.onclick = function removeLocalStorageItemControlOnClick () {
const originInnerText = this.innerText;
removeLocalStorageItem(storageName);
clearTimeout(this.timeout);
this.setAttribute('disabled', 'disabled');
this.innerText = 'Now it\'s cleared!'
setTimeout(() => {
this.innerText = originInnerText;
this.removeAttribute('disabled');
}, 3000);
toggleDir();
toggleAnimation();
form.reset();
};
});