Fixed empty paragraphs after paste
authorAlexander Ebert <ebert@woltlab.com>
Thu, 25 Aug 2016 09:52:41 +0000 (11:52 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 25 Aug 2016 09:52:41 +0000 (11:52 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js [new file with mode: 0644]

index 4abf9700cb2016367dd8dbbd96005577c7f50796..c26711b2631dd0b28b767eff69ce4c4b36933936 100644 (file)
@@ -21,6 +21,7 @@
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabEvent.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabImage.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInlineCode.js?v={@LAST_UPDATE_TIME}',
+                       '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInsert.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}',
                                        'WoltLabEvent',
                                        'WoltLabImage',
                                        'WoltLabInlineCode',
+                                       'WoltLabInsert',
                                        'WoltLabLink',
                                        'WoltLabModal',
                                        'WoltLabPaste',
diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabInsert.js
new file mode 100644 (file)
index 0000000..2a220a5
--- /dev/null
@@ -0,0 +1,24 @@
+$.Redactor.prototype.WoltLabInsert = function() {
+       "use strict";
+       
+       return {
+               init: function () {
+                       var mpHtml = this.insert.html;
+                       this.insert.html = (function (html, data) {
+                               this.placeholder.hide();
+                               this.core.editor().focus();
+                               
+                               /** @var Element */
+                               var block = this.selection.block();
+                               
+                               mpHtml.call(this, html, data);
+                               
+                               if (block && block.nodeName === 'P' && block.nextElementSibling && !block.childElementCount && block.textContent.replace(/\u200B/g, '').trim() === '') {
+                                       // inserting HTML tends to cause new paragraphs inserted
+                                       // rather than using the current, empty one
+                                       elRemove(block);
+                               }
+                       }).bind(this);
+               }
+       };
+};