forked from rhazdon/hugo-theme-hello-friend-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Djordje Atlialp
committed
May 12, 2020
1 parent
c6ecbfb
commit 9474c64
Showing
2 changed files
with
18 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
// Toggle theme | ||
|
||
const getTheme = window.localStorage && window.localStorage.getItem("theme"); | ||
const theme = window.localStorage && window.localStorage.getItem("theme"); | ||
const themeToggle = document.querySelector(".theme-toggle"); | ||
const isDark = getTheme === "dark"; | ||
const isDark = theme === "dark"; | ||
var metaThemeColor = document.querySelector("meta[name=theme-color]"); | ||
|
||
if (getTheme !== null) { | ||
if (theme !== null) { | ||
document.body.classList.toggle("dark-theme", isDark); | ||
isDark ? metaThemeColor.setAttribute("content", "#252627") : metaThemeColor.setAttribute("content", "#fafafa"); | ||
isDark | ||
? metaThemeColor.setAttribute("content", "#252627") | ||
: metaThemeColor.setAttribute("content", "#fafafa"); | ||
} | ||
|
||
themeToggle.addEventListener("click", () => { | ||
document.body.classList.toggle("dark-theme"); | ||
window.localStorage && | ||
window.localStorage.setItem( | ||
"theme", | ||
document.body.classList.contains("dark-theme") ? "dark" : "light", | ||
document.body.classList.contains("dark-theme") ? "dark" : "light" | ||
); | ||
document.body.classList.contains("dark-theme") ? | ||
metaThemeColor.setAttribute("content", "#252627") : metaThemeColor.setAttribute("content", "#fafafa"); | ||
; | ||
document.body.classList.contains("dark-theme") | ||
? metaThemeColor.setAttribute("content", "#252627") | ||
: metaThemeColor.setAttribute("content", "#fafafa"); | ||
}); |