summaryrefslogtreecommitdiff
path: root/layouts/partials/footer.html
diff options
context:
space:
mode:
authorAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-10-04 20:43:24 +0530
committerAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-10-04 20:43:24 +0530
commit6a9e9e129a46f1b6ebdc7622dcf0519b7a582d4e (patch)
tree94351ab1d69238679d925ee9427470a592323b1e /layouts/partials/footer.html
parentaf192360022f5ae6554eceeea3f9ed9892d70fa3 (diff)
theme-switch-button: init feature (#15)
* thanks to https://feathericons.com for svgs * can be disabled in site config Params: disableThemeToggle : true
Diffstat (limited to 'layouts/partials/footer.html')
-rw-r--r--layouts/partials/footer.html20
1 files changed, 19 insertions, 1 deletions
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index ff5cdd5..edf86ac 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -44,4 +44,22 @@
function menu_on_scroll() {
localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft);
}
-</script> \ No newline at end of file
+</script>
+{{- if not .Site.Params.disableThemeToggle }}
+<script>
+ document.getElementById("theme-toggle").addEventListener("click", () => {
+ if (document.body.className.includes("dark")) {
+ document.body.classList.remove('dark');
+ localStorage.setItem("pref-theme", 'light');
+ } else {
+ document.body.classList.add('dark');
+ localStorage.setItem("pref-theme", 'dark');
+ }
+ })
+</script>
+{{- else -}}
+<!-- case where owner disables theme button after deployment, this resets the stored theme -->
+<script>
+ localStorage.removeItem("pref-theme");
+</script>
+{{- end }} \ No newline at end of file