diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/css.js | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/css.js b/src/css.js index 0e5a55610..acd4bb3eb 100644 --- a/src/css.js +++ b/src/css.js @@ -27,8 +27,6 @@ var // except "table", "table-cell", or "table-caption" // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display rdisplayswap = /^(none|table(?!-c[ea]).+)/, - rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ), - cssShow = { position: "absolute", visibility: "hidden", display: "block" }, cssNormalTransform = { letterSpacing: "0", @@ -59,11 +57,14 @@ function vendorPropName( name ) { } function setPositiveNumber( elem, value, subtract ) { - var matches = rnumsplit.exec( value ); + + // Any relative (+/-) values have already been + // normalized at this point + var matches = rcssNum.exec( value ); return matches ? // Guard against undefined "subtract", e.g., when used as in cssHooks - Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) : + Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) : value; } @@ -336,16 +337,25 @@ jQuery.each( [ "height", "width" ], function( i, name ) { }, set: function( elem, value, extra ) { - var styles = extra && getStyles( elem ); - return setPositiveNumber( elem, value, extra ? - augmentWidthOrHeight( + var matches, + styles = extra && getStyles( elem ), + subtract = extra && augmentWidthOrHeight( elem, name, extra, jQuery.css( elem, "boxSizing", false, styles ) === "border-box", styles - ) : 0 - ); + ); + + // Convert to pixels if value adjustment is needed + if ( subtract && ( matches = rcssNum.exec( value ) ) && + ( matches[ 3 ] || "px" ) !== "px" ) { + + elem.style[ name ] = value; + value = jQuery.css( elem, name ); + } + + return setPositiveNumber( elem, value, subtract ); } }; } ); |