Move the caret after the link when inserting images
authorAlexander Ebert <ebert@woltlab.com>
Sun, 20 May 2018 08:37:39 +0000 (10:37 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 20 May 2018 08:37:39 +0000 (10:37 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabImage.js

index 1c21365ea94cd706b9d97188848da43649619906..2e3ea8f78eb9779a5788d9e6727cacaf64342f8b 100644 (file)
@@ -157,8 +157,10 @@ $.Redactor.prototype.WoltLabImage = function() {
                        }
                        
                        var html = '<img src="' + WCF.String.escapeHTML(source) + '"' + (className ? ' class="' + className + '"' : '') + '>';
+                       var linkUuid;
                        if (link) {
-                               html = '<a href="' + WCF.String.escapeHTML(link) + '">' + html + '</a>';
+                               linkUuid = WCF.getUUID();
+                               html = '<a href="' + WCF.String.escapeHTML(link) + '" data-uuid="' + linkUuid + '">' + html + '</a>';
                        }
                        
                        this.modal.close();
@@ -166,6 +168,16 @@ $.Redactor.prototype.WoltLabImage = function() {
                        this.buffer.set();
                        
                        this.insert.html(html);
+                       
+                       if (linkUuid) {
+                               window.setTimeout((function() {
+                                       var link = elBySel('a[data-uuid="' + linkUuid + '"]', this.core.editor()[0]);
+                                       if (link) {
+                                               link.removeAttribute('data-uuid');
+                                               this.caret.after(link);
+                                       }
+                               }).bind(this), 1);
+                       }
                }
        };
-};
\ No newline at end of file
+};