-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathhistoire.setup.ts
39 lines (34 loc) · 1022 Bytes
/
histoire.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import './histoire.css'
import './src/style.css'
// development
if (document.readyState == 'complete') {
updateThemeAttrOnThemeChange()
}
// production
window.addEventListener('DOMContentLoaded', () => {
updateThemeAttrOnThemeChange()
})
function updateThemeAttrOnThemeChange() {
let observer = new MutationObserver((mutations) => {
for (const m of mutations) {
const newValue = m.target.getAttribute(m.attributeName)
if (newValue === 'htw-dark') {
document.documentElement.setAttribute('data-theme', 'dark')
} else {
document.documentElement.setAttribute('data-theme', 'light')
}
}
})
// observe changes to the class attribute on root element
observer.observe(document.documentElement, {
attributes: true,
attributeOldValue: true,
attributeFilter: ['class'],
})
}
// handle route param in url
const urlParams = new URLSearchParams(window.location.search)
const route = urlParams.get('route')
if (route) {
history.pushState({}, '', route)
}