mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2023-12-21 10:22:58 +01:00
theme-switch-button: improve logic
- owner can set dark/light/auto default theme - theme toggle will be enabled on all theme modes unless disbaled - if disableThemeToggle is true, user won't be able to switch themes, here auto (a/c to system theme) also works for #69
This commit is contained in:
parent
229df19ec9
commit
0eed773e6d
@ -50,7 +50,7 @@
|
|||||||
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
|
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
|
{{- if (and (not .Site.Params.disableThemeToggle) (not (eq .Site.Params.defaultTheme "auto"))) }}
|
||||||
<script>
|
<script>
|
||||||
document.getElementById("theme-toggle").addEventListener("click", () => {
|
document.getElementById("theme-toggle").addEventListener("click", () => {
|
||||||
if (document.body.className.includes("dark")) {
|
if (document.body.className.includes("dark")) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
|
{{- if (and (not .Site.Params.disableThemeToggle) (not (eq .Site.Params.defaultTheme "auto"))) }}
|
||||||
<script>
|
<script>
|
||||||
// load memory
|
// load memory
|
||||||
if (localStorage.getItem("pref-theme") === "dark") {
|
if (localStorage.getItem("pref-theme") === "dark") {
|
||||||
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if (and (.Site.Params.disableThemeToggle) (eq .Site.Params.defaultTheme "auto")) }}
|
{{- if (eq .Site.Params.defaultTheme "auto") }}
|
||||||
<script>
|
<script>
|
||||||
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
document.body.classList.add('dark');
|
document.body.classList.add('dark');
|
||||||
@ -41,7 +41,7 @@
|
|||||||
{{- .Site.Params.label.text | default .Site.Title -}}
|
{{- .Site.Params.label.text | default .Site.Title -}}
|
||||||
</a>
|
</a>
|
||||||
<span class="logo-switches">
|
<span class="logo-switches">
|
||||||
{{- if (and (not .Site.Params.disableThemeToggle) (not (or (eq .Site.Params.defaultTheme "light") (eq .Site.Params.defaultTheme "dark")))) }}
|
{{- if (not .Site.Params.disableThemeToggle) }}
|
||||||
<span class="theme-toggle">
|
<span class="theme-toggle">
|
||||||
<a id="theme-toggle" accesskey="t">
|
<a id="theme-toggle" accesskey="t">
|
||||||
<svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
|
<svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
|
||||||
|
Loading…
Reference in New Issue
Block a user