aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-08-16 18:00:44 -0400
committerDave Methvin <dave.methvin@gmail.com>2011-08-16 18:00:44 -0400
commit015328787cd2e52efbc77d1254ebcac13cc4ac53 (patch)
tree3901aec082b1d14f0a1f586566ec417f06543b9a /src
parentb22c9046529852c7ce567df13397849e11e2b9cc (diff)
downloadjquery-015328787cd2e52efbc77d1254ebcac13cc4ac53.tar.gz
jquery-015328787cd2e52efbc77d1254ebcac13cc4ac53.zip
Fixes #10021. Allow negative relative values for `.css()` (e.g., `"+=-20px"`) since `.animate()` already allows it. Useful for when the relative value is a variable.
Diffstat (limited to 'src')
-rw-r--r--src/css.js17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/css.js b/src/css.js
index efd881653..da0dd20c8 100644
--- a/src/css.js
+++ b/src/css.js
@@ -6,8 +6,7 @@ var ralpha = /alpha\([^)]*\)/i,
rupper = /([A-Z]|^ms)/g,
rnumpx = /^-?\d+(?:px)?$/i,
rnum = /^-?\d/,
- rrelNum = /^[+\-]=/,
- rrelNumFilter = /[^+\-\.\de]+/g,
+ rrelNum = /^([+\-])=([+\-\.\de]+)/,
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
cssWidth = [ "Left", "Right" ],
@@ -84,18 +83,18 @@ jQuery.extend({
if ( value !== undefined ) {
type = typeof value;
- // Make sure that NaN and null values aren't set. See: #7116
- if ( type === "number" && isNaN( value ) || value == null ) {
- return;
- }
-
// 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 ( type === "string" && (ret = rrelNum.exec( value )) ) {
+ value = (ret[1] === "+"? +ret[2] : -ret[2]) + parseFloat( jQuery.css( elem, name ) );
// Fixes bug #9237
type = "number";
}
+ // Make sure that NaN and null values aren't set. See: #7116
+ if ( type === "number" && isNaN( value ) || value == null ) {
+ return;
+ }
+
// If a number was passed in, add 'px' to the (except for certain CSS properties)
if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
value += "px";