Skip to content

Commit

Permalink
Fix dark theme async loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Simounet committed Jul 21, 2023
1 parent b0903dc commit 5de28a7
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function _t (key, args) {
return value;
}

function darkTheme () {
(function darkTheme () {
const rootEl = document.querySelector('html');
const themeDom = {
darkClass: 'dark-theme',
Expand Down Expand Up @@ -122,29 +122,34 @@ function darkTheme () {
});
}
};
const addListeners = () => {
$(function () {
'use strict';
const themeButtonLow = document.querySelector('.js-theme-toggle-set[data-theme="light"]');
themeButtonLow.addEventListener('click', () => {
themeDom.removeClass(rootEl);
themeCookie.setCookie(false);
});
const themeButtonHigh = document.querySelector('.js-theme-toggle-set[data-theme="dark"]');
themeButtonHigh.addEventListener('click', () => {
themeDom.addClass(rootEl);
themeCookie.setCookie(true);
});
const themeButtonAuto = document.querySelector('.js-theme-toggle-set[data-theme="auto"]');
themeButtonAuto.addEventListener('click', () => {
themeCookie.removeCookie();
preferedColorScheme.choose();
});
});
};
preferedColorScheme.init();
const themeButtonLow = document.querySelector('.js-theme-toggle-set[data-theme="light"]');
themeButtonLow.addEventListener('click', () => {
themeDom.removeClass(rootEl);
themeCookie.setCookie(false);
});
const themeButtonHigh = document.querySelector('.js-theme-toggle-set[data-theme="dark"]');
themeButtonHigh.addEventListener('click', () => {
themeDom.addClass(rootEl);
themeCookie.setCookie(true);
});
const themeButtonAuto = document.querySelector('.js-theme-toggle-set[data-theme="auto"]');
themeButtonAuto.addEventListener('click', () => {
themeCookie.removeCookie();
preferedColorScheme.choose();
});
}
addListeners();
})();

$(function () {
'use strict';

anonymousState = $('[data-anonymous-state]').data('anonymous-state');
darkTheme();
undoMarkAsRead.init();

$('.wrapper').on('click keypress', '.js-event', function (event) {
Expand Down

0 comments on commit 5de28a7

Please sign in to comment.