Zulma-Theme/static/js/switchcss.js

42 lines
989 B
JavaScript
Raw Normal View History

const THEME_KEY = "ZULMA_THEME";
2019-05-06 22:16:37 +01:00
let theme = localStorage.getItem(THEME_KEY);
if (theme) {
changeTheme(theme);
document.querySelectorAll('#theme-select>option').forEach(element => {
if (element.value === theme) {
element.selected = 'selected';
}
});
}
function changeTheme(themeName) {
let alternates = [];
document.querySelectorAll('link.stylesheet').forEach(element => {
if (element.id === themeName) {
2019-05-06 22:16:37 +01:00
element.disabled = false;
element.media = '';
}
else {
alternates.push(element);
}
});
alternates.forEach(element => {
2019-05-06 22:16:37 +01:00
element.disabled = true;
element.media = 'none';
});
saveTheme(themeName);
}
function saveTheme(themeName) {
localStorage.setItem(THEME_KEY, themeName);
}
window.addEventListener('load', () => {
document.getElementById('theme-select').onchange = function () {
changeTheme(this.value);
}
});