From 96447575c23f7b313091750ed84cec05db3a25c6 Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Tue, 13 Jan 2015 08:16:32 +0300 Subject: [PATCH] Offset: simplify jQuery#offsetParent method * It seems, check for html element (and previously for body element) was redundant * Simplify "return" statement * Add comment about potential errors that didn't find themselves in real life app Ref 74ae5444832b2fb966768a97281d2ad8c088bc58 --- src/offset.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/offset.js b/src/offset.js index 37d7c34cf..c6ced41be 100644 --- a/src/offset.js +++ b/src/offset.js @@ -149,14 +149,24 @@ jQuery.fn.extend({ }; }, + // This method will return documentElement in the following cases: + // 1) For the element inside the iframe without offsetParent, this method will return + // documentElement of the parent window + // 2) For the hidden or detached element + // 3) For body or html element, i.e. in case of the html node - it will return itself + // + // but those exceptions were never presented as a real life use-cases + // and might be considered as more preferable results. + // + // This logic, however, is not guaranteed and can change at any point in the future offsetParent: function() { return this.map(function() { - var offsetParent = this.offsetParent || docElem; + var offsetParent = this.offsetParent; - while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && - jQuery.css( offsetParent, "position" ) === "static" ) ) { + while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) { offsetParent = offsetParent.offsetParent; } + return offsetParent || docElem; }); } -- 2.39.5