Skip to content

Commit

Permalink
fix: make dark mode respect system preferences
Browse files Browse the repository at this point in the history
treat media query as system preferences instead of user prefers
  • Loading branch information
reuixiy committed Apr 2, 2020
1 parent cef984d commit 10d6cca
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions assets/js/dark-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ darkModeMediaQuery.addListener((e) => {
if (darkModeOn) {
changeModeMeta('dark');
changeMode('dark');
setMode('dark');
}
});

Expand All @@ -29,7 +28,6 @@ lightModeMediaQuery.addListener((e) => {
if (lightModeOn) {
changeModeMeta('light');
changeMode('light');
setMode('light');
}
});

Expand All @@ -44,11 +42,11 @@ themeSwitcher.addEventListener('click', function() {
if (currentMode === 'dark') {
changeModeMeta('light');
changeMode('light');
setMode('light');
storePrefers('light');
} else {
changeModeMeta('dark');
changeMode('dark');
setMode('dark');
storePrefers('dark');
}
});

Expand Down Expand Up @@ -102,6 +100,6 @@ function changeMode(theme) {
{{ end }}
}

function setMode(theme) {
function storePrefers(theme) {
window.localStorage.setItem('theme', theme);
}

0 comments on commit 10d6cca

Please sign in to comment.