summaryrefslogtreecommitdiff
path: root/layouts/partials/footer.html
diff options
context:
space:
mode:
authorReorx <novoreorx@gmail.com>2022-05-27 22:40:21 +0800
committerReorx <novoreorx@gmail.com>2022-05-27 23:39:55 +0800
commit47a2fc815386d762d9e61376dce36c983787e093 (patch)
treef1d71a7c4a6331df169d3afe24982135b8e3ebd7 /layouts/partials/footer.html
parent28511efd081dba9dac8cbf8fa2c8135216264243 (diff)
refactor theme toggle; add delegate-it
Diffstat (limited to 'layouts/partials/footer.html')
-rw-r--r--layouts/partials/footer.html35
1 files changed, 21 insertions, 14 deletions
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index 67355d0..a38931d 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -26,6 +26,27 @@
{{- partial "extend_footer.html" . }}
+{{/* Load delegate script */}}
+{{- $delegate := resources.Get "js/delegate-it.js" }}
+<script src="{{ $delegate.RelPermalink }}" data-no-instant
+ {{- if site.Params.assets.disableFingerprinting }}integrity="{{ $delegate.Data.Integrity }}"{{- end }}
+></script>
+
+<script>
+ (function() {
+ /* theme toggle */
+ const disableThemeToggle = '{{ if site.Params.disableThemeToggle }}1{{ end }}' == '1';
+ if (disableThemeToggle) {
+ return;
+ }
+
+ // listen to toggle button
+ document.getElementById("theme-toggle").addEventListener("click", () => {
+ window.dispatchEvent(new CustomEvent('toggle-theme'));
+ });
+ })();
+</script>
+
<script>
(function () {
let menu = document.getElementById('menu')
@@ -75,20 +96,6 @@
</script>
{{- end }}
-{{- 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>
-{{- end }}
-
{{- /* Base64Email */}}
{{- if (.Param "MaskedEmail") }}
<script>