]> BookStack Code Mirror - bookstack/commitdiff
Improved loading for images with failed thumbnails
authorDan Brown <redacted>
Mon, 10 Jan 2022 18:12:11 +0000 (18:12 +0000)
committerDan Brown <redacted>
Mon, 10 Jan 2022 18:13:48 +0000 (18:13 +0000)
- A placeholder is now shown in the gallery.
- The page editors will use the original image url if the display
  thumbnail is missing.

For #3142

public/loading_error.png [new file with mode: 0644]
resources/js/components/image-manager.js
resources/js/components/markdown-editor.js
resources/js/components/wysiwyg-editor.js
resources/views/pages/parts/image-manager-form.blade.php

diff --git a/public/loading_error.png b/public/loading_error.png
new file mode 100644 (file)
index 0000000..4f588fb
Binary files /dev/null and b/public/loading_error.png differ
index c974ab1b0abd818d7be81c81d08ae56cf134cd6c..6d05d3388af6f8a21809daad455b3d3d46dc4972 100644 (file)
@@ -74,6 +74,10 @@ class ImageManager {
 
         this.listContainer.addEventListener('event-emit-select-image', this.onImageSelectEvent.bind(this));
 
+        this.listContainer.addEventListener('error', event => {
+            event.target.src = baseUrl('loading_error.png');
+        }, true);
+
         onSelect(this.selectButton, () => {
             if (this.callback) {
                 this.callback(this.lastSelected);
index a90f74e2746401562f59c03cea0b8824298f9dc8..def3db5af864f30cd6f321d2f47c80240b9b1dd1 100644 (file)
@@ -395,8 +395,9 @@ class MarkdownEditor {
     actionInsertImage() {
         const cursorPos = this.cm.getCursor('from');
         window.ImageManager.show(image => {
+            const imageUrl = image.thumbs.display || image.url;
             let selectedText = this.cm.getSelection();
-            let newText = "[![" + (selectedText || image.name) + "](" + image.thumbs.display + ")](" + image.url + ")";
+            let newText = "[![" + (selectedText || image.name) + "](" + imageUrl + ")](" + image.url + ")";
             this.cm.focus();
             this.cm.replaceSelection(newText);
             this.cm.setCursor(cursorPos.line, cursorPos.ch + newText.length);
index bde73f4bfb12aa2e87e4f3d250e7b76d8831e314..7a2b6ceba45b4aa492a351c6056c9d05f86d1364 100644 (file)
@@ -563,8 +563,9 @@ class WysiwygEditor {
                         }
 
                         // Replace the actively selected content with the linked image
+                        const imageUrl = image.thumbs.display || image.url;
                         let html = `<a href="${image.url}" target="_blank">`;
-                        html += `<img src="${image.thumbs.display}" alt="${image.name}">`;
+                        html += `<img src="${imageUrl}" alt="${image.name}">`;
                         html += '</a>';
                         win.tinyMCE.activeEditor.execCommand('mceInsertContent', false, html);
                     }, 'gallery');
@@ -723,8 +724,9 @@ class WysiwygEditor {
                     tooltip: 'Insert an image',
                     onclick: function () {
                         window.ImageManager.show(function (image) {
+                            const imageUrl = image.thumbs.display || image.url;
                             let html = `<a href="${image.url}" target="_blank">`;
-                            html += `<img src="${image.thumbs.display}" alt="${image.name}">`;
+                            html += `<img src="${imageUrl}" alt="${image.name}">`;
                             html += '</a>';
                             editor.execCommand('mceInsertContent', false, html);
                         }, 'gallery');
index 6d62552266945fc7d27579cab7044a835289907f..81041fcac04e4fecd79861301f43ccaca92da2f5 100644 (file)
@@ -8,7 +8,7 @@
 
         <div class="image-manager-viewer">
             <a href="{{ $image->url }}" target="_blank" rel="noopener" class="block">
-                <img src="{{ $image->thumbs['display'] }}"
+                <img src="{{ $image->thumbs['display'] ?? $image->url }}"
                      alt="{{ $image->name }}"
                      class="anim fadeIn"
                      title="{{ $image->name }}">