]> source.dussan.org Git - jquery.git/commitdiff
Ensure each tick gets it's own fxNow - Fixes #12837 - Thanks @chadparry
authorCorey Frang <gnarf@gnarf.net>
Thu, 8 Nov 2012 01:22:14 +0000 (19:22 -0600)
committerCorey Frang <gnarf@gnarf.net>
Thu, 8 Nov 2012 01:22:59 +0000 (19:22 -0600)
Closes gh-1022
Closes gh-1021
(cherry picked from commit 781a5c0b78a029b079aae970200d3e4edf543349)

src/effects.js
test/unit/effects.js

index 3118da40707543d2cb4c4adb8795dc7b3ba6d6cc..874935085ac14a2a3c78968177db8b17d56816f6 100644 (file)
@@ -614,6 +614,8 @@ jQuery.fx.tick = function() {
                timers = jQuery.timers,
                i = 0;
 
+       fxNow = jQuery.now();
+
        for ( ; i < timers.length; i++ ) {
                timer = timers[ i ];
                // Checks the timer has not already been removed
@@ -625,6 +627,7 @@ jQuery.fx.tick = function() {
        if ( !timers.length ) {
                jQuery.fx.stop();
        }
+       fxNow = undefined;
 };
 
 jQuery.fx.timer = function( timer ) {
index a11af646abcc42ba3d41555768dc512b288306b1..06a598e03dc1daac87f061afe80cde7ac0a831d2 100644 (file)
@@ -1811,6 +1811,35 @@ test( "Animate properly sets overflow hidden when animating width/height (#12117
        });
 });
 
+test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
+       var lastVal, current,
+               tmp = jQuery({
+                       test: 0
+               });
+       expect( 3 );
+       tmp.animate({
+               test: 100
+       }, {
+               step: function( p, fx ) {
+                       ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
+                       lastVal = fx.now;
+               }
+       });
+       current = jQuery.now();
+       // intentionally empty, we want to spin wheels until the time changes.
+       while ( current === jQuery.now() ) { }
+
+       // now that we have a new time, run another tick
+       jQuery.fx.tick();
+
+       current = jQuery.now();
+       // intentionally empty, we want to spin wheels until the time changes.
+       while ( current === jQuery.now() ) { }
+
+       jQuery.fx.tick();
+       tmp.stop();
+});
+
 test( "Animations with 0 duration don't ease (#12273)", 1, function() {
        jQuery.easing.test = function() {
                ok( false, "Called easing" );