fix saving of mobile theme, add IE compatibility

This commit is contained in:
recanman 2024-01-27 09:18:05 -08:00
parent 38301f8715
commit 35203f4eda

View File

@ -67,12 +67,20 @@ if (document.body.clientWidth < 940) {
] ]
] ]
// Switch the theme when the theme switcher is clicked. const checkMobileTheme = () => {
themeSwitcher.addEventListener('change', () => {
const theme = themeVariables[themeSwitcher.checked ? 1 : 0]; const theme = themeVariables[themeSwitcher.checked ? 1 : 0];
theme.forEach(variable => { theme.forEach(variable => {
document.documentElement.style.setProperty(`--${variable.name}`, variable.value); document.documentElement.style.setProperty(`--${variable.name}`, variable.value);
}); });
}); };
// Ensure IE compatibility
if (document.addEventListener) {
themeSwitcher.addEventListener('change', checkMobileTheme);
} else if (document.attachEvent) {
themeSwitcher.attachEvent('onchange', checkMobileTheme);
}
checkMobileTheme();
} }