From: Alexander Ebert Date: Fri, 19 Aug 2016 15:41:58 +0000 (+0200) Subject: Fixed setting caret after block element X-Git-Tag: 3.0.0_Beta_1~652 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5a7a1cd8b8e64dd5e815f0d76d5053fc0eb2f642;p=GitHub%2FWoltLab%2FWCF.git Fixed setting caret after block element --- diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index 00ed92391c..42db80b1c8 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -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}', @@ -152,6 +153,7 @@ 'WoltLabAlignment', 'WoltLabAttachment', 'WoltLabAutosave', + 'WoltLabCaret', 'WoltLabCode', 'WoltLabColor', 'WoltLabDropdown', diff --git a/wcfsetup/install/files/acp/templates/wysiwyg.tpl b/wcfsetup/install/files/acp/templates/wysiwyg.tpl index 00ed92391c..42db80b1c8 100644 --- a/wcfsetup/install/files/acp/templates/wysiwyg.tpl +++ b/wcfsetup/install/files/acp/templates/wysiwyg.tpl @@ -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}', @@ -152,6 +153,7 @@ '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 index 0000000000..6c96331f38 --- /dev/null +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js @@ -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); + } + }; +};