]> source.dussan.org Git - jquery.git/commitdiff
Fix #13937: Correctly scope .finish() following multi-element .animate(). Thanks...
authorRichard Gibson <richard.gibson@gmail.com>
Sat, 25 May 2013 14:18:57 +0000 (10:18 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Tue, 28 May 2013 20:49:48 +0000 (16:49 -0400)
(cherry picked from commit ae9e05e9f3cb071232b056005755acb5926e403e)

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

index cb78b5cfe577a2c4b695b50b7c6e5e2bf29e0f57..b0a9083e70bf084fe59120d46f631f2b3c49963d 100644 (file)
@@ -488,9 +488,7 @@ jQuery.fn.extend({
                        doAnimation = function() {
                                // Operate on a copy of prop so per-property easing won't be lost
                                var anim = Animation( this, jQuery.extend( {}, prop ), optall );
-                               doAnimation.finish = function() {
-                                       anim.stop( true );
-                               };
+
                                // Empty animations, or finishing resolves immediately
                                if ( empty || data_priv.get( this, "finish" ) ) {
                                        anim.stop( true );
@@ -570,8 +568,8 @@ jQuery.fn.extend({
                        // empty the queue first
                        jQuery.queue( this, type, [] );
 
-                       if ( hooks && hooks.cur && hooks.cur.finish ) {
-                               hooks.cur.finish.call( this );
+                       if ( hooks && hooks.stop ) {
+                               hooks.stop.call( this, true );
                        }
 
                        // look for any active animations, and finish them
index 46b9ba8fcca9663fd9b7c0564522af18825f1628..1297bc1b4e9a9ec70811a2d4ec9ba6369b1a9581 100644 (file)
@@ -35,7 +35,6 @@ jQuery.extend({
                        startLength--;
                }
 
-               hooks.cur = fn;
                if ( fn ) {
 
                        // Add a progress sentinel to prevent the fx queue from being
index 05f1c017a379e60924a7c2d0b1fc01f6e6f5bc91..4c4e31495d13e577c647f1c6d41a48b1d1c096be 100644 (file)
@@ -2096,21 +2096,47 @@ test( ".finish( \"custom\" ) - custom queue animations", function() {
 });
 
 test( ".finish() calls finish of custom queue functions", function() {
-       function queueTester() {
-
+       function queueTester( next, hooks ) {
+               hooks.stop = function( gotoEnd ) {
+                       inside++;
+                       equal( this, div[0] );
+                       ok( gotoEnd, "hooks.stop(true) called");
+               };
        }
-       var div = jQuery( "<div>" );
+       var div = jQuery( "<div>" ),
+               inside = 0,
+               outside = 0;
 
-       expect( 3 );
+       expect( 6 );
        queueTester.finish = function() {
+               outside++;
                ok( true, "Finish called on custom queue function" );
        };
 
        div.queue( queueTester ).queue( queueTester ).queue( queueTester ).finish();
 
+       equal( inside, 1, "1 stop(true) callback" );
+       equal( outside, 2, "2 finish callbacks" );
+
        div.remove();
 });
 
+asyncTest( ".finish() is applied correctly when multiple elements were animated (#13937)", function() {
+       expect( 3 );
+
+       var elems = jQuery("<a>0</a><a>1</a><a>2</a>");
+
+       elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
+       setTimeout(function() {
+               elems.eq( 1 ).finish();
+               ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
+               ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" );
+               ok( elems.eq( 2 ).queue().length, "non-empty queue for following element" );
+               elems.stop( true );
+               start();
+       }, 100 );
+});
+
 asyncTest( "slideDown() after stop() (#13483)", 2, function() {
        var ul = jQuery( "<ul style='height: 100px;display: block'></ul>" ),
                origHeight = ul.height();