Merge pull request #6584 from Simounet/fix/5808-auto-dark-theme-flickering

This commit is contained in:
Jérémy Benoist 2023-06-07 06:32:05 +02:00 committed by GitHub
commit 004de9e7c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 32 deletions

View file

@ -19,7 +19,7 @@ import './css/index.scss';
const mobileMaxWidth = 993; const mobileMaxWidth = 993;
function darkTheme() { (function darkTheme() {
const rootEl = document.querySelector('html'); const rootEl = document.querySelector('html');
const themeDom = { const themeDom = {
darkClass: 'dark-theme', darkClass: 'dark-theme',
@ -87,35 +87,42 @@ function darkTheme() {
return true; return true;
}, },
}; };
const addDarkThemeListeners = () => {
$(document).ready(() => {
const lightThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="light"]');
[...lightThemeButtons].map((lightThemeButton) => {
lightThemeButton.addEventListener('click', (e) => {
e.preventDefault();
themeDom.removeClass(rootEl);
themeCookie.setCookie(false);
});
return true;
});
const darkThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="dark"]');
[...darkThemeButtons].map((darkThemeButton) => {
darkThemeButton.addEventListener('click', (e) => {
e.preventDefault();
themeDom.addClass(rootEl);
themeCookie.setCookie(true);
});
return true;
});
const autoThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="auto"]');
[...autoThemeButtons].map((autoThemeButton) => {
autoThemeButton.addEventListener('click', (e) => {
e.preventDefault();
themeCookie.removeCookie();
preferedColorScheme.choose();
});
return true;
});
});
};
preferedColorScheme.init(); preferedColorScheme.init();
const lightThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="light"]'); addDarkThemeListeners();
[...lightThemeButtons].map((lightThemeButton) => { }());
lightThemeButton.addEventListener('click', (e) => {
e.preventDefault();
themeDom.removeClass(rootEl);
themeCookie.setCookie(false);
});
return true;
});
const darkThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="dark"]');
[...darkThemeButtons].map((darkThemeButton) => {
darkThemeButton.addEventListener('click', (e) => {
e.preventDefault();
themeDom.addClass(rootEl);
themeCookie.setCookie(true);
});
return true;
});
const autoThemeButtons = document.querySelectorAll('.js-theme-toggle[data-theme="auto"]');
[...autoThemeButtons].map((autoThemeButton) => {
autoThemeButton.addEventListener('click', (e) => {
e.preventDefault();
themeCookie.removeCookie();
preferedColorScheme.choose();
});
return true;
});
}
const stickyNav = () => { const stickyNav = () => {
const nav = $('.js-entry-nav-top'); const nav = $('.js-entry-nav-top');
@ -150,7 +157,6 @@ const articleScroll = () => {
$(document).ready(() => { $(document).ready(() => {
// sideNav // sideNav
$('.button-collapse').sideNav(); $('.button-collapse').sideNav();
darkTheme();
$('select').material_select(); $('select').material_select();
$('.collapsible').collapsible({ $('.collapsible').collapsible({
accordion: false, accordion: false,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long