From 79aa4269eccfc6afdb6347b37956b16e7603f0b0 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 11 Jun 2022 15:49:16 +0530 Subject: Handle sub-directories, show error on 0 images --- resources/js/gallery.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'resources/js/gallery.js') diff --git a/resources/js/gallery.js b/resources/js/gallery.js index b7b7e06..d188e49 100644 --- a/resources/js/gallery.js +++ b/resources/js/gallery.js @@ -38,6 +38,18 @@ document.addEventListener('DOMContentLoaded', event => { */ // Packing after loading images //////////////////////////////////////////// +const showLoadingError = (message) => { + const loadError = document.getElementById("loading-error"); + const loadErrorText = document.getElementById("loading-error-text"); + const loadErrorDismiss = document.getElementById("loading-error-dismiss"); + loadError.style.display = "block"; + loadErrorText.innerHTML = message; + + loadErrorDismiss.addEventListener('click', function(){ + loadError.style.display = "none"; + }); +} + const onImagesLoaded = (container, event) => { const images = container.getElementsByTagName("img"); const progressBar = document.getElementById("loading-progress"); @@ -53,6 +65,11 @@ const onImagesLoaded = (container, event) => { let failed = 0; let remaining = images.length; + if (images.length === 0) { + showLoadingError("No images to display."); + event(remaining, failed, progressBar); + } + for (let i = 0; i < images.length; i++) { if (images[i].complete) remaining--; @@ -111,17 +128,9 @@ const imagesLoaded = (remaining, failed, progressBar) => { document.getElementById("loading").style.display = "none"; // Show error on failure. - const loadError = document.getElementById("loading-error"); - const loadErrorText = document.getElementById("loading-error-text"); - const loadErrorDismiss = document.getElementById("loading-error-dismiss"); if (failed !== 0) { - loadError.style.display = "block"; const t = failed === 1 ? "image" : "images"; - loadErrorText.innerHTML = `${failed} ${t} failed to load.`; - - loadErrorDismiss.addEventListener('click', function(){ - loadError.style.display = "none"; - }); + showLoadingError(`${failed} ${t} failed to load.`); } }; -- cgit 1.4.1-2-gfad0 nus/cetus/blame/LICENSE?id=944222f65a6c633e28638cba6ada5c7154aef3ed'>blame)
1
2
3
4
5
6
7
8
9
10
11
12
13