From 6df399073c6027608dff84bbd3b71e62df6c1c9b Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Tue, 16 Jun 2015 12:08:57 -0400 Subject: [PATCH] Offset: revert to jQuery.contains for IE8's sake (compat only) - getClientRects() throws on disconnected elements in IE8 only --- src/offset.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/offset.js b/src/offset.js index bad91e779..142c91893 100644 --- a/src/offset.js +++ b/src/offset.js @@ -88,17 +88,22 @@ 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 }; } @@ -106,9 +111,7 @@ jQuery.fn.extend({ // 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; }, -- 2.39.5