From: Richard Gibson Date: Tue, 20 Oct 2015 22:20:25 +0000 (-0400) Subject: CSS: Protect against getBoundingClientRect exceptions X-Git-Tag: 1.12.0~94 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c40b12a6bd30649066babc6f8c16b53a14b110dd;p=jquery.git CSS: Protect against getBoundingClientRect exceptions Ref 487d5ca913c237aafe9efa1179749b46382fddbf Ref 6df399073c6027608dff84bbd3b71e62df6c1c9b --- 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"; } } );