Skip to content

Commit

Permalink
CSS: Protect against getBoundingClientRect exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Oct 20, 2015
1 parent b94af72 commit c40b12a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
);
Expand Down

0 comments on commit c40b12a

Please sign in to comment.