From e706a5f14fa134eb13361e41f73e7d1c87e0ce63 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Wed, 2 Apr 2025 13:54:25 +0800 Subject: fix: console error when post nav is not present Former-commit-id: 2b546a57852cacbfb3f204d5b552a039440478fb --- layouts/partials/components/global-search.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'layouts/partials') diff --git a/layouts/partials/components/global-search.html b/layouts/partials/components/global-search.html index c1051ee4..9311416d 100644 --- a/layouts/partials/components/global-search.html +++ b/layouts/partials/components/global-search.html @@ -107,8 +107,8 @@ }); const searchInstruction = document.getElementById("search-instruction"); - searchInstruction.addEventListener("click", (event) => { - turnOn(); - }); + if (searchInstruction) { + searchInstruction.addEventListener("click", turnOn); + } })(); -- cgit v1.2.3 From 6581552a1201ceabec5595cd2f31138e39e1bd1a Mon Sep 17 00:00:00 2001 From: Eltrac Date: Wed, 2 Apr 2025 14:24:40 +0800 Subject: feat: double-click to turn off global search also clearer comment Former-commit-id: 27af269ad0a26e858217b71ba5d4697bdb791ae8 --- layouts/partials/components/global-search.html | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'layouts/partials') diff --git a/layouts/partials/components/global-search.html b/layouts/partials/components/global-search.html index 9311416d..5b158abe 100644 --- a/layouts/partials/components/global-search.html +++ b/layouts/partials/components/global-search.html @@ -106,9 +106,15 @@ } }); + // trigger by clicking instruction text + // to allow mobile users to search const searchInstruction = document.getElementById("search-instruction"); if (searchInstruction) { searchInstruction.addEventListener("click", turnOn); } + + // double-click to turn off search + // in case esc and ctrl/cmd+k cannot be used + search.addEventListener("dblclick", turnOff); })(); -- cgit v1.2.3 From 8bcbdf938f1f53afdd2f18ea1dce6c7efcf8ce97 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Wed, 2 Apr 2025 14:33:40 +0800 Subject: perf: load fancybox only in single pages Former-commit-id: 0b221b7f8f0ecb006fc9f17e01e7689a3cc3a816 --- layouts/partials/scripts.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'layouts/partials') diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index b22c8989..dbf6aee0 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -8,9 +8,12 @@ {{- end }} -{{- $fancybox := resources.Get "js/fancybox.js" | minify }} -{{- if $fancybox }} - +{{- if or (in .Section "posts") (in .Section "cards") (in .Section "library") (eq .Type "single") }} + + {{- $fancybox := resources.Get "js/fancybox.js" | minify }} + {{- if $fancybox }} + + {{- end }} {{- end }}