Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix for #4216. css now ignores negative numbers for width and height …

…when passed an object of props and vals.
  • Loading branch information...
commit 6a049246a123d7da75430f875e9eee1ba3270722 1 parent 8be5792
Brandon Aaron authored April 22, 2009
8  src/css.js
@@ -8,10 +8,6 @@ var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
8 8
 jQuery.fn.css = function( name, value ) {
9 9
 	var options = name, isFunction = jQuery.isFunction( value );
10 10
 
11  
-	// ignore negative width and height values
12  
-	if ( (name == 'width' || name == 'height') && parseFloat(value) < 0 )
13  
-		value = undefined;
14  
-
15 11
 	if ( typeof name === "string" ) {
16 12
 		// Are we setting the style?
17 13
 		if ( value === undefined ) {
@@ -55,6 +51,10 @@ jQuery.extend({
55 51
 		if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
56 52
 			return undefined;
57 53
 
  54
+		// ignore negative width and height values #1599
  55
+		if ( (name == 'width' || name == 'height') && parseFloat(value) < 0 )
  56
+			value = undefined;
  57
+
58 58
 		var style = elem.style || elem, set = value !== undefined;
59 59
 
60 60
 		// IE uses filters for opacity
8  test/unit/css.js
... ...
@@ -1,7 +1,7 @@
1 1
 module("css");
2 2
 
3 3
 test("css(String|Hash)", function() {
4  
-	expect(19);
  4
+	expect(21);
5 5
 
6 6
 	equals( jQuery('#main').css("display"), 'none', 'Check for css property "display"');
7 7
 
@@ -11,6 +11,12 @@ test("css(String|Hash)", function() {
11 11
 	jQuery('#nothiddendiv').css({display: 'block'});
12 12
 	ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
13 13
 
  14
+	// handle negative numbers by ignoring #1599, #4216
  15
+	var width = parseFloat(jQuery('#nothiddendiv').css('width')), height = parseFloat(jQuery('#nothiddendiv').css('height'));
  16
+	jQuery('#nothiddendiv').css({ width: -1, height: -1 });
  17
+	equals( parseFloat(jQuery('#nothiddendiv').css('width')), width, 'Test negative width ignored')
  18
+	equals( parseFloat(jQuery('#nothiddendiv').css('height')), height, 'Test negative height ignored')
  19
+
14 20
 	jQuery('#floatTest').css({styleFloat: 'right'});
15 21
 	equals( jQuery('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
16 22
 	jQuery('#floatTest').css({cssFloat: 'left'});

0 notes on commit 6a04924

Please sign in to comment.
Something went wrong with that request. Please try again.