switcher: reset selection after browser back navigation

This commit is contained in:
Sören Weber 2025-03-20 21:29:05 +01:00
parent 3ccc8f777f
commit 7a2667a7d3
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
8 changed files with 65 additions and 30 deletions
assets/js

View file

@ -1444,6 +1444,42 @@ function scrollToPositions() {
}
}
function handleHistoryClearer() {
document.querySelectorAll('.R-historyclearer button').forEach(function (select) {
select.addEventListener('click', function (event) {
clearHistory();
});
});
}
function handleLanguageSwitcher() {
document.querySelectorAll('.R-languageswitcher select').forEach(function (select) {
select.addEventListener('change', function (event) {
const url = this.options[`R-select-language-${this.value}`].dataset.url;
this.value = this.querySelector('[data-selected]')?.value ?? select.value;
window.location = url;
});
});
}
function handleVariantSwitcher() {
document.querySelectorAll('.R-variantswitcher select').forEach(function (select) {
select.addEventListener('change', function (event) {
window.relearn.changeVariant(this.value);
});
});
}
function handleVersionSwitcher() {
document.querySelectorAll('.R-versionswitcher select').forEach(function (select) {
select.addEventListener('change', function (event) {
const url = (this.options[`R-select-version-${this.value}`].dataset.abs == 'true' ? '' : window.relearn.relBaseUri) + this.options[`R-select-version-${this.value}`].dataset.uri + window.relearn.path;
this.value = this.querySelector('[data-selected]')?.value ?? select.value;
window.location = url;
});
});
}
window.addEventListener('popstate', function (event) {
scrollToPositions();
});
@ -1757,6 +1793,10 @@ function ready(fn) {
ready(function () {
initArrowVerticalNav();
initArrowHorizontalNav();
handleHistoryClearer();
handleLanguageSwitcher();
handleVariantSwitcher();
handleVersionSwitcher();
initMermaid();
initOpenapi();
initMenuScrollbar();