From c40b12a6bd30649066babc6f8c16b53a14b110dd Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 20 Oct 2015 18:20:25 -0400 Subject: [PATCH] CSS: Protect against getBoundingClientRect exceptions Ref 487d5ca913c237aafe9efa1179749b46382fddbf Ref 6df399073c6027608dff84bbd3b71e62df6c1c9b --- src/css.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/css.js b/src/css.js index 2a82b3845..0c966c6f4 100644 --- a/src/css.js +++ b/src/css.js @@ -437,12 +437,21 @@ jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight, jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft, function( elem, computed ) { if ( computed ) { - return ( parseFloat( curCSS( elem, "marginLeft" ) ) || - elem.getBoundingClientRect().left - - swap( elem, { marginLeft: 0 }, function() { - return elem.getBoundingClientRect().left; - } ) - ) + "px"; + return ( + parseFloat( curCSS( elem, "marginLeft" ) ) || + + // Support: IE<=11+ + // Running getBoundingClientRect on a disconnected node in IE throws an error + // Support: IE8 only + // getClientRects() errors on disconnected elems + ( jQuery.contains( elem.ownerDocument, elem ) ? + elem.getBoundingClientRect().left - + swap( elem, { marginLeft: 0 }, function() { + return elem.getBoundingClientRect().left; + } ) : + 0 + ) + ) + "px"; } } ); -- 2.39.5