From 73635a5f031d6dad4f7f722a210959aa4ff52d37 Mon Sep 17 00:00:00 2001 From: "Claw (AI)" Date: Wed, 13 May 2026 23:09:12 +0000 Subject: [PATCH] fix(js): improve lightbox WebP fallback error handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use .off('error') to prevent stacking error handlers - Simplify fallback logic: only replace .webp → .png on error - Prevents infinite error loops --- js/haus-schleusingen.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/js/haus-schleusingen.js b/js/haus-schleusingen.js index 76b690e..1d6bf06 100644 --- a/js/haus-schleusingen.js +++ b/js/haus-schleusingen.js @@ -46,10 +46,11 @@ $(function () { // Lightbox – gallery grid items $(document).on("click", ".grid-item", function () { var src = $(this).data("img") || $(this).find("img").attr("src"); - $("#lightboxImg").on("error", function () { + $("#lightboxImg").off("error").on("error", function () { // WebP fallback: try original format - var fallback = src.replace(/\.webp$/, src.endsWith('.webp') ? '.png' : '.jpg'); - if ($(this).attr('src') !== fallback) $(this).attr('src', fallback); + if ($(this).attr('src').endsWith('.webp')) { + $(this).attr('src', src.replace(/\.webp$/, '.png')); + } }); $("#lightboxImg").attr("src", src); $("#lightbox").addClass("open"); @@ -59,9 +60,10 @@ $(function () { // Lightbox – floor plan images in Raumaufteilung $(document).on("click", ".floor-plan img[data-img]", function () { var src = $(this).data("img"); - $("#lightboxImg").on("error", function () { - var fallback = src.replace(/\.webp$/, '.png'); - if ($(this).attr('src') !== fallback) $(this).attr('src', fallback); + $("#lightboxImg").off("error").on("error", function () { + if ($(this).attr('src').endsWith('.webp')) { + $(this).attr('src', src.replace(/\.webp$/, '.png')); + } }); $("#lightboxImg").attr("src", src); $("#lightbox").addClass("open");