Permalink
Browse files

Offset: revert to jQuery.contains for IE8's sake (compat only)

- getClientRects() throws on disconnected elements in IE8 only
  • Loading branch information...
timmywil committed Jun 16, 2015
1 parent 25e8620 commit 6df399073c6027608dff84bbd3b71e62df6c1c9b
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/offset.js
View
@@ -88,27 +88,30 @@ jQuery.fn.extend({
});
}
- var docElem, win, rect, doc,
- elem = this[ 0 ];
+ var docElem, win, rect,
+ elem = this[ 0 ],
+ doc = elem && elem.ownerDocument;
- if ( !elem ) {
+ if ( !doc ) {
return;
}
+ docElem = doc.documentElement;
+
// Support: IE<=11+
// Running getBoundingClientRect on a
// disconnected node in IE throws an error
- if ( !elem.getClientRects().length ) {
+ // Support: IE8 only
+ // getClientRects() errors on disconnected elems
+ if ( !jQuery.contains( docElem, elem ) ) {
return { top: 0, left: 0 };
}
rect = elem.getBoundingClientRect();
// Make sure element is not hidden (display: none)
if ( rect.width || rect.height ) {
- doc = elem.ownerDocument;
win = getWindow( doc );
- docElem = doc.documentElement;
return {
top: rect.top + ( win.pageYOffset || docElem.scrollTop ) -
@@ -118,7 +121,7 @@ jQuery.fn.extend({
};
}
- // Return zeros for disconnected and hidden elements (gh-2310)
+ // Return zeros for hidden elements
return rect;
},

0 comments on commit 6df3990

Please sign in to comment.