-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
60 lines (57 loc) · 2 KB
/
demo.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
// Dom interference buttons
const container = document.getElementById("dom-interference-container");
document
.getElementById("dom-interference-add-button")
?.addEventListener("click", () => {
const newButton = document.createElement("button");
newButton.innerHTML = `Button ${container.children.length + 1}`;
container.appendChild(newButton);
});
document
.getElementById("dom-interference-remove-button")
?.addEventListener("click", () => {
document
.querySelector("#dom-interference-container > :last-child")
?.remove();
});
// JIT options
const jitFocusgroup = document.getElementById("jit-focusgroup");
document.querySelectorAll(".jit-toggle").forEach((toggle) => {
toggle.addEventListener("change", (e) => {
let options = jitFocusgroup.getAttribute("focusgroup");
const optionToToggle = e.target.name;
if (options.includes(optionToToggle)) {
options = options.replace(optionToToggle, "");
} else {
options += ` ${optionToToggle}`;
}
jitFocusgroup.setAttribute("focusgroup", options.trim());
});
});
// Custom attribute testing
const testButton = document.getElementById("test-attribute");
const addAttribute = document.getElementById("add-attribute");
const removeAttribute = document.getElementById("remove-attribute");
const editAttribute = document.getElementById("edit-attribute");
const cloneDiv = document.getElementById("clone-div");
addAttribute?.addEventListener("click", () =>
testButton?.setAttribute("custom-attribute", "1")
);
removeAttribute?.addEventListener("click", () =>
testButton?.removeAttribute("custom-attribute")
);
editAttribute?.addEventListener("click", () =>
testButton?.setAttribute(
"custom-attribute",
`${
testButton !== null
? parseInt(testButton.getAttribute("custom-attribute") || "0") + 1
: 0
}`
)
);
cloneDiv?.addEventListener("click", (e) => {
if (!(e.target instanceof Element)) return;
const x = e.target?.parentElement.cloneNode(true);
document.body.prepend(x);
});