From 11b099caef8b352d25106f4780238a2fa8dd013a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 27 Feb 2015 11:40:18 +0100 Subject: [PATCH] Properly check if selection is within the $messageBody element --- wcfsetup/install/files/js/WCF.Message.js | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 9c5bb032f1..5232d5f30f 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -2088,6 +2088,14 @@ WCF.Message.Quote.Handler = Class.extend({ $element = $element.parentElement; } + // check if selection starts and ends within the $messageBody element + var $range = window.getSelection().getRangeAt(0); + if (!this._elementInsideContainer($range.startContainer, $messageBody) || !this._elementInsideContainer($range.endContainer, $messageBody)) { + this._copyQuote.hide(); + + return; + } + // compare selection with message text of given container var $messageText = this._getNodeText($messageBody); @@ -2133,6 +2141,27 @@ WCF.Message.Quote.Handler = Class.extend({ }, 10); }, + /** + * Returns true if given element is a child element of given container element. + * + * @param Node element + * @param Element container + * @return boolean + */ + _elementInsideContainer: function(element, container) { + if (element.nodeType === Node.TEXT_NODE) element = element.parentElement; + + while (element) { + if (element === container) { + return true; + } + + element = element.parentElement; + } + + return false; + }, + /** * Normalizes a text for comparison. * -- 2.20.1