mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-26 19:15:16 +02:00
fix(js): theming flash
Fix case of potential theming flash when `day_night` disabled.
Fix 6c434e6de2
This commit is contained in:
parent
6c434e6de2
commit
0eb331a7f6
1 changed files with 12 additions and 1 deletions
|
@ -23,11 +23,15 @@ function canChangeTheme() {
|
||||||
// flashing between the default theme mode and the user's choice.
|
// flashing between the default theme mode and the user's choice.
|
||||||
function initThemeVariation() {
|
function initThemeVariation() {
|
||||||
if (!canChangeTheme()) {
|
if (!canChangeTheme()) {
|
||||||
return;
|
return {
|
||||||
|
isDarkTheme: window.wc.isSiteThemeDark,
|
||||||
|
themeMode: window.wc.isSiteThemeDark ? 1 : 0,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentThemeMode = getThemeMode();
|
let currentThemeMode = getThemeMode();
|
||||||
let isDarkTheme;
|
let isDarkTheme;
|
||||||
|
|
||||||
switch (currentThemeMode) {
|
switch (currentThemeMode) {
|
||||||
case 0:
|
case 0:
|
||||||
isDarkTheme = false;
|
isDarkTheme = false;
|
||||||
|
@ -48,6 +52,7 @@ function initThemeVariation() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDarkTheme && !body.classList.contains('dark')) {
|
if (isDarkTheme && !body.classList.contains('dark')) {
|
||||||
console.debug('Applying Wowchemy dark theme');
|
console.debug('Applying Wowchemy dark theme');
|
||||||
document.body.classList.add("dark");
|
document.body.classList.add("dark");
|
||||||
|
@ -55,6 +60,7 @@ function initThemeVariation() {
|
||||||
console.debug('Applying Wowchemy light theme');
|
console.debug('Applying Wowchemy light theme');
|
||||||
document.body.classList.remove("dark");
|
document.body.classList.remove("dark");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isDarkTheme: isDarkTheme,
|
isDarkTheme: isDarkTheme,
|
||||||
themeMode: currentThemeMode,
|
themeMode: currentThemeMode,
|
||||||
|
@ -100,6 +106,11 @@ function showActiveTheme(mode) {
|
||||||
let linkLight = document.querySelector('.js-set-theme-light');
|
let linkLight = document.querySelector('.js-set-theme-light');
|
||||||
let linkDark = document.querySelector('.js-set-theme-dark');
|
let linkDark = document.querySelector('.js-set-theme-dark');
|
||||||
let linkAuto = document.querySelector('.js-set-theme-auto');
|
let linkAuto = document.querySelector('.js-set-theme-auto');
|
||||||
|
|
||||||
|
if (linkLight === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0:
|
case 0:
|
||||||
// Light.
|
// Light.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue