diff options
author | avaly <github-com@agachi.name> | 2011-05-13 12:09:49 -0400 |
---|---|---|
committer | timmywil <tim.willison@thisismedium.com> | 2011-05-13 12:09:49 -0400 |
commit | cbbd7d28e1088e76a9c89bfb30ba9af8f1fce759 (patch) | |
tree | d1da4999230ecfd6125f4ac2735a6bfeb99ecb25 | |
parent | 3486365062cdc7e8598cea238e67aafa33af7dce (diff) | |
download | jquery-cbbd7d28e1088e76a9c89bfb30ba9af8f1fce759.tar.gz jquery-cbbd7d28e1088e76a9c89bfb30ba9af8f1fce759.zip |
Landing pull request 375. Added test case to support #9237 Fixes #9237.
More Details:
- https://github.com/jquery/jquery/pull/375
- http://bugs.jquery.com/ticket/9237
-rw-r--r-- | src/css.js | 2 | ||||
-rw-r--r-- | test/unit/css.js | 54 |
2 files changed, 54 insertions, 2 deletions
diff --git a/src/css.js b/src/css.js index 318cd5979..59eaed71c 100644 --- a/src/css.js +++ b/src/css.js @@ -96,6 +96,8 @@ jQuery.extend({ // convert relative number strings (+= or -=) to relative numbers. #7345 if ( type === "string" && rrelNum.test( value ) ) { value = +value.replace( rrelNumFilter, "" ) + parseFloat( jQuery.css( elem, name ) ); + // Fixes bug #9237 + type = 'number'; } // If a number was passed in, add 'px' to the (except for certain CSS properties) diff --git a/test/unit/css.js b/test/unit/css.js index 380709d12..67271c876 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -109,11 +109,13 @@ test("css(String|Hash)", function() { }); test("css() explicit and relative values", function() { - expect(9); + expect(27); var $elem = jQuery("#nothiddendiv"); - $elem.css({ width: 1, height: 1 }); + $elem.css({ width: 1, height: 1, paddingLeft: '1px', opacity: 1 }); equals( $elem.width(), 1, "Initial css set or width/height works (hash)" ); + equals( $elem.css("paddingLeft"), '1px', "Initial css set of paddingLeft works (hash)" ); + equals( $elem.css("opacity"), '1', "Initial css set of opacity works (hash)" ); $elem.css({ width: "+=9" }); equals( $elem.width(), 10, "'+=9' on width (hash)" ); @@ -138,6 +140,54 @@ test("css() explicit and relative values", function() { $elem.css( "width", "-=9px" ); equals( $elem.width(), 1, "'-=9px' on width (params)" ); + + $elem.css({ paddingLeft: "+=4" }); + equals( $elem.css("paddingLeft"), '5px', "'+=4' on paddingLeft (hash)" ); + + $elem.css({ paddingLeft: "-=4" }); + equals( $elem.css("paddingLeft"), '1px', "'-=4' on paddingLeft (hash)" ); + + $elem.css({ paddingLeft: "+=4px" }); + equals( $elem.css("paddingLeft"), '5px', "'+=4px' on paddingLeft (hash)" ); + + $elem.css({ paddingLeft: "-=4px" }); + equals( $elem.css("paddingLeft"), '1px', "'-=4px' on paddingLeft (hash)" ); + + $elem.css({ "padding-left": "+=4" }); + equals( $elem.css("paddingLeft"), '5px', "'+=4' on padding-left (hash)" ); + + $elem.css({ "padding-left": "-=4" }); + equals( $elem.css("paddingLeft"), '1px', "'-=4' on padding-left (hash)" ); + + $elem.css({ "padding-left": "+=4px" }); + equals( $elem.css("paddingLeft"), '5px', "'+=4px' on padding-left (hash)" ); + + $elem.css({ "padding-left": "-=4px" }); + equals( $elem.css("paddingLeft"), '1px', "'-=4px' on padding-left (hash)" ); + + $elem.css( "paddingLeft", "+=4" ); + equals( $elem.css("paddingLeft"), '5px', "'+=4' on paddingLeft (params)" ); + + $elem.css( "paddingLeft", "-=4" ); + equals( $elem.css("paddingLeft"), '1px', "'-=4' on paddingLeft (params)" ); + + $elem.css( "padding-left", "+=4px" ); + equals( $elem.css("paddingLeft"), '5px', "'+=4px' on padding-left (params)" ); + + $elem.css( "padding-left", "-=4px" ); + equals( $elem.css("paddingLeft"), '1px', "'-=4px' on padding-left (params)" ); + + $elem.css({ opacity: "-=0.5" }); + equals( $elem.css("opacity"), '0.5', "'-=0.5' on opacity (hash)" ); + + $elem.css({ opacity: "+=0.5" }); + equals( $elem.css("opacity"), '1', "'+=0.5' on opacity (hash)" ); + + $elem.css( "opacity", "-=0.5" ); + equals( $elem.css("opacity"), '0.5', "'-=0.5' on opacity (params)" ); + + $elem.css( "opacity", "+=0.5" ); + equals( $elem.css("opacity"), '1', "'+=0.5' on opacity (params)" ); }); test("css(String, Object)", function() { |