Permalink
Browse files

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

Closes gh-1968
  • Loading branch information...
markelog committed Jan 13, 2015
1 parent 85ffc6d commit 74ae5444832b2fb966768a97281d2ad8c088bc58
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/offset.js
View
@@ -143,12 +143,21 @@ 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 || documentElement;
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;
}

0 comments on commit 74ae544

Please sign in to comment.