From: Alexander Ebert Date: Mon, 2 Feb 2015 18:54:16 +0000 (+0100) Subject: Improved quote selection for messages containing quotes X-Git-Tag: 2.1.0_Beta_4~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d62f35623f632139b16dda6aed8fec2405b517bd;p=GitHub%2FWoltLab%2FWCF.git Improved quote selection for messages containing quotes Quotes are no longer considered to be valid and are removed from the selection and virtual message body. In addition quotes cannot be created if the mousedown or mouseup occured within a quote, simply checking with indexOf() does not work if the same exact phrase appears outside the quote but within the message body. Quoting quotes isn't great because the system looks at it on a text level where it cannot understand that the quoted text belongs to a completely different message, causing confusion because the to be created quote will reference the message author. --- diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index fc93ab9163..bbd843b695 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -1963,6 +1963,19 @@ WCF.Message.Quote.Handler = Class.extend({ return; } + else { + // check if mousedown occured inside a
+ var $element = event.target; + while ($element !== $container[0]) { + if ($element.tagName === 'BLOCKQUOTE') { + this._activeContainerID = ''; + + return; + } + + $element = $element.parentElement; + } + } this._activeContainerID = $container.wcfIdentify(); @@ -1985,11 +1998,17 @@ WCF.Message.Quote.Handler = Class.extend({ _getNodeText: function(node) { // work-around for IE, see http://stackoverflow.com/a/5983176 var $nodeFilter = function(node) { - if (node.tagName === 'H3' || node.tagName === 'SCRIPT') { - return NodeFilter.FILTER_REJECT; + switch (node.tagName) { + case 'BLOCKQUOTE': + case 'H3': + case 'SCRIPT': + return NodeFilter.FILTER_REJECT; + break; + + default: + return NodeFilter.FILTER_ACCEPT; + break; } - - return NodeFilter.FILTER_ACCEPT; }; $nodeFilter.acceptNode = $nodeFilter; @@ -2050,15 +2069,23 @@ WCF.Message.Quote.Handler = Class.extend({ return; } - // compare selection with message text of given container - var $messageText = null; - if (this._messageBodySelector) { - $messageText = this._getNodeText($container.find(this._messageContentSelector)[0]); - } - else { - $messageText = this._getNodeText($container[0]); + var $messageBody = (this._messageBodySelector) ? $container.find(this._messageContentSelector)[0] : $container[0]; + + // check if mouseup occured within a
+ var $element = event.target; + while ($element !== $container[0]) { + if ($element.tagName === 'BLOCKQUOTE') { + this._copyQuote.hide(); + + return; + } + + $element = $element.parentElement; } + // compare selection with message text of given container + var $messageText = this._getNodeText($messageBody); + // selected text is not part of $messageText or contains text from unrelated nodes if (this._normalize($messageText).indexOf(this._normalize($text)) === -1) { return;