Pinafore-Web-Client-Frontend/routes/_utils/themeEngine.js

20 lines
587 B
JavaScript
Raw Normal View History

2018-02-09 07:29:29 +01:00
import { loadCSS } from 'fg-loadcss'
2018-01-14 03:59:49 +01:00
2018-02-16 17:59:44 +01:00
let meta = process.browser && document.getElementById('theThemeColor')
2018-01-22 00:20:50 +01:00
2018-02-09 07:29:29 +01:00
export function switchToTheme (themeName) {
2018-01-22 00:20:50 +01:00
let clazzList = document.body.classList
for (let i = 0; i < clazzList.length; i++) {
let clazz = clazzList.item(i)
2018-01-14 03:59:49 +01:00
if (clazz.startsWith('theme-')) {
2018-01-22 00:20:50 +01:00
clazzList.remove(clazz)
2018-01-14 03:59:49 +01:00
}
}
2018-01-22 00:20:50 +01:00
let themeColor = window.__themeColors[themeName]
meta.content = themeColor || window.__themeColors['default']
2018-01-14 03:59:49 +01:00
if (themeName !== 'default') {
2018-01-22 00:20:50 +01:00
clazzList.add(`theme-${themeName}`)
2018-01-14 03:59:49 +01:00
loadCSS(`/theme-${themeName}.css`)
}
2018-02-09 07:29:29 +01:00
}