mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-05-24 18:54: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
docs/assets/js
|
@ -45,29 +45,29 @@ var variants = {
|
|||
|
||||
addCustomVariantOption: function () {
|
||||
var customvariant = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant');
|
||||
var select = document.querySelector('#R-select-variant');
|
||||
if (!customvariant || !select) {
|
||||
if (!customvariant ) {
|
||||
return;
|
||||
}
|
||||
var option = document.querySelector('#R-select-variant-' + this.customvariantname);
|
||||
if (!option) {
|
||||
option = document.createElement('option');
|
||||
option.id = 'R-select-variant-' + this.customvariantname;
|
||||
option.value = this.customvariantname;
|
||||
option.text = this.customvariantname.replace(/-/g, ' ').replace(/\w\S*/g, function (w) {
|
||||
return w.replace(/^\w/g, function (c) {
|
||||
return c.toUpperCase();
|
||||
document.querySelectorAll('.R-variantswitcher select').forEach((select) => {
|
||||
var option = select.options[`R-select-variant-${this.customvariantname}`];
|
||||
if (!option) {
|
||||
option = document.createElement('option');
|
||||
option.id = `R-select-variant-${this.customvariantname}`;
|
||||
option.value = this.customvariantname;
|
||||
option.text = this.customvariantname.replace(/-/g, ' ').replace(/\w\S*/g, function (w) {
|
||||
return w.replace(/^\w/g, function (c) {
|
||||
return c.toUpperCase();
|
||||
});
|
||||
});
|
||||
});
|
||||
select.appendChild(option);
|
||||
}
|
||||
select.appendChild(option);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeCustomVariantOption: function () {
|
||||
var option = document.querySelector('#R-select-variant-' + this.customvariantname);
|
||||
if (option) {
|
||||
document.querySelectorAll(`.R-variantswitcher option[value=${this.customvariantname}]`).forEach((option) => {
|
||||
option.remove();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
addCustomVariantStyles: function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue