Skip to content

Commit 6fd5e48

Browse files
committed
Fix #13937: Correctly scope .finish() following multi-element .animate(). Thanks @gnarf37. Close jquerygh-1279.
(cherry picked from commit ae9e05e)
1 parent 68c9d05 commit 6fd5e48

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/effects.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,7 @@ jQuery.fn.extend({
488488
doAnimation = function() {
489489
// Operate on a copy of prop so per-property easing won't be lost
490490
var anim = Animation( this, jQuery.extend( {}, prop ), optall );
491-
doAnimation.finish = function() {
492-
anim.stop( true );
493-
};
491+
494492
// Empty animations, or finishing resolves immediately
495493
if ( empty || data_priv.get( this, "finish" ) ) {
496494
anim.stop( true );
@@ -570,8 +568,8 @@ jQuery.fn.extend({
570568
// empty the queue first
571569
jQuery.queue( this, type, [] );
572570

573-
if ( hooks && hooks.cur && hooks.cur.finish ) {
574-
hooks.cur.finish.call( this );
571+
if ( hooks && hooks.stop ) {
572+
hooks.stop.call( this, true );
575573
}
576574

577575
// look for any active animations, and finish them

src/queue.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jQuery.extend({
3535
startLength--;
3636
}
3737

38-
hooks.cur = fn;
3938
if ( fn ) {
4039

4140
// Add a progress sentinel to prevent the fx queue from being

test/unit/effects.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,21 +2096,47 @@ test( ".finish( \"custom\" ) - custom queue animations", function() {
20962096
});
20972097

20982098
test( ".finish() calls finish of custom queue functions", function() {
2099-
function queueTester() {
2100-
2099+
function queueTester( next, hooks ) {
2100+
hooks.stop = function( gotoEnd ) {
2101+
inside++;
2102+
equal( this, div[0] );
2103+
ok( gotoEnd, "hooks.stop(true) called");
2104+
};
21012105
}
2102-
var div = jQuery( "<div>" );
2106+
var div = jQuery( "<div>" ),
2107+
inside = 0,
2108+
outside = 0;
21032109

2104-
expect( 3 );
2110+
expect( 6 );
21052111
queueTester.finish = function() {
2112+
outside++;
21062113
ok( true, "Finish called on custom queue function" );
21072114
};
21082115

21092116
div.queue( queueTester ).queue( queueTester ).queue( queueTester ).finish();
21102117

2118+
equal( inside, 1, "1 stop(true) callback" );
2119+
equal( outside, 2, "2 finish callbacks" );
2120+
21112121
div.remove();
21122122
});
21132123

2124+
asyncTest( ".finish() is applied correctly when multiple elements were animated (#13937)", function() {
2125+
expect( 3 );
2126+
2127+
var elems = jQuery("<a>0</a><a>1</a><a>2</a>");
2128+
2129+
elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
2130+
setTimeout(function() {
2131+
elems.eq( 1 ).finish();
2132+
ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
2133+
ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" );
2134+
ok( elems.eq( 2 ).queue().length, "non-empty queue for following element" );
2135+
elems.stop( true );
2136+
start();
2137+
}, 100 );
2138+
});
2139+
21142140
asyncTest( "slideDown() after stop() (#13483)", 2, function() {
21152141
var ul = jQuery( "<ul style='height: 100px;display: block'></ul>" ),
21162142
origHeight = ul.height();

0 commit comments

Comments
 (0)