mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Move theme and custom css to react components
This commit is contained in:
parent
27f4b8a7e5
commit
88b247596a
8 changed files with 159 additions and 143 deletions
|
@ -1,16 +1,7 @@
|
|||
import { getDefaultTheme, getThemes as getConfiguredThemes } from './settings/webSettings';
|
||||
|
||||
let themeStyleElement = document.querySelector('#cssTheme');
|
||||
let currentThemeId;
|
||||
|
||||
function unloadTheme() {
|
||||
const elem = themeStyleElement;
|
||||
if (elem) {
|
||||
elem.removeAttribute('href');
|
||||
currentThemeId = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getThemes() {
|
||||
return getConfiguredThemes();
|
||||
}
|
||||
|
@ -29,11 +20,7 @@ function getThemeStylesheetInfo(id) {
|
|||
theme = getDefaultTheme();
|
||||
}
|
||||
|
||||
return {
|
||||
stylesheetPath: 'themes/' + theme.id + '/theme.css',
|
||||
themeId: theme.id,
|
||||
color: theme.color
|
||||
};
|
||||
return theme;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -45,36 +32,12 @@ function setTheme(id) {
|
|||
}
|
||||
|
||||
getThemeStylesheetInfo(id).then(function (info) {
|
||||
if (currentThemeId && currentThemeId === info.themeId) {
|
||||
if (currentThemeId && currentThemeId === info.id) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
const linkUrl = info.stylesheetPath;
|
||||
unloadTheme();
|
||||
|
||||
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);
|
||||
themeStyleElement = link;
|
||||
currentThemeId = info.themeId;
|
||||
currentThemeId = info.id;
|
||||
|
||||
document.getElementById('themeColor').content = info.color;
|
||||
});
|
||||
|
@ -82,6 +45,6 @@ function setTheme(id) {
|
|||
}
|
||||
|
||||
export default {
|
||||
getThemes: getThemes,
|
||||
setTheme: setTheme
|
||||
getThemes,
|
||||
setTheme
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue