From: Alexander Ebert Date: Sun, 30 Mar 2014 14:53:54 +0000 (+0200) Subject: Cleaned up code, resolved an issue with 0x200B X-Git-Tag: 2.1.0_Alpha_1~934 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=81c61b3d403e36ee03ecb1612178064fdee35616;p=GitHub%2FWoltLab%2FWCF.git Cleaned up code, resolved an issue with 0x200B --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 31cd080b63..9f639705a9 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -119,25 +119,6 @@ RedactorPlugins.wbbcode = { } }, - /** - * Removes the unicode zero width space (0x200B). - * - * @param string string - * @return string - */ - _removeCrap: function(string) { - var $string = ''; - - for (var $i = 0, $length = string.length; $i < $length; $i++) { - var $byte = string.charCodeAt($i).toString(16); - if ($byte != '200b') { - $string += string[$i]; - } - } - - return $string; - }, - _convertParagraphs: function() { this.$editor.find('p').replaceWith(function() { var $html = $(this).html(); @@ -301,7 +282,7 @@ RedactorPlugins.wbbcode = { var data = this.$source.val(); // remove 0x200B (unicode zero width space) - data = this._removeCrap(data); + data = this.removeZeroWidthSpace(data); //if (!$pasted) { // Convert & to its HTML entity. diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 1c6f9374d5..67e166d1d9 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -233,5 +233,46 @@ RedactorPlugins.wmonkeypatch = { marginLeft: -1 * Math.round($dimensions.width / 2) + 'px', marginTop: -1 * Math.round($dimensions.height / 2) + 'px' }); - } + }, + + /** + * Overwrites $.Redactor.inlineEachNodes(), the original method compares "selectionHtml" + * and "parentHtml" to check if the callback should be invoked. In some cases the "parentHtml" + * may contain a trailing unicode zero-width space and the comparision will fail, even though + * the "entire" node is selected. + * + * @see $.Redactor.inlineEachNodes() + */ + inlineEachNodes: function(callback) + { + var range = this.getRange(), + node = this.getElement(), + nodes = this.getNodes(), + collapsed; + + if (range.collapsed || range.startContainer === range.endContainer && node) + { + nodes = $(node); + collapsed = true; + } + + $.each(nodes, $.proxy(function(i, node) + { + if (!collapsed && node.tagName !== 'INLINE') + { + var selectionHtml = this.getSelectionText(); + var parentHtml = $(node).parent().text(); + // if parentHtml contains a trailing 0x200B, the comparison will most likely fail + var selected = this.removeZeroWidthSpace(selectionHtml) == this.removeZeroWidthSpace(parentHtml); + + if (selected && node.parentNode.tagName === 'INLINE' && !$(node.parentNode).hasClass('redactor_editor')) + { + node = node.parentNode; + } + else return; + } + callback.call(this, node); + + }, this ) ); + }, } \ No newline at end of file diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 0d52ee0cf6..fc5075c65e 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -282,5 +282,24 @@ RedactorPlugins.wutil = { $target.parent().remove(); return $button; - } + }, + + /** + * Removes the unicode zero-width space (0x200B). + * + * @param string string + * @return string + */ + removeZeroWidthSpace: function(string) { + var $string = ''; + + for (var $i = 0, $length = string.length; $i < $length; $i++) { + var $byte = string.charCodeAt($i).toString(16); + if ($byte != '200b') { + $string += string[$i]; + } + } + + return $string; + }, };