From: Alexander Ebert Date: Sun, 29 Mar 2015 14:12:35 +0000 (+0200) Subject: Fixed handling of quote/code bbcode X-Git-Tag: 2.1.3~60 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=30c64335a5446a33df4306c18940d830a2a81285;p=GitHub%2FWoltLab%2FWCF.git Fixed handling of quote/code bbcode --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index af343425d9..d56dd92d82 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -27,7 +27,7 @@ RedactorPlugins.wbbcode = function() { // use stored editor contents var $content = $.trim(this.wutil.getOption('woltlab.originalValue')); if ($content.length) { - this.wutil.replaceText($content); + this.wutil.replaceText($content, false); // ensure that the caret is not within a quote tag this.wutil.selectionEndOfEditor(); @@ -1412,6 +1412,7 @@ RedactorPlugins.wbbcode = function() { + ''; }).bind(this)); + data = data.replace(new RegExp('(?:

)?(@@' + $cachedCode.key + '@@)(?:<\/p>)?', 'g'), '$1'); data = data.replace($regex, $value); } } @@ -2213,6 +2214,7 @@ RedactorPlugins.wbbcode = function() { var $html = this.wbbcode.convertToHtml($bbcode); this.buffer.set(); + this.insert.html($html, false); // set caret after code listing @@ -2302,35 +2304,28 @@ RedactorPlugins.wbbcode = function() { }, /** - * Ensures that there is a paragraph in front of each block-level element because you cannot click in between two of them. + * Inserting block-level elements (e.g. quotes or code bbcode) can lead to void paragraphs. */ fixBlockLevelElements: function() { - return; - var $addSpacing = (function(referenceElement, target) { - var $tagName = 'P'; - - // fix reference element if a block element is within a quote (wrapped by

...
) - if (referenceElement.parentElement.tagName === 'DIV' && referenceElement.parentElement !== this.$editor[0]) { - referenceElement = referenceElement.parentElement; - $tagName = 'DIV'; - } - - // no previous/next element or it is not a

(default) or

(within quotes) - if (referenceElement[target] === null || referenceElement[target].tagName !== $tagName) { - $('<' + $tagName + '>' + this.opts.invisibleSpace + '')[(target === 'previousElementSibling' ? 'insertBefore' : 'insertAfter')](referenceElement); - } - else if (referenceElement.previousElementSibling.tagName === $tagName) { - // previous/next element is empty or contains an empty

(block element is a direct children of the editor) - if (!referenceElement[target].innerHTML.length || referenceElement[target].innerHTML.toLowerCase() === '

') { - $(referenceElement[target]).html(this.opts.invisibleSpace); + var $removeVoidElements = (function(referenceElement, position) { + var $sibling = referenceElement[position]; + if ($sibling && $sibling.nodeType === Node.ELEMENT_NODE && $sibling.tagName === 'P') { + if (!$sibling.innerHTML.length) { + $sibling.parentElement.removeChild($sibling); + } + else if ($sibling.innerHTML === '\u200b') { + var $adjacentSibling = $sibling[position]; + if ($adjacentSibling && $adjacentSibling.nodeType === Node.ELEMENT_NODE && $adjacentSibling.tagName === 'P' && $adjacentSibling.innerHTML.length) { + $sibling.parentElement.removeChild($sibling); + } } } }).bind(this); - this.$editor.find('blockquote, .codeBox').each((function(index, blockElement) { - $addSpacing(blockElement, 'previousElementSibling'); - $addSpacing(blockElement, 'nextElementSibling'); - }).bind(this)); + this.$editor.find('blockquote, .codeBox').each(function() { + $removeVoidElements(this, 'previousElementSibling'); + $removeVoidElements(this, 'nextElementSibling'); + }); }, /** diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 7a9b9dc92f..813d1407d1 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -763,9 +763,10 @@ RedactorPlugins.wutil = function() { this.wutil.selectionEndOfEditor(); } else { - var $p = $('


').insertAfter($insertAfter); + this.caret.setAfter($insertAfter); + /*var $p = $('


').insertAfter($insertAfter); - this.caret.setEnd($p); + this.caret.setEnd($p);*/ } } } @@ -883,8 +884,9 @@ RedactorPlugins.wutil = function() { * Replaces the current content with the provided value. * * @param string value + * @param boolean addNewlines */ - replaceText: function(value) { + replaceText: function(value, addNewlines) { var $document = $(document); var $offsetTop = $document.scrollTop(); var $wasInWysiwygMode = false; @@ -894,7 +896,10 @@ RedactorPlugins.wutil = function() { $wasInWysiwygMode = true; } - value = this.wutil.addNewlines(value); + if (addNewlines !== false) { + value = this.wutil.addNewlines(value); + } + this.$textarea.val(value); if ($wasInWysiwygMode) {