diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2015-11-06 16:16:53 -0500 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2015-11-09 17:38:00 -0500 |
commit | 75b3cdd509a2cf0a704767d04557ec392112a438 (patch) | |
tree | 46f3fd4da0f29b70040003eba4cea585b10dbf12 /src | |
parent | 22449eb968622c2e14d6c8d8de2cf1e1ba4adccd (diff) | |
download | jquery-75b3cdd509a2cf0a704767d04557ec392112a438.tar.gz jquery-75b3cdd509a2cf0a704767d04557ec392112a438.zip |
Dimensions: properly manipulate non-px values
Fixes gh-1712
Close gh-2695
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 ); } }; } ); |