diff --git a/assets/js/background-blur.js b/assets/js/background-blur.js index 95f7271f..e530c9d2 100644 --- a/assets/js/background-blur.js +++ b/assets/js/background-blur.js @@ -23,9 +23,18 @@ function setBackgroundBlur(targetId, scrollDivisor = 300, disableBlur = false, i blurElement.style.opacity = scroll / scrollDivisor; } }; + let framePending = false; + const requestBlurUpdate = () => { + if (framePending) return; + framePending = true; + window.requestAnimationFrame(() => { + framePending = false; + updateBlur(); + }); + }; blurElement.setAttribute("role", "presentation"); blurElement.setAttribute("tabindex", "-1"); - window.addEventListener("scroll", updateBlur); + window.addEventListener("scroll", requestBlurUpdate, { passive: true }); updateBlur(); } @@ -33,7 +42,12 @@ document.querySelectorAll("script[data-blur-id]").forEach((script) => { const targetId = script.getAttribute("data-blur-id"); const scrollDivisor = Number(script.getAttribute("data-scroll-divisor") || 300); const isMenuBlur = targetId === "menu-blur"; - const settings = JSON.parse(localStorage.getItem("a11ySettings") || "{}"); + let settings = {}; + try { + settings = JSON.parse(localStorage.getItem("a11ySettings") || "{}"); + } catch (_) { + settings = {}; + } const disableBlur = settings.disableBlur || false; setBackgroundBlur(targetId, scrollDivisor, disableBlur, isMenuBlur); }); diff --git a/layouts/partials/functions/resize.html b/layouts/partials/functions/resize.html new file mode 100644 index 00000000..cf39d293 --- /dev/null +++ b/layouts/partials/functions/resize.html @@ -0,0 +1,7 @@ +{{ $resource := .resource }} +{{ $spec := .spec }} +{{ $result := $resource }} +{{ with try ($resource.Resize $spec) }} + {{ with .Value }}{{ $result = . }}{{ end }} +{{ end }} +{{ return $result }} diff --git a/layouts/partials/hero/background.html b/layouts/partials/hero/background.html index 83b5c002..259de33c 100644 --- a/layouts/partials/hero/background.html +++ b/layouts/partials/hero/background.html @@ -42,7 +42,7 @@ {{ $featuredURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} {{ $size := site.Store.Get "backgroundImageWidth" }} - {{ $featuredURL = (.Resize $size).RelPermalink }} + {{ $featuredURL = (partial "functions/resize.html" (dict "resource" . "spec" $size)).RelPermalink }} {{ end }} {{ end }} {{ end }} diff --git a/layouts/partials/hero/basic.html b/layouts/partials/hero/basic.html index acf5b5fc..9d7625cd 100644 --- a/layouts/partials/hero/basic.html +++ b/layouts/partials/hero/basic.html @@ -42,7 +42,7 @@ {{ $featuredURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} {{ $size := site.Store.Get "backgroundImageWidth" }} - {{ $featuredURL = (.Resize $size).RelPermalink }} + {{ $featuredURL = (partial "functions/resize.html" (dict "resource" . "spec" $size)).RelPermalink }} {{ end }} {{ end }} {{ end }} diff --git a/layouts/partials/hero/big.html b/layouts/partials/hero/big.html index 7e0d85d4..8c5a6679 100644 --- a/layouts/partials/hero/big.html +++ b/layouts/partials/hero/big.html @@ -42,7 +42,7 @@ {{ $featuredURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} {{ $size := site.Store.Get "backgroundImageWidth" }} - {{ $featuredURL = (.Resize $size).RelPermalink }} + {{ $featuredURL = (partial "functions/resize.html" (dict "resource" . "spec" $size)).RelPermalink }} {{ end }} {{ end }} {{ end }} diff --git a/layouts/partials/hero/thumbAndBackground.html b/layouts/partials/hero/thumbAndBackground.html index e342ebfd..ff9e3666 100644 --- a/layouts/partials/hero/thumbAndBackground.html +++ b/layouts/partials/hero/thumbAndBackground.html @@ -29,7 +29,7 @@ {{ $backgroundURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} {{ $size := site.Store.Get "backgroundImageWidth" }} - {{ $backgroundURL = (.Resize $size).RelPermalink }} + {{ $backgroundURL = (partial "functions/resize.html" (dict "resource" . "spec" $size)).RelPermalink }} {{ end }} {{ end }} {{ end }} @@ -74,7 +74,7 @@ {{ $featuredURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} {{ $size := site.Store.Get "backgroundImageWidth" }} - {{ $featuredURL = (.Resize $size).RelPermalink }} + {{ $featuredURL = (partial "functions/resize.html" (dict "resource" . "spec" $size)).RelPermalink }} {{ end }} {{ end }} {{ end }}