mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-05-21 17:24:11 +00:00
switcher: reset selection after browser back navigation #1065
This commit is contained in:
parent
3ccc8f777f
commit
7a2667a7d3
8 changed files with 65 additions and 30 deletions
assets/js
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue