1
0
mirror of https://github.com/nolanlawson/pinafore synced 2025-02-02 22:57:36 +01:00

20 lines
587 B
JavaScript
Raw Normal View History

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