From 1e9458802ad04ad0456d6316811635fc942f3e02 Mon Sep 17 00:00:00 2001 From: Served Smart <195884188+servedsmart@users.noreply.github.com> Date: Tue, 24 Jun 2025 17:47:00 +0200 Subject: [PATCH] :recycle: Refactor: Use IIFE for background-blur and simplify code This improves readability and removes an unnecessary function declaration by using IIFE. This is inspired by https://github.com/nunocoracao/blowfish/pull/2262 . If both are merged, this would enhance consistency --- assets/js/background-blur.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/assets/js/background-blur.js b/assets/js/background-blur.js index e46df713..d2d0432b 100644 --- a/assets/js/background-blur.js +++ b/assets/js/background-blur.js @@ -1,15 +1,10 @@ -function setBackgroundBlur() { - const scriptElement = document.currentScript; - const targetId = - scriptElement && scriptElement.getAttribute("data-target-id") - ? scriptElement.getAttribute("data-target-id") - : (console.error("data-target-id is null"), null); +(() => { + const script = document.currentScript; + const targetId = script?.getAttribute("data-target-id"); window.addEventListener("scroll", () => { const scroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; const backgroundBlur = document.getElementById(targetId); backgroundBlur.style.opacity = scroll / 300; }); -} - -setBackgroundBlur(); +})();