From ae9e05e9f3cb071232b056005755acb5926e403e Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Sat, 25 May 2013 10:18:57 -0400 Subject: [PATCH] Fix #13937: Correctly scope .finish() following multi-element .animate(). Thanks @gnarf37. Close gh-1279. --- src/effects.js | 8 +++----- src/queue.js | 1 - test/unit/effects.js | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/effects.js b/src/effects.js index b03036ce3..f939ae607 100644 --- a/src/effects.js +++ b/src/effects.js @@ -490,9 +490,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 || jQuery._data( this, "finish" ) ) { anim.stop( true ); @@ -572,8 +570,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 diff --git a/src/queue.js b/src/queue.js index d4c3f0040..c5a0cbd7d 100644 --- a/src/queue.js +++ b/src/queue.js @@ -35,7 +35,6 @@ jQuery.extend({ startLength--; } - hooks.cur = fn; if ( fn ) { // Add a progress sentinel to prevent the fx queue from being diff --git a/test/unit/effects.js b/test/unit/effects.js index fc40e49d2..e50fc2185 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -2134,21 +2134,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( "
" ); + var div = jQuery( "
" ), + 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("012"); + + 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( "
    " ), origHeight = ul.height(); -- 2.39.5