-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
let darkMode = localStorage.getItem('darkMode'); | ||
const darkModeToggle = document.querySelector('.btn-toggle'); | ||
|
||
const enableDarkModeOnInit = () => { | ||
document.documentElement.setAttribute('data-theme', 'dark'); | ||
document.documentElement.setAttribute('class', 'has-background-dark'); | ||
document.getElementById('icon-toggle').classList.add('fa-sun-o'); | ||
document.body.classList.add('dark-theme'); | ||
localStorage.setItem('darkMode', 'enabled'); | ||
} | ||
|
||
const enableDarkMode = () => { | ||
document.documentElement.setAttribute('data-theme', 'dark'); | ||
document.documentElement.setAttribute('class', document.documentElement.getAttribute('class').replace('has-background-light', 'has-background-dark')); | ||
document.getElementById('icon-toggle').classList.replace('fa-moon-o','fa-sun-o'); | ||
document.body.classList.add('dark-theme'); | ||
localStorage.setItem('darkMode', 'enabled'); | ||
} | ||
|
||
const disableDarkModeOnInit = () => { | ||
document.documentElement.setAttribute('data-theme','light'); | ||
document.documentElement.setAttribute('class','has-background-light'); | ||
document.getElementById('icon-toggle').classList.add('fa-moon-o'); | ||
document.body.classList.remove('dark-theme'); | ||
localStorage.setItem('darkMode', 'disabled') | ||
} | ||
|
||
const disableDarkMode = () => { | ||
document.documentElement.setAttribute('data-theme', 'light'); | ||
document.documentElement.setAttribute('class', document.documentElement.getAttribute('class').replace('has-background-dark', 'has-background-light')); | ||
document.getElementById('icon-toggle').classList.replace('fa-sun-o','fa-moon-o'); | ||
document.body.classList.remove('dark-theme'); | ||
localStorage.setItem('darkMode', 'disabled') | ||
} | ||
|
||
(() => { | ||
//Check if the user hasn't visited the site before. If yes, check what the preferred color scheme is. | ||
if (!darkMode) { | ||
if (window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
enableDarkModeOnInit(); | ||
} else { | ||
disableDarkModeOnInit(); | ||
} | ||
} | ||
|
||
if (darkMode === 'enabled') { | ||
enableDarkModeOnInit(); | ||
} else if (darkMode === 'disabled') { | ||
disableDarkModeOnInit(); | ||
} | ||
|
||
darkModeToggle.addEventListener('click', () => { | ||
darkMode = localStorage.getItem('darkMode'); | ||
if (darkMode !== 'enabled') { | ||
enableDarkMode(); | ||
} else { | ||
disableDarkMode(); | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters