aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2015-10-20 18:20:25 -0400
committerRichard Gibson <richard.gibson@gmail.com>2015-10-20 18:20:25 -0400
commitc40b12a6bd30649066babc6f8c16b53a14b110dd (patch)
tree2d6a4e734b951c1217e85fffe68ed022341ced4a
parentb94af72bc8da4802abab6a5b300fb444dfcacea9 (diff)
downloadjquery-c40b12a6bd30649066babc6f8c16b53a14b110dd.tar.gz
jquery-c40b12a6bd30649066babc6f8c16b53a14b110dd.zip
CSS: Protect against getBoundingClientRect exceptions
Ref 487d5ca913c237aafe9efa1179749b46382fddbf Ref 6df399073c6027608dff84bbd3b71e62df6c1c9b
-rw-r--r--src/css.js21
1 files 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";
}
}
);