mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-01-22 14:35:43 -06:00
✨[#676] Add logo dark/light mode switching mechanism
This commit is contained in:
parent
92f26f9bdd
commit
b8f23598c8
2 changed files with 27 additions and 3 deletions
|
@ -26,16 +26,20 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
|||
const switcher = document.getElementById("appearance-switcher");
|
||||
const switcherMobile = document.getElementById("appearance-switcher-mobile");
|
||||
|
||||
var targetAppearance = document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||
updateMeta()
|
||||
updateLogo(targetAppearance)
|
||||
|
||||
if (switcher) {
|
||||
switcher.addEventListener("click", () => {
|
||||
document.documentElement.classList.toggle("dark");
|
||||
var targetAppearance = document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||
localStorage.setItem(
|
||||
"appearance",
|
||||
document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||
targetAppearance
|
||||
);
|
||||
updateMeta()
|
||||
updateLogo(targetAppearance)
|
||||
});
|
||||
switcher.addEventListener("contextmenu", (event) => {
|
||||
event.preventDefault();
|
||||
|
@ -45,11 +49,13 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
|||
if (switcherMobile) {
|
||||
switcherMobile.addEventListener("click", () => {
|
||||
document.documentElement.classList.toggle("dark");
|
||||
var targetAppearance = document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||
localStorage.setItem(
|
||||
"appearance",
|
||||
document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||
targetAppearance
|
||||
);
|
||||
updateMeta()
|
||||
updateLogo(targetAppearance)
|
||||
});
|
||||
switcherMobile.addEventListener("contextmenu", (event) => {
|
||||
event.preventDefault();
|
||||
|
@ -65,3 +71,20 @@ var updateMeta = () => {
|
|||
style = getComputedStyle(elem);
|
||||
document.querySelector('meta[name="theme-color"]').setAttribute('content', style.backgroundColor);
|
||||
}
|
||||
|
||||
var updateLogo = (targetAppearance) => {
|
||||
{{ if and (.Site.Params.Logo) (.Site.Params.SecondaryLogo) }}
|
||||
{{ $primaryLogo := resources.Get .Site.Params.Logo }}
|
||||
{{ $secondaryLogo := resources.Get .Site.Params.SecondaryLogo }}
|
||||
{{ if and ($primaryLogo) ($secondaryLogo) }}
|
||||
var elems;
|
||||
elems = document.querySelectorAll("img.logo")
|
||||
targetLogoPath =
|
||||
targetAppearance == "{{ .Site.Params.DefaultAppearance }}" ?
|
||||
"{{ $primaryLogo.RelPermalink }}" : "{{ $secondaryLogo.RelPermalink }}"
|
||||
for (const elem of elems) {
|
||||
elem.setAttribute("src", targetLogoPath)
|
||||
}
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ rtl = false
|
|||
|
||||
title = "Blowfish"
|
||||
# logo = "img/logo.png"
|
||||
# secondaryLogo = "img/secondary-logo.png"
|
||||
# description = "My awesome website"
|
||||
# copyright = "Copy, _right?_ :thinking_face:"
|
||||
|
||||
|
|
Loading…
Reference in a new issue