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

19 lines
596 B
JavaScript
Raw Normal View History

2018-01-14 03:59:49 +01:00
import { loadCSS } from 'fg-loadcss';
2018-01-22 00:20:50 +01:00
let meta = process.browser && document.querySelector('meta[name="theme-color"]')
2018-01-14 03:59:49 +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`)
}
}