Skip to content

Commit 456d2e6

Browse files
authored
Fix broken dark mode switch button icon (#50)
Signed-off-by: Hofi <[email protected]>
2 parents 98a4809 + 66bd702 commit 456d2e6

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

_includes/skins.html

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,14 @@
7070
return getSkinForState(getSkinModeState());
7171
}
7272

73-
function toggleSkin(event) {
74-
const currentSkinState = getSkinModeState();
75-
if (currentSkinState == darkModeStateOff) {
76-
event.target.classList.remove('fa-toggle-on');
77-
event.target.classList.add('fa-toggle-off');
78-
}
79-
else {
80-
event.target.classList.remove('fa-toggle-off');
81-
event.target.classList.add('fa-toggle-on');
82-
}
83-
setSkinModeState(currentSkinState == darkModeStateOff ? darkModeStateOn : darkModeStateOff);
84-
event.currentTarget.blur();
85-
}
86-
8773
function saveColorChanges() {
8874
const htmlStyle = window.getComputedStyle(document.documentElement);
8975
const backgroundColor = htmlStyle.backgroundColor;
9076
setCookie(selectedSkinBackgroundColorKey, backgroundColor);
9177
};
9278

93-
function toggleIcon(target, off) {
94-
if (off) {
79+
function setIcon(target, isOff) {
80+
if (isOff) {
9581
target.classList.remove('fa-toggle-on');
9682
target.classList.add('fa-toggle-off');
9783
}
@@ -105,7 +91,7 @@
10591
var off = getSkinModeState() == darkModeStateOff;
10692

10793
setSkinModeState(off ? darkModeStateOn : darkModeStateOff);
108-
toggleIcon(event.target, off);
94+
setIcon(event.target, off == false);
10995

11096
event.currentTarget.blur();
11197
}
@@ -121,8 +107,10 @@
121107
// Why this is not working?!?!
122108
//document.body.style.removeProperty("backgroundColor");
123109
document.body.style.backgroundColor = "";
124-
125-
toggleIcon($('#skin-button').find('.masthead_button_icon')[0], getSkinModeState());
110+
111+
var currSkinModeState = getSkinModeState();
112+
setIcon($('#skin-button').find('.masthead_button_icon')[0], currSkinModeState == darkModeStateOff);
113+
126114
$("#skin-button").on("click", toggleSkin);
127115

128116
// TODO: See, setSkinModeState - stylesheet.onload

0 commit comments

Comments
 (0)