aboutsummaryrefslogtreecommitdiffstats
path: root/src/css.js
diff options
context:
space:
mode:
authorDan Heberden <danheberden@gmail.com>2011-04-04 16:48:24 -0700
committerDan Heberden <danheberden@gmail.com>2011-04-04 16:48:24 -0700
commit44a3b5839e6db9e3735b3d2d3035c6f79b3bcbe8 (patch)
treec5e6e2e6747273822041a6e150fa03636fc51938 /src/css.js
parent123dd72e808800d670769f9bca75c6f2c866326b (diff)
downloadjquery-44a3b5839e6db9e3735b3d2d3035c6f79b3bcbe8.tar.gz
jquery-44a3b5839e6db9e3735b3d2d3035c6f79b3bcbe8.zip
Improve relative string performance in .css and some code cleanup
Diffstat (limited to 'src/css.js')
-rw-r--r--src/css.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/css.js b/src/css.js
index d23549fa4..65ec20f57 100644
--- a/src/css.js
+++ b/src/css.js
@@ -7,8 +7,8 @@ var ralpha = /alpha\([^)]*\)/i,
rupper = /([A-Z]|^ms)/g,
rnumpx = /^-?\d+(?:px)?$/i,
rnum = /^-?\d/,
- rrelNum = /=/,
- rrelString = /[^+\-\de]+/g,
+ rrelNum = /^[+\-]=/,
+ rrelNumFilter = /[^+\-\.\de]+/g,
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
cssWidth = [ "Left", "Right" ],
@@ -77,26 +77,27 @@ jQuery.extend({
}
// Make sure that we're working with the right name
- var ret, parsed, type, origName = jQuery.camelCase( name ),
+ var ret, type, origName = jQuery.camelCase( name ),
style = elem.style, hooks = jQuery.cssHooks[ origName ];
name = jQuery.cssProps[ origName ] || origName;
// Check if we're setting a value
if ( value !== undefined ) {
+ type = typeof value;
+
// Make sure that NaN and null values aren't set. See: #7116
- if ( typeof value === "number" && isNaN( value ) || value == null ) {
+ if ( type === "number" && isNaN( value ) || value == null ) {
return;
}
- // convert string to number or relative number
- if ( type === "string" ) {
- parsed = +value.replace( rrelString, '' );
- value = rrelNum.test( value ) ? parsed + jQuery.css( elem, name ) : parsed;
+ // convert relative number strings (+= or -=) to relative numbers. #7345
+ if ( type === "string" && rrelNum.test( value ) ) {
+ value = +value.replace( rrelNumFilter, '' ) + parseFloat( jQuery.css( elem, name ) );
}
// If a number was passed in, add 'px' to the (except for certain CSS properties)
- if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
+ if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
value += "px";
}