Skip to content

Commit

Permalink
Hide room on overview page while preview image fails to load
Browse files Browse the repository at this point in the history
This assumes that a room isn't 'live' when it is configured to have a
preview image but it cannot currently be loaded.
  • Loading branch information
mstock committed Dec 30, 2022
1 parent 2e17d91 commit 9c7a534
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions assets/js/lustiges-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<img />'),
src = $teaser.data('src');

Expand All @@ -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);
Expand Down

0 comments on commit 9c7a534

Please sign in to comment.