Add eventlistener for change of day/night mode
And add a static js folder for js-files apart from the asset pipeline.
This commit is contained in:
10
priv/static/js/dark-mode.js
Normal file
10
priv/static/js/dark-mode.js
Normal file
@ -0,0 +1,10 @@
|
||||
function set_day_night_mode(){
|
||||
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
|
||||
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||||
document.documentElement.classList.add('dark')
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark')
|
||||
}
|
||||
}
|
||||
set_day_night_mode()
|
||||
matchMedia('(prefers-color-scheme: dark)').addEventListener("change", set_day_night_mode)
|
||||
Reference in New Issue
Block a user