1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Reorder CSS loading

This commit is contained in:
Dmitry Lyzo 2020-08-13 00:15:02 +03:00
parent 808a670b55
commit c32f83a19e
2 changed files with 27 additions and 13 deletions

View file

@ -1,13 +1,12 @@
import * as webSettings from 'webSettings';
var themeStyleElement;
var themeStyleElement = document.querySelector('#cssTheme');
var currentThemeId;
function unloadTheme() {
var elem = themeStyleElement;
if (elem) {
elem.parentNode.removeChild(elem);
themeStyleElement = null;
elem.removeAttribute('href');
currentThemeId = null;
}
}
@ -45,15 +44,26 @@ function setTheme(id) {
var linkUrl = info.stylesheetPath;
unloadTheme();
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.onload = function () {
let link = themeStyleElement;
if (!link) {
// Inject the theme css as a dom element in body so it will take
// precedence over other stylesheets
link = document.createElement('link');
link.id = 'cssTheme';
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
document.body.appendChild(link);
}
const onLoad = function (e) {
e.target.removeEventListener('load', onLoad);
resolve();
};
link.addEventListener('load', onLoad);
link.setAttribute('href', linkUrl);
document.head.appendChild(link);
themeStyleElement = link;
currentThemeId = info.themeId;
});