-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsheet_selector.js
More file actions
32 lines (24 loc) · 1.03 KB
/
sheet_selector.js
File metadata and controls
32 lines (24 loc) · 1.03 KB
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
window.addEventListener("load", () => {
const previewBlocks = Array.from(document.getElementsByClassName("rd-sheet-selector-previews"));
const previews = previewBlocks.flatMap(b => Array.from(b.children))
const preview = (elem) => {
if (!elem) {
return;
}
previews.forEach((p) => {
p.classList.remove("selected");
p.ariaHidden = true;
});
let index = parseInt(elem.dataset.previewIndex ?? -1);
if (index < 0) {
return;
}
previews[index].classList.add("selected");
previews[index].ariaHidden = false;
}
const radios = Array.from(document.querySelectorAll('.rd-sheet-preview input[type="radio"]'))
radios.forEach(radio => radio.addEventListener("click", () => preview(radio)))
// Show the preview for any default selected option when the page loads
const currentlySelected = document.querySelector('.rd-sheet-preview input[type="radio"]:checked');
preview(currentlySelected);
});