-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
79 lines (64 loc) · 1.88 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RadioRadio: Example</title>
<style>
body {
color: #333;
font-family: sans-serif;
line-height: 1.5;
padding: 3rem;
}
button {
background-color: #ddd;
border-radius: 0.25rem;
font-family: inherit;
font-size: 1rem;
font-weight: bold;
padding: 0.5rem 1rem;
}
[aria-hidden] {
display: none !important;
}
</style>
</head>
<body>
<h1>RadioRadio: Example</h1>
<h2>Showing <span>all</span> items.</h3>
<button data-show="all">Show all items</button>
<button data-show="even">Show even items</button>
<button data-show="odd">Show odd items</button>
<ul id="list">
<li class="odd">Item #1</li>
<li class="even">Item #2</li>
<li class="odd">Item #3</li>
<li class="even">Item #4</li>
<li class="odd">Item #5</li>
<li class="even">Item #6</li>
</ul>
<script type="module">
import * as RadioRadio from "../src/radioradio.js";
const title = document.querySelector("h2 span");
const buttons = document.querySelectorAll("button");
const listItems = document.querySelectorAll("#list li");
const handleClick = (event) => {
RadioRadio.publish("update", {
show: event.currentTarget.getAttribute("data-show"),
});
};
buttons.forEach(button => button.addEventListener("click", handleClick));
RadioRadio.subscribe("update.title", ({ show }) => {
for (const listItem of listItems) {
if (show === "all" || listItem.classList.contains(show)) {
listItem.removeAttribute("aria-hidden");
} else {
listItem.setAttribute("aria-hidden", true);
}
}
});
RadioRadio.subscribe("update.list", ({ show }) => title.innerHTML = show);
</script>
</body>
</html>