move js files
This commit is contained in:
parent
8793f9736a
commit
252eac442e
6 changed files with 6 additions and 6 deletions
35
assets/javascript/radioState.js
Normal file
35
assets/javascript/radioState.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Radio button state management with localStorage
|
||||
function initRadioState() {
|
||||
// Store and retrieve radio button state
|
||||
const radioButtons = document.querySelectorAll('input[name="mode"]');
|
||||
|
||||
// Load saved state on page load
|
||||
const savedMode = localStorage.getItem('selectedMode');
|
||||
if (savedMode) {
|
||||
const radioToCheck = document.getElementById(savedMode);
|
||||
if (radioToCheck) {
|
||||
radioToCheck.checked = true;
|
||||
// Set the data attribute to match the saved mode
|
||||
document.documentElement.setAttribute('data-website-mode', savedMode);
|
||||
}
|
||||
} else {
|
||||
// If no saved state, set to the currently checked radio button
|
||||
const checkedRadio = document.querySelector('input[name="mode"]:checked');
|
||||
if (checkedRadio) {
|
||||
document.documentElement.setAttribute('data-website-mode', checkedRadio.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Save state when radio button changes
|
||||
radioButtons.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.checked) {
|
||||
localStorage.setItem('selectedMode', this.id);
|
||||
// Update the data attribute when mode changes
|
||||
document.documentElement.setAttribute('data-website-mode', this.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export { initRadioState };
|
Loading…
Add table
Add a link
Reference in a new issue