« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/static/client2.js36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/static/client2.js b/src/static/client2.js
index 0a8eb860..8ae9876e 100644
--- a/src/static/client2.js
+++ b/src/static/client2.js
@@ -717,18 +717,32 @@ function handleImageLinkClicked(evt) {
 
   updateFileSizeInformation(originalFileSize);
 
-  const {thumb: mainThumb, length: mainLength} = getPreferredThumbSize(availableThumbList);
-  const {thumb: smallThumb, length: smallLength} = getSmallestThumbSize(availableThumbList);
-
-  const mainSrc = originalSrc.replace(/\.(jpg|png)$/, `.${mainThumb}.jpg`);
-  const thumbSrc = originalSrc.replace(/\.(jpg|png)$/, `.${smallThumb}.jpg`);
-
-  thumbImage.src = thumbSrc;
+  let mainSrc = null;
+  let thumbSrc = null;
+
+  if (availableThumbList) {
+    const {thumb: mainThumb, length: mainLength} = getPreferredThumbSize(availableThumbList);
+    const {thumb: smallThumb, length: smallLength} = getSmallestThumbSize(availableThumbList);
+    mainSrc = originalSrc.replace(/\.(jpg|png)$/, `.${mainThumb}.jpg`);
+    thumbSrc = originalSrc.replace(/\.(jpg|png)$/, `.${smallThumb}.jpg`);
+    // Show the thumbnail size on each <img> element's data attributes.
+    // Y'know, just for debugging convenience.
+    mainImage.dataset.displayingThumb = `${mainThumb}:${mainLength}`;
+    thumbImage.dataset.displayingThumb = `${smallThumb}:${smallLength}`;
+  } else {
+    mainSrc = originalSrc;
+    thumbSrc = null;
+    mainImage.dataset.displayingThumb = '';
+    thumbImage.dataset.displayingThumb = '';
+  }
 
-  // Show the thumbnail size on each <img> element's data attributes.
-  // Y'know, just for debugging convenience.
-  mainImage.dataset.displayingThumb = `${mainThumb}:${mainLength}`;
-  thumbImage.dataset.displayingThumb = `${smallThumb}:${smallLength}`;
+  if (thumbSrc) {
+    thumbImage.src = thumbSrc;
+    thumbImage.style.display = null;
+  } else {
+    thumbImage.src = '';
+    thumbImage.style.display = 'none';
+  }
 
   for (const viewOriginal of allViewOriginal) {
     viewOriginal.href = originalSrc;