Skip to content

Commit

Permalink
Fix broken dark mode switch button icon (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Hofi <[email protected]>
  • Loading branch information
HofiOne authored May 21, 2024
2 parents 98a4809 + 66bd702 commit 456d2e6
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions _includes/skins.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,14 @@
return getSkinForState(getSkinModeState());
}

function toggleSkin(event) {
const currentSkinState = getSkinModeState();
if (currentSkinState == darkModeStateOff) {
event.target.classList.remove('fa-toggle-on');
event.target.classList.add('fa-toggle-off');
}
else {
event.target.classList.remove('fa-toggle-off');
event.target.classList.add('fa-toggle-on');
}
setSkinModeState(currentSkinState == darkModeStateOff ? darkModeStateOn : darkModeStateOff);
event.currentTarget.blur();
}

function saveColorChanges() {
const htmlStyle = window.getComputedStyle(document.documentElement);
const backgroundColor = htmlStyle.backgroundColor;
setCookie(selectedSkinBackgroundColorKey, backgroundColor);
};

function toggleIcon(target, off) {
if (off) {
function setIcon(target, isOff) {
if (isOff) {
target.classList.remove('fa-toggle-on');
target.classList.add('fa-toggle-off');
}
Expand All @@ -105,7 +91,7 @@
var off = getSkinModeState() == darkModeStateOff;

setSkinModeState(off ? darkModeStateOn : darkModeStateOff);
toggleIcon(event.target, off);
setIcon(event.target, off == false);

event.currentTarget.blur();
}
Expand All @@ -121,8 +107,10 @@
// Why this is not working?!?!
//document.body.style.removeProperty("backgroundColor");
document.body.style.backgroundColor = "";

toggleIcon($('#skin-button').find('.masthead_button_icon')[0], getSkinModeState());

var currSkinModeState = getSkinModeState();
setIcon($('#skin-button').find('.masthead_button_icon')[0], currSkinModeState == darkModeStateOff);

$("#skin-button").on("click", toggleSkin);

// TODO: See, setSkinModeState - stylesheet.onload
Expand Down

0 comments on commit 456d2e6

Please sign in to comment.