From: Alexander Ebert Date: Fri, 27 Feb 2015 10:40:18 +0000 (+0100) Subject: Properly check if selection is within the $messageBody element X-Git-Tag: 2.1.0~13 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=11b099caef8b352d25106f4780238a2fa8dd013a;p=GitHub%2FWoltLab%2FWCF.git Properly check if selection is within the $messageBody element --- 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. *