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
|
(function () {
const cookiesDisabled = !navigator.cookieEnabled;
if (cookiesDisabled) {
document.cookie = "disabled";
document.cookie.indexOf("disabled");
return console.warn("WARNING: Cannot persist form state due to cookie restrictions");
}
["pageshow", "URLChangedCustomEvent", "DOMContentLoaded"].forEach(function (event) {
self.addEventListener(event, function (event) {
const input = Array.prototype.slice.call(document.querySelectorAll("form input"));
const select = Array.prototype.slice.call(document.querySelectorAll("form select"));
const textarea = Array.prototype.slice.call(document.querySelectorAll("form textarea"));
const summary = Array.prototype.slice.call(document.querySelectorAll("details summary"));
const states = input.concat(select).concat(textarea);
for (var i = 0; i < states.length; i++) {
const state = states[i];
const sync = i === states.length - 1;
if (localStorage[state.id]) {
if (state.type === "radio" || state.type === "checkbox") {
if (localStorage[state.id] === "on") state.checked = true;
} else state.value = localStorage[state.id];
}
if (sync) self.dispatchEvent(new Event("storage"));
state.addEventListener("change", function (event) {
// console.log("INFO: STATE:", event.target);
// console.log("INFO: ID:", event.target.id);
// console.log("INFO: NAME:", event.target.name);
// console.log("INFO: TYPE:", event.target.type);
// console.log("INFO: VALUE:", event.target.value);
// console.log("INFO: CHECKED:", event.target.checked);
localStorage[event.target.id] = event.target.value;
const group = document.querySelectorAll(`input[name='${event.target.name}']`);
for (var j = 0; j < group.length; j++) {
const member = group[j];
if ((member.type === "radio" || member.type === "checkbox") && !member.checked) {
localStorage[member.id] = "off";
}
}
self.dispatchEvent(new Event("storage"));
});
}
for (var k = 0; k < summary.length; k++) {
let child = summary[k];
let details = child.parentElement;
if (details.id && details.nodeName === "DETAILS") {
sessionStorage[details.id] === "false" && details.removeAttribute("open");
sessionStorage[details.id] === "true" && details.setAttribute("open", true);
child.addEventListener("click", function (event) {
let details = event.target.parentElement;
sessionStorage[details.id] = !details.open;
});
}
}
});
});
["storage", "DOMContentLoaded"].forEach(function (event) {
self.addEventListener(event, function () {
let stylesheet;
stylesheet = document.querySelector('link[href$="default-simple.css"]')
if (localStorage["config.layout.simple"] === "on") stylesheet.rel = "stylesheet"
if (localStorage["config.layout.default"] === "on") stylesheet.rel = "alternate stylesheet"
stylesheet = document.querySelector('link[href$="default-fast.css"]')
if (localStorage["config.speed.fast"] === "on") stylesheet.rel = "stylesheet"
if (localStorage["config.speed.slow"] === "on") stylesheet.rel = "alternate stylesheet"
});
});
})();
|