Widget:Guides/PlatformSwitcher

From pronounmail wiki
Revision as of 23:34, 6 December 2024 by Leah (talk | contribs)
Jump to navigation Jump to search

<form>

 <fieldset id="platform-switcher">
   <legend>Select your operating system:</legend>
   <label>
     <input type="radio" name="platform" value="windows" checked /> Windows
   </label>
   <label>
     <input type="radio" name="platform" value="macos" /> macOS
   </label>
   <label>
     <input type="radio" name="platform" value="linux" /> Linux
   </label>
   <label>
     <input type="radio" name="platform" value="haiku" /> Haiku
   </label>
 </fieldset>

</form>

<script type="module" defer> const containers = document.querySelectorAll('.platform-specific'); switch_thing('windows');

const fieldset = document.getElementById("platform-switcher");

for (const elem of fieldset.querySelectorAll('input')) {

 elem.addEventListener('change', () => switch_thing(elem.value))

}

function switch_thing(value) {

 for (const x of containers) {
   x.style.display = "none"
 }
 document.querySelector('.' + value).style.display = "block";

} </script>