aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-08-25 12:23:37 -0700
committerDave Methvin <dave.methvin@gmail.com>2011-08-25 12:23:37 -0700
commit3ba72f991dccbae6020c23d6f7a65435f4ca6f03 (patch)
treeed96e4978ae66ec2456c0f18092b807a8d3f3148 /src
parenta839af034db2bd934e4d4fa6758a3fed8de74174 (diff)
parent5d954c1b2395b0f7f9132dd76a6dd5048066db04 (diff)
downloadjquery-3ba72f991dccbae6020c23d6f7a65435f4ca6f03.tar.gz
jquery-3ba72f991dccbae6020c23d6f7a65435f4ca6f03.zip
Merge pull request #464 from dmethvin/fix-10021-relative-negative-values
Fixes #10021. Allow negative relative values for `.css()`
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..a4ca555ef 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] + 1) * +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 ( value == null || type === "number" && isNaN( value ) ) {
+ return;
+ }
+
// If a number was passed in, add 'px' to the (except for certain CSS properties)
if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
value += "px";