Fixed setting caret after block element
authorAlexander Ebert <ebert@woltlab.com>
Fri, 19 Aug 2016 15:41:58 +0000 (17:41 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 19 Aug 2016 15:42:05 +0000 (17:42 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/acp/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js [new file with mode: 0644]

index 00ed92391cfd967b81b5968b41285faa34ad5cbc..42db80b1c8a121fdc6794bb5a26bbaea8e1edc65 100644 (file)
@@ -13,6 +13,7 @@
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabAutosave.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabBlock.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabButton.js?v={@LAST_UPDATE_TIME}',
+                       '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabCaret.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabCode.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabColor.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabDropdown.js?v={@LAST_UPDATE_TIME}',
                                        'WoltLabAlignment',
                                        'WoltLabAttachment',
                                        'WoltLabAutosave',
+                                       'WoltLabCaret',
                                        'WoltLabCode',
                                        'WoltLabColor',
                                        'WoltLabDropdown',
index 00ed92391cfd967b81b5968b41285faa34ad5cbc..42db80b1c8a121fdc6794bb5a26bbaea8e1edc65 100644 (file)
@@ -13,6 +13,7 @@
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabAutosave.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabBlock.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabButton.js?v={@LAST_UPDATE_TIME}',
+                       '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabCaret.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabCode.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabColor.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabDropdown.js?v={@LAST_UPDATE_TIME}',
                                        'WoltLabAlignment',
                                        'WoltLabAttachment',
                                        'WoltLabAutosave',
+                                       'WoltLabCaret',
                                        'WoltLabCode',
                                        'WoltLabColor',
                                        'WoltLabDropdown',
diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js
new file mode 100644 (file)
index 0000000..6c96331
--- /dev/null
@@ -0,0 +1,30 @@
+$.Redactor.prototype.WoltLabCaret = function() {
+       "use strict";
+       
+       return {
+               init: function () {
+                       var mpAfter = this.caret.after;
+                       this.caret.after = (function (node) {
+                               node = this.caret.prepare(node);
+                               
+                               if (this.utils.isBlockTag(node.tagName)) {
+                                       this.WoltLabCaret._addParagraphAfterBlock(node);
+                               }
+                               
+                               mpAfter.call(this, node);
+                       }).bind(this);
+               },
+               
+               _addParagraphAfterBlock: function (block) {
+                       var nextElement = block.nextElementSibling;
+                       if (nextElement && (nextElement.nodeName === 'P' || this.utils.isBlockTag(nextElement.nodeName))) {
+                               // valid target
+                               return;
+                       }
+                       
+                       nextElement = elCreate('p');
+                       nextElement.textContent = '\u200B';
+                       block.parentNode.insertBefore(nextElement, block.nextSibling);
+               }
+       };
+};