Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes #7912. Make sure .cur() only returns 0 as fallback value when i…

…t needs to ("", auto, undefined, null).

This change makes .cur() more .cssHooks friendly. .cur() now returns the unmodified value by
.css() if it isn't a number, number-alike or a value that needs a fallback to 0.
This way fx.start doesn't need to be recalculated for complex values.
  • Loading branch information...
commit 85d9343271da85fc945bf37a604873eaf247a3a7 1 parent b9f5e2b
authored jitter committed
10  src/effects.js
@@ -185,7 +185,7 @@ jQuery.fn.extend({
185 185
 
186 186
 				} else {
187 187
 					var parts = rfxnum.exec(val),
188  
-						start = e.cur() || 0;
  188
+						start = e.cur();
189 189
 
190 190
 					if ( parts ) {
191 191
 						var end = parseFloat( parts[2] ),
@@ -336,8 +336,12 @@ jQuery.fx.prototype = {
336 336
 			return this.elem[ this.prop ];
337 337
 		}
338 338
 
339  
-		var r = parseFloat( jQuery.css( this.elem, this.prop ) );
340  
-		return r || 0;
  339
+		var parsed,
  340
+			r = jQuery.css( this.elem, this.prop );
  341
+		// Empty strings, null, undefined and "auto" are converted to 0,
  342
+		// complex values such as "rotate(1rad)" are returned as is,
  343
+		// simple values such as "10px" are parsed to Float.
  344
+		return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
341 345
 	},
342 346
 
343 347
 	// Start an animation from one number to another
53  test/unit/effects.js
@@ -558,21 +558,44 @@ jQuery.checkOverflowDisplay = function(){
558 558
 	start();
559 559
 }
560 560
 
561  
-test("support negative values < -10000 (bug #7193)", function () {
562  
-	expect(1);
563  
-	stop();
564  
-
565  
-	jQuery.extend(jQuery.fx.step, {
566  
-		"marginBottom": function(fx) {
567  
-			equals( fx.cur(), -11000, "Element has margin-bottom of -11000" );
568  
-			delete jQuery.fx.step.marginBottom;
569  
-		}
570  
-	});
571  
-
572  
-	jQuery("#main").css("marginBottom", "-11000px").animate({ marginBottom: "-11001px" }, {
573  
-		duration: 1,
574  
-		complete: start
575  
-	});
  561
+test("jQuery.fx.prototype.cur()", function() {
  562
+	expect(5);
  563
+	var nothiddendiv = jQuery('#nothiddendiv').css({
  564
+			color: '#ABC',
  565
+			border: '5px solid black',
  566
+			left: 'auto',
  567
+			marginBottom: '11000px'
  568
+		})[0];
  569
+
  570
+	equals(
  571
+		(new jQuery.fx( nothiddendiv, {}, 'color' )).cur(),
  572
+		jQuery.css( nothiddendiv,'color' ),
  573
+		"Return the same value as jQuery.css for complex properties (bug #7912)"
  574
+	);
  575
+
  576
+	strictEqual(
  577
+		(new jQuery.fx( nothiddendiv, {}, 'borderLeftWidth' )).cur(),
  578
+		5,
  579
+		"Return simple values parsed as Float"
  580
+	);
  581
+
  582
+	strictEqual(
  583
+		(new jQuery.fx( nothiddendiv, {}, 'backgroundPosition' )).cur(),
  584
+		0,
  585
+		'Return 0 when jQuery.css returns an empty string'
  586
+	);
  587
+
  588
+	strictEqual(
  589
+		(new jQuery.fx( nothiddendiv, {}, 'left' )).cur(),
  590
+		0,
  591
+		'Return 0 when jQuery.css returns "auto"'
  592
+	);
  593
+
  594
+	equals(
  595
+		(new jQuery.fx( nothiddendiv, {}, 'marginBottom' )).cur(),
  596
+		11000,
  597
+		"support negative values < -10000 (bug #7193)"
  598
+	);
576 599
 });
577 600
 
578 601
 test("JS Overflow and Display", function() {

0 notes on commit 85d9343

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