]> source.dussan.org Git - jquery.git/commitdiff
CSS: Protect against getBoundingClientRect exceptions
authorRichard Gibson <richard.gibson@gmail.com>
Tue, 20 Oct 2015 22:20:25 +0000 (18:20 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Tue, 20 Oct 2015 22:20:25 +0000 (18:20 -0400)
Ref 487d5ca913c237aafe9efa1179749b46382fddbf
Ref 6df399073c6027608dff84bbd3b71e62df6c1c9b

src/css.js

index 2a82b38450e88e9726532f64ea6ca5122d632bcc..0c966c6f407499a68f6428e1f6a19f9b7b8b546c 100644 (file)
@@ -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";
                }
        }
 );