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

- getClientRects() throws on disconnected elements in IE8 only
This commit is contained in:
Timmy Willison 2015-06-16 12:08:57 -04:00
parent 25e8620da9
commit 6df399073c

View File

@ -88,17 +88,22 @@ jQuery.fn.extend({
}); });
} }
var docElem, win, rect, doc, var docElem, win, rect,
elem = this[ 0 ]; elem = this[ 0 ],
doc = elem && elem.ownerDocument;
if ( !elem ) { if ( !doc ) {
return; return;
} }
docElem = doc.documentElement;
// Support: IE<=11+ // Support: IE<=11+
// Running getBoundingClientRect on a // Running getBoundingClientRect on a
// disconnected node in IE throws an error // 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 }; return { top: 0, left: 0 };
} }
@ -106,9 +111,7 @@ jQuery.fn.extend({
// Make sure element is not hidden (display: none) // Make sure element is not hidden (display: none)
if ( rect.width || rect.height ) { if ( rect.width || rect.height ) {
doc = elem.ownerDocument;
win = getWindow( doc ); win = getWindow( doc );
docElem = doc.documentElement;
return { return {
top: rect.top + ( win.pageYOffset || docElem.scrollTop ) - 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; return rect;
}, },