forked from lydell/elm-safe-virtual-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
115 lines (111 loc) · 3.3 KB
/
index.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DOM</title>
</head>
<body>
<div id="main"></div>
<button id="reorder">Ändra ordning</button>
<button id="steal">Stjäl</button>
<button id="insert">Ny</button>
<button id="remove">Ta bort</button>
<button id="replace">Ersätt</button>
<div id="stolen" style="border: solid"></div>
<script src="elm.js"></script>
<script>
reorder.onclick = () => {
document.body.appendChild(
document.body.childNodes[
Math.floor(
Math.random() * Math.max(0, document.body.childNodes.length - 1)
)
]
);
};
steal.onclick = () => {
const node =
document.body.childNodes[
Math.floor(
Math.random() * Math.max(0, document.body.childNodes.length - 1)
)
];
if (node !== stolen) {
stolen.appendChild(node);
}
};
insert.onclick = () => {
const node =
document.body.childNodes[
Math.floor(
Math.random() * Math.max(0, document.body.childNodes.length - 1)
)
];
document.body.insertBefore(document.createElement("hr"), node);
};
remove.onclick = () => {
const node =
document.body.childNodes[
Math.floor(
Math.random() * Math.max(0, document.body.childNodes.length - 1)
)
];
node.remove();
document.body.appendChild(
document.createTextNode(`Tog bort: ${node.outerHTML || node.data}`)
);
};
replace.onclick = () => {
const node =
document.body.childNodes[
Math.floor(
Math.random() * Math.max(0, document.body.childNodes.length - 1)
)
];
node.replaceWith(
document.createTextNode(
`Ersatt: ${node.outerHTML || JSON.stringify(node.data)}`
)
);
};
new MutationObserver(console.log).observe(document.documentElement, {
subtree: true,
childList: true,
attributes: true,
});
customElements.define(
"custom-element",
class extends HTMLElement {
connectedCallback() {
console.log(
"Setting custom-element content. Previous content:",
this.innerHTML
);
this.innerHTML = "<br>Content inside custom element.";
}
}
);
if (Elm.Main) {
Elm.Main.init({
virtualize: (node) => node === document.body,
});
} else if (Elm.Sandbox) {
Elm.Sandbox.init({ node: document.getElementById("main") });
} else if (Elm.KeyList) {
Elm.KeyList.init({
node: document.getElementById("main"),
time: "render",
});
} else if (Elm.ElmUi) {
Elm.ElmUi.init({ node: document.getElementById("main") });
} else {
throw new Error("No known Elm module", Elm);
}
setTimeout(() => {
document.body.appendChild(document.createElement("hr"));
});
</script>
</body>
</html>