function onSwitch(event) { const option = event.target.selectedIndex; const item = event.target.options[option]; window.location.href = item.dataset.url; } document.addEventListener("readthedocs-addons-data-ready", function(event) { const config = event.detail.data() const versionSelect = ` `; // Prepend the current language to the options on the selector let languages = config.projects.translations.concat(config.projects.current); languages = languages.sort((a, b) => a.language.name.localeCompare(b.language.name)); const languageSelect = ` `; // Query all the placeholders because there are different ones for Desktop/Mobile const versionPlaceholders = document.querySelectorAll(".version_switcher_placeholder"); for (placeholder of versionPlaceholders) { placeholder.innerHTML = versionSelect; let selectElement = placeholder.querySelector("select"); selectElement.addEventListener("change", onSwitch); } const languagePlaceholders = document.querySelectorAll(".language_switcher_placeholder"); for (placeholder of languagePlaceholders) { placeholder.innerHTML = languageSelect; let selectElement = placeholder.querySelector("select"); selectElement.addEventListener("change", onSwitch); } });