mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-07 18:14:28 +00:00
Sync color mode when navigating browser history
This commit is contained in:
@@ -42,6 +42,10 @@
|
|||||||
} else {
|
} else {
|
||||||
document.documentElement.setAttribute('data-bs-theme', theme)
|
document.documentElement.setAttribute('data-bs-theme', theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.navbar-mode-selector').forEach(chk => {
|
||||||
|
chk.checked = (document.documentElement.getAttribute('data-bs-theme') === 'light')
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// alternates the currently active theme
|
// alternates the currently active theme
|
||||||
@@ -58,26 +62,31 @@
|
|||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
setTheme(getTheme())
|
setTheme(getTheme())
|
||||||
|
const light = (document.documentElement.getAttribute('data-bs-theme') === 'light')
|
||||||
|
|
||||||
document.querySelectorAll('.ball').forEach(ball => {
|
document.querySelectorAll('.ball').forEach(ball => {
|
||||||
ball.classList.add('notransition');
|
ball.classList.add('notransition');
|
||||||
})
|
})
|
||||||
|
|
||||||
const chk = document.querySelectorAll('.navbar-mode-selector')
|
document.querySelectorAll('.navbar-mode-selector').forEach(chk => {
|
||||||
for (let i = 0; i < chk.length; ++i) {
|
chk.checked = light
|
||||||
if (document.documentElement.getAttribute('data-bs-theme') === 'light') {
|
chk.addEventListener('change', function () {
|
||||||
chk[i].click()
|
|
||||||
}
|
|
||||||
chk[i].addEventListener('change', function () {
|
|
||||||
toggleTheme()
|
toggleTheme()
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
|
||||||
document.querySelectorAll('.ball').forEach(ball => {
|
document.querySelectorAll('.ball').forEach(ball => {
|
||||||
ball.offsetHeight; // flush css changes
|
ball.offsetHeight; // flush css changes
|
||||||
ball.classList.remove('notransition');
|
ball.classList.remove('notransition');
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
const light = (document.documentElement.getAttribute('data-bs-theme') === 'light')
|
||||||
|
document.querySelectorAll('.navbar-mode-selector').forEach(chk => {
|
||||||
|
chk.checked = light
|
||||||
|
})
|
||||||
|
});
|
||||||
})()
|
})()
|
||||||
|
|
||||||
{{- end -}}
|
{{- end -}}
|
Reference in New Issue
Block a user