Add data-mx-theme to theme css for hot-reload

pull/21833/head
Dariusz Niemczyk 2021-08-01 16:18:06 +02:00 committed by Dariusz Niemczyk
parent 3ea0571c5f
commit 7fd14c9ccc
No known key found for this signature in database
GPG Key ID: 0AD2F70C94CA5B03
1 changed files with 4 additions and 9 deletions

View File

@ -171,15 +171,10 @@ export async function setTheme(theme) {
// look for the stylesheet elements.
// styleElements is a map from style name to HTMLLinkElement.
const styleElements = Object.create(null);
let a;
for (let i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
const href = a.getAttribute("href");
// shouldn't we be using the 'title' tag rather than the href?
const match = href && href.match(/^bundles\/.*\/theme-(.*)\.css$/);
if (match) {
styleElements[match[1]] = a;
}
}
const themes = Array.from(document.querySelectorAll('[data-mx-theme]'));
themes.forEach(theme => {
styleElements[theme.attributes['data-mx-theme'].value.toLowerCase()] = theme;
});
if (!(stylesheetName in styleElements)) {
throw new Error("Unknown theme " + stylesheetName);