forked from alshedivat/al-folio
-
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.
Correctly update medium-zoom background when switching theme (alshedi…
- Loading branch information
1 parent
495c4aa
commit 9c8bd1a
Showing
4 changed files
with
47 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,51 @@ | ||
// Has to be in the head tag, otherwise a flicker effect will occur. | ||
|
||
let toggleTheme = (theme) => { | ||
if (theme == "dark") { | ||
setTheme("light"); | ||
} else { | ||
setTheme("dark"); | ||
} | ||
} | ||
|
||
|
||
let setTheme = (theme) => { | ||
transTheme(); | ||
if (theme) { | ||
document.documentElement.setAttribute("data-theme", theme); | ||
} | ||
else { | ||
document.documentElement.removeAttribute("data-theme"); | ||
} | ||
localStorage.setItem("theme", theme); | ||
|
||
// Updates the background of medium-zoom overlay. | ||
if (typeof medium_zoom !== 'undefined') { | ||
medium_zoom.update({ | ||
background: getComputedStyle(document.documentElement) | ||
.getPropertyValue('--global-bg-color') + 'ee', // + 'ee' for trasparency. | ||
}) | ||
} | ||
}; | ||
|
||
|
||
let transTheme = () => { | ||
document.documentElement.classList.add("transition"); | ||
window.setTimeout(() => { | ||
document.documentElement.classList.remove("transition"); | ||
}, 500) | ||
} | ||
|
||
|
||
let initTheme = (theme) => { | ||
if (theme == null) { | ||
const userPref = window.matchMedia; | ||
if (userPref && userPref('(prefers-color-scheme: dark)').matches) { | ||
theme = 'dark'; | ||
} | ||
} | ||
|
||
if (theme) { | ||
document.documentElement.setAttribute('data-theme', theme) | ||
} | ||
|
||
localStorage.setItem("theme", theme); | ||
setTheme(theme); | ||
} | ||
|
||
|
||
initTheme(localStorage.getItem("theme")); |
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,8 +1,8 @@ | ||
|
||
// Initialize medium zoom. | ||
$(document).ready(function() { | ||
mediumZoom('[data-zoomable]', { | ||
margin: 100, | ||
background: getComputedStyle(document.documentElement) | ||
.getPropertyValue('--global-bg-color') + 'ee', | ||
}) | ||
medium_zoom = mediumZoom('[data-zoomable]', { | ||
margin: 100, | ||
background: getComputedStyle(document.documentElement) | ||
.getPropertyValue('--global-bg-color') + 'ee', // + 'ee' for trasparency. | ||
}) | ||
}); |