pages/assets/js/theme.js
JD e30a46bbfa
Issue 105 : Dark Mode + Theming #118 (#119)
* Dark Mode + Theming

* Themes scss file created with default color scheme and dark color scheme.

* Logic for managing dark mode toggle added.

* Modified existing scss/html to work with theme toggling.

* Fixed hover issues

* Added enable_darkmode to configs.  

* Added the requested option of disabling/enabling dark mode via config files.
2020-10-04 20:32:47 -04:00

18 lines
453 B
JavaScript

//Has to be in the head tag, otherwise a flicker effect will occur.
let initTheme = (theme) => {
if (theme == null) {
const userPref = window.matchMedia;
if (userPref && userPref('(prefers-color-scheme: dark)').matches) {
theme = 'dark';
}
}
if (theme) {
document.documentElement.setAttribute('data-theme', theme)
}
localStorage.setItem("theme", theme);
}
initTheme(localStorage.getItem("theme"));