-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
52 lines (42 loc) · 1.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="/src/up-and-down.js"></script>
<script src="/build/elm.js"></script>
</head>
<body>
<h1>Elm</h1>
<div id="elm"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('elm')
});
</script>
<h1>Vanilla Javascript</h1>
<up-and-down id="js-up-and-down">
<div slot="direction-label"><span>Going Nowhere</span></div>
</up-and-down>
<script>
$el = document.querySelector("#js-up-and-down");
let oldCount = $el.count;
$el.addEventListener("countChange", e => {
console.log("javascript countChange", e.detail.count, oldCount);
const newCount = e.detail.count;
const $slot = $el.querySelector("[slot='direction-label']");
const $newSlot = $slot.cloneNode(true);
const $label = $newSlot.querySelector("div span");
if (oldCount > newCount) {
$label.innerHTML = "Going down";
$el.replaceChild($newSlot, $slot);
}
else {
$label.innerHTML = "Going up";
$el.replaceChild($newSlot, $slot);
}
oldCount = newCount;
})
</script>
</body>
</html>