pinafore/routes/_utils/themeEngine.js

20 lines
587 B
JavaScript
Raw Normal View History

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