From 9c7a5348877719cf3bbbed2099b641fb8af01ce1 Mon Sep 17 00:00:00 2001 From: Manfred Stock Date: Thu, 29 Dec 2022 15:21:46 +0100 Subject: [PATCH] Hide room on overview page while preview image fails to load This assumes that a room isn't 'live' when it is configured to have a preview image but it cannot currently be loaded. --- assets/js/lustiges-script.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/assets/js/lustiges-script.js b/assets/js/lustiges-script.js index 288404d5..7833845d 100644 --- a/assets/js/lustiges-script.js +++ b/assets/js/lustiges-script.js @@ -299,12 +299,27 @@ $(function() { }); }); -// update teaser images +// update teaser images, hide/show room depending on teaser image availability $(function() { + var + roomSelector = '.room.has-preview', + previewSelector = roomSelector + ' .preview'; + + $(previewSelector).each(function() { + var + $teaser = $(this), + $room = $teaser.parents(roomSelector); + + $teaser.on('error', function() { + $room.addClass('hidden'); + }); + }); + setInterval(function() { - $('.room.has-preview .preview').each(function() { + $(previewSelector).each(function() { var $teaser = $(this), + $room = $teaser.parents(roomSelector), $preload = $(''), src = $teaser.data('src'); @@ -315,6 +330,9 @@ $(function() { $preload.on('load', function() { $teaser.prop('src', $preload.prop('src')); + $room.removeClass('hidden'); + }).on('error', function() { + $room.addClass('hidden'); }).prop('src', src + '?'+(new Date()).getTime()); }); }, 1000*60);