Improved quote selection for messages containing quotes
authorAlexander Ebert <ebert@woltlab.com>
Mon, 2 Feb 2015 18:54:16 +0000 (19:54 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 2 Feb 2015 18:54:16 +0000 (19:54 +0100)
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.

wcfsetup/install/files/js/WCF.Message.js

index fc93ab916308471acf0fa9375fd7ee753e9c1e66..bbd843b695894cdc1d94eced55507ec1b51d7cda 100644 (file)
@@ -1963,6 +1963,19 @@ WCF.Message.Quote.Handler = Class.extend({
                        
                        return;
                }
+               else {
+                       // check if mousedown occured inside a <blockquote>
+                       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 <blockquote>
+               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;