summary refs log tree commit diff stats
path: root/resources
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2022-06-11 15:49:16 +0530
committerAndinus <andinus@nand.sh>2022-06-11 15:49:16 +0530
commit79aa4269eccfc6afdb6347b37956b16e7603f0b0 (patch)
treeda5dfefba6c53336df25caf66a91406d329c451f /resources
parent74d75501d6ac26e84f07d25a04a4639bcf1d5f61 (diff)
downloadcrater-79aa4269eccfc6afdb6347b37956b16e7603f0b0.tar.gz
Handle sub-directories, show error on 0 images
Diffstat (limited to 'resources')
-rw-r--r--resources/js/gallery.js27
1 files changed, 18 insertions, 9 deletions
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.`);
     }
 };