mirror of https://github.com/lxndrblz/anatole.git

alexanderdavide
17.32.2022 91624833b8e18e158104756f9ac37218aec495ad
refactor: initialize theme with body class only
1 files modified
16 ■■■■ changed files
assets/js/anatole-theme-switcher.js 16 ●●●● patch | view | raw | blame | history
assets/js/anatole-theme-switcher.js
@@ -9,7 +9,6 @@
};
const setThemeStyle = (style) => {
  document.documentElement.setAttribute('data-theme', style);
  localStorage.setItem('theme', style);
  setThemeClass(style);
};
@@ -31,20 +30,13 @@
const initTheme = () => {
  const currThemeStyle = getStoredThemeStyle();
  const userPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
  if (currThemeStyle) {
    document.documentElement.setAttribute('data-theme', currThemeStyle);
    setThemeClass(currThemeStyle);
    setThemeStyle(currThemeStyle);
    return;
  }
  if (userPrefersDark) {
    setThemeStyle('dark');
  } else if (!document.documentElement.getAttribute('data-theme')) {
    setThemeStyle('light');
  } else {
    setThemeStyle(document.documentElement.getAttribute('data-theme'));
  }
  const userPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
  if (!userPrefersDark) return;
  setThemeStyle('dark');
};
document.addEventListener(