2019-05-06 00:23:38 +00:00
|
|
|
const THEME_KEY = "ZULMA_THEME";
|
|
|
|
|
2019-05-06 22:16:37 +01:00
|
|
|
let theme = localStorage.getItem(THEME_KEY);
|
|
|
|
if (theme) {
|
|
|
|
changeTheme(theme);
|
2019-05-06 23:18:32 +01:00
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
|
|
document.querySelectorAll('#theme-select>option').forEach(element => {
|
|
|
|
if (element.value === theme) {
|
|
|
|
element.selected = 'selected';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-05-06 22:16:37 +01:00
|
|
|
}
|
|
|
|
|
2019-05-06 23:18:32 +01:00
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
|
|
document.getElementById('theme-select').onchange = function () {
|
|
|
|
changeTheme(this.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-06 00:23:38 +00:00
|
|
|
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;
|
2019-05-06 23:08:24 +01:00
|
|
|
element.media = '';
|
2019-05-06 00:23:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
alternates.push(element);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
alternates.forEach(element => {
|
2019-05-06 22:16:37 +01:00
|
|
|
element.disabled = true;
|
2019-05-06 23:08:24 +01:00
|
|
|
element.media = 'none';
|
2019-05-06 00:23:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
saveTheme(themeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveTheme(themeName) {
|
|
|
|
localStorage.setItem(THEME_KEY, themeName);
|
2019-05-06 23:18:32 +01:00
|
|
|
}
|