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();
|
||||
})
|
||||
.then(function(css) {
|
||||
let style = document.querySelector('#cssBranding');
|
||||
if (!style) {
|
||||
// Inject the branding css as a dom element in body so it will take
|
||||
// precedence over other stylesheets
|
||||
var style = document.createElement('style');
|
||||
style.appendChild(document.createTextNode(css));
|
||||
style = document.createElement('style');
|
||||
style.id = 'cssBranding';
|
||||
document.body.appendChild(style);
|
||||
}
|
||||
style.textContent = css;
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.warn('Error applying custom css', err);
|
||||
|
|
|
@ -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');
|
||||
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');
|
||||
link.onload = function () {
|
||||
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;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue