소스 검색

fix(js): theming flash

Fix case of potential theming flash when `day_night` disabled.

Fix 6c434e6de205ab5877dd4879e225e995ca703499
George Cushen 4 년 전
부모
커밋
0eb331a7f6
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      wowchemy/assets/js/wowchemy-theming.js

+ 12 - 1
wowchemy/assets/js/wowchemy-theming.js

@@ -23,11 +23,15 @@ function canChangeTheme() {
 // flashing between the default theme mode and the user's choice.
 function initThemeVariation() {
   if (!canChangeTheme()) {
-    return;
+    return {
+      isDarkTheme: window.wc.isSiteThemeDark,
+      themeMode: window.wc.isSiteThemeDark ? 1 : 0,
+    };
   }
 
   let currentThemeMode = getThemeMode();
   let isDarkTheme;
+
   switch (currentThemeMode) {
     case 0:
       isDarkTheme = false;
@@ -48,6 +52,7 @@ function initThemeVariation() {
       }
       break;
   }
+
   if (isDarkTheme && !body.classList.contains('dark')) {
     console.debug('Applying Wowchemy dark theme');
     document.body.classList.add("dark");
@@ -55,6 +60,7 @@ function initThemeVariation() {
     console.debug('Applying Wowchemy light theme');
     document.body.classList.remove("dark");
   }
+
   return {
     isDarkTheme: isDarkTheme,
     themeMode: currentThemeMode,
@@ -100,6 +106,11 @@ function showActiveTheme(mode) {
   let linkLight = document.querySelector('.js-set-theme-light');
   let linkDark = document.querySelector('.js-set-theme-dark');
   let linkAuto = document.querySelector('.js-set-theme-auto');
+
+  if (linkLight === null) {
+    return;
+  }
+
   switch (mode) {
     case 0:
       // Light.