Debian Codegraph @

docs/index.js

raw
1 // Get the <select> element
2 const select = document.querySelector("select");
3
4 // Get the current theme
5 let currentTheme = select.value;
6
7 // Whenever user chooses a new option from the <select> dropdown, reload all the
8 // iframes on the page with examples from the new chosen theme
9 select.addEventListener("change", (event) => {
10 const nextTheme = event.currentTarget.value;
11 document.querySelectorAll("iframe").forEach((element) => {
12 // Replace theme name in URL to load example from new theme
13 element.src = element.src.replace(currentTheme, nextTheme);
14 });
15 currentTheme = nextTheme;
16 });