remove css vars when switching theme

This commit is contained in:
Bruno Windels 2020-06-23 17:54:17 +02:00
parent e083856801
commit b3510aa2b4

View file

@ -35,6 +35,16 @@ export function enumerateThemes() {
return Object.assign({}, customThemeNames, BUILTIN_THEMES);
}
function clearCustomTheme() {
// remove all css variables, we assume these are there because of the custom theme
const inlineStyleProps = Object.values(document.body.style);
for (const prop of inlineStyleProps) {
if (prop.startsWith("--")) {
document.body.style.removeProperty(prop);
}
}
}
function setCustomThemeVars(customTheme) {
const {style} = document.body;
@ -97,6 +107,7 @@ export async function setTheme(theme) {
const themeWatcher = new ThemeWatcher();
theme = themeWatcher.getEffectiveTheme();
}
clearCustomTheme();
let stylesheetName = theme;
if (theme.startsWith("custom-")) {
const customTheme = getCustomTheme(theme.substr(7));