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:
parent
808a670b55
commit
c32f83a19e
2 changed files with 27 additions and 13 deletions
|
@ -384,11 +384,15 @@ function initClient() {
|
||||||
return response.text();
|
return response.text();
|
||||||
})
|
})
|
||||||
.then(function(css) {
|
.then(function(css) {
|
||||||
// Inject the branding css as a dom element in body so it will take
|
let style = document.querySelector('#cssBranding');
|
||||||
// precedence over other stylesheets
|
if (!style) {
|
||||||
var style = document.createElement('style');
|
// Inject the branding css as a dom element in body so it will take
|
||||||
style.appendChild(document.createTextNode(css));
|
// precedence over other stylesheets
|
||||||
document.body.appendChild(style);
|
style = document.createElement('style');
|
||||||
|
style.id = 'cssBranding';
|
||||||
|
document.body.appendChild(style);
|
||||||
|
}
|
||||||
|
style.textContent = css;
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
console.warn('Error applying custom css', err);
|
console.warn('Error applying custom css', err);
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import * as webSettings from 'webSettings';
|
import * as webSettings from 'webSettings';
|
||||||
|
|
||||||
var themeStyleElement;
|
var themeStyleElement = document.querySelector('#cssTheme');
|
||||||
var currentThemeId;
|
var currentThemeId;
|
||||||
|
|
||||||
function unloadTheme() {
|
function unloadTheme() {
|
||||||
var elem = themeStyleElement;
|
var elem = themeStyleElement;
|
||||||
if (elem) {
|
if (elem) {
|
||||||
elem.parentNode.removeChild(elem);
|
elem.removeAttribute('href');
|
||||||
themeStyleElement = null;
|
|
||||||
currentThemeId = null;
|
currentThemeId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,15 +44,26 @@ function setTheme(id) {
|
||||||
var linkUrl = info.stylesheetPath;
|
var linkUrl = info.stylesheetPath;
|
||||||
unloadTheme();
|
unloadTheme();
|
||||||
|
|
||||||
var link = document.createElement('link');
|
let link = themeStyleElement;
|
||||||
link.setAttribute('rel', 'stylesheet');
|
|
||||||
link.setAttribute('type', 'text/css');
|
if (!link) {
|
||||||
link.onload = function () {
|
// 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();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
link.addEventListener('load', onLoad);
|
||||||
|
|
||||||
link.setAttribute('href', linkUrl);
|
link.setAttribute('href', linkUrl);
|
||||||
document.head.appendChild(link);
|
|
||||||
themeStyleElement = link;
|
themeStyleElement = link;
|
||||||
currentThemeId = info.themeId;
|
currentThemeId = info.themeId;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue