diff options
author | Dessalines <tyhou13@gmx.com> | 2019-11-11 19:24:40 -0800 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-11-11 19:24:40 -0800 |
commit | 408b0efd48d73e1222b5e783fe1f02b9573f8e1b (patch) | |
tree | 48cc66c1dffea0c17cbba825cbaddb78f49bfe71 /ui/src/utils.ts | |
parent | a4033baa4ce10dfc8035ab1d09feb12303b25787 (diff) |
Dynamically loading CSS theme, removing all but darkly from index.html
- Fixes #333
Diffstat (limited to 'ui/src/utils.ts')
-rw-r--r-- | ui/src/utils.ts | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/ui/src/utils.ts b/ui/src/utils.ts index 9d2e720e..b63f0cab 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -290,12 +290,24 @@ export const themes = [ ]; export function setTheme(theme: string = 'darkly') { + // unload all the other themes for (var i = 0; i < themes.length; i++) { let styleSheet = document.getElementById(themes[i]); - if (themes[i] == theme) { - styleSheet.removeAttribute('disabled'); - } else { + if (styleSheet) { styleSheet.setAttribute('disabled', 'disabled'); } } + + // Load the theme dynamically + if (!document.getElementById(theme)) { + var head = document.getElementsByTagName('head')[0]; + var link = document.createElement('link'); + link.id = theme; + link.rel = 'stylesheet'; + link.type = 'text/css'; + link.href = `/static/assets/css/themes/${theme}.min.css`; + link.media = 'all'; + head.appendChild(link); + } + document.getElementById(theme).removeAttribute('disabled'); } |