Files
serinty-website/docs/js/theme.js
T
Sven Jörns 56e02634b3 Squashed 'themes/zolastrap/' content from commit df5d3ee
git-subtree-dir: themes/zolastrap
git-subtree-split: df5d3ee5cc738a0666c61028566608bf93de2303
2022-06-29 18:59:02 +03:00

37 lines
777 B
JavaScript

function activeTheme(theme) {
document.querySelectorAll(
'nav a.dropdown-item[onclick^="switchTheme("]'
).forEach(function (a) {
a.classList.remove('active')
})
const a = document.querySelector(
'nav a.dropdown-item[onclick="switchTheme(\''+theme+'\')"]'
)
if (a) {
a.classList.add('active')
}
}
function switchTheme(theme) {
sessionStorage.setItem("theme", theme)
activeTheme(theme)
document
.querySelectorAll('link.alternate')
.forEach(function (e) {
if (e.id == theme) {
e.rel = "stylesheet"
} else {
e.rel = "stylesheet alternate"
}
})
}
var theme = sessionStorage.getItem("theme")
if (theme) {
switchTheme(theme)
}
window.addEventListener('load', function () {
activeTheme(theme)
})