Spaces:
Running
Running
| // Code-sample tab switcher. Progressive enhancement: with JS disabled every | |
| // panel except the first stays hidden via the `hidden` attribute in the markup, | |
| // so the page still shows one working example. | |
| document.querySelectorAll(".code-tabs").forEach((tabs) => { | |
| const buttons = [...tabs.querySelectorAll("button")]; | |
| const panels = buttons.map((b) => document.getElementById(b.dataset.panel)); | |
| const select = (i) => { | |
| buttons.forEach((b, j) => b.setAttribute("aria-selected", String(i === j))); | |
| panels.forEach((p, j) => p && (p.hidden = i !== j)); | |
| }; | |
| buttons.forEach((b, i) => b.addEventListener("click", () => select(i))); | |
| select(0); | |
| }); | |