]> source.dussan.org Git - jquery.git/commitdiff
Fix #7157. Animation callbacks shouldn't see an element as :animated.
authorCorey Frang <gnarf@gnarf.net>
Fri, 18 May 2012 17:48:24 +0000 (13:48 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Fri, 18 May 2012 17:48:24 +0000 (13:48 -0400)
Unless of course, there are other animations to be done! Closes gh-775.

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

index 26530a2f8c474d8fefb01aef7ddc8b527da7fd61..f7a317ac97f4b0a2bada42b51ed793601874ddcc 100644 (file)
@@ -49,6 +49,7 @@ function callTweeners( animation, props ) {
                        length = collection.length;
                for ( ; index < length; index++ ) {
                        if ( collection[ index ].call( animation, prop, value ) ) {
+
                                // we're done with this property
                                return;
                        }
@@ -63,14 +64,33 @@ function Animation( elem, properties, options ) {
                length = animationPrefilters.length,
                finished = jQuery.Deferred(),
                deferred = jQuery.Deferred().always(function( ended ) {
-                       // remove cirular reference
-                       delete animation.tick;
 
+                       // don't match elem in the :animated selector
+                       delete tick.elem;
                        if ( deferred.state() === "resolved" || ended ) {
+
                                // fire callbacks
                                finished.resolveWith( this );
                        }
                }),
+               tick = function() {
+                       var currentTime = fxNow || createFxNow(),
+                               remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
+                               percent = 1 - ( remaining / animation.duration || 0 ),
+                               index = 0,
+                               length = animation.tweens.length;
+
+                       for ( ; index < length ; index++ ) {
+                               animation.tweens[ index ].run( percent );
+                       }
+
+                       if ( percent < 1 && length ) {
+                               return remaining;
+                       } else {
+                               deferred.resolveWith( elem, [ currentTime ] );
+                               return false;
+                       }
+               },
                animation = deferred.promise({
                        elem: elem,
                        props: jQuery.extend( {}, properties ),
@@ -87,24 +107,6 @@ function Animation( elem, properties, options ) {
                                animation.tweens.push( tween );
                                return tween;
                        },
-                       tick: function() {
-                               var currentTime = fxNow || createFxNow(),
-                                       remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
-                                       percent = 1 - ( remaining / animation.duration || 0 ),
-                                       index = 0,
-                                       length = animation.tweens.length;
-
-                               for ( ; index < length ; index++ ) {
-                                       animation.tweens[ index ].run( percent );
-                               }
-
-                               if ( percent < 1 && length ) {
-                                       return remaining;
-                               } else {
-                                       deferred.resolveWith( elem, [ currentTime ] );
-                                       return false;
-                               }
-                       },
                        stop: function( gotoEnd ) {
                                var index = 0,
                                        // if we are going to the end, we want to run all the tweens
@@ -132,13 +134,13 @@ function Animation( elem, properties, options ) {
 
        callTweeners( animation, props );
 
-       jQuery.extend( animation.tick, {
-               anim: animation,
-               queue: animation.opts.queue,
-               elem: elem
-       });
-
-       jQuery.fx.timer( animation.tick );
+       jQuery.fx.timer(
+               jQuery.extend( tick, {
+                       anim: animation,
+                       queue: animation.opts.queue,
+                       elem: elem
+               })
+       );
        return animation;
 }
 
index 59a3d362729b7d568c4c7e8171f941c15f2cfad5..b05dfa0cfff037861ca6a7aef5e40c79e57bfed6 100644 (file)
@@ -1509,3 +1509,14 @@ asyncTest( "User supplied callback called after show when fx off (#8892)", 2, fu
                });
        });
 });
+
+asyncTest("Animation callback should not show animated element as animated (#7157)", 1, function() {
+       var foo = jQuery( "#foo" );
+
+       foo.animate({
+               opacity: 0
+       }, 100, function() {
+               ok( !foo.is(':animated'), "The element is not animated" );
+               start();
+       });
+});
\ No newline at end of file