mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Fix #13937: Correctly scope .finish() following multi-element .animate(). Thanks @gnarf37. Close gh-1279.
(cherry picked from commit ae9e05e9f3
)
This commit is contained in:
parent
68c9d0528c
commit
6fd5e480c1
8
src/effects.js
vendored
8
src/effects.js
vendored
@ -488,9 +488,7 @@ jQuery.fn.extend({
|
|||||||
doAnimation = function() {
|
doAnimation = function() {
|
||||||
// Operate on a copy of prop so per-property easing won't be lost
|
// Operate on a copy of prop so per-property easing won't be lost
|
||||||
var anim = Animation( this, jQuery.extend( {}, prop ), optall );
|
var anim = Animation( this, jQuery.extend( {}, prop ), optall );
|
||||||
doAnimation.finish = function() {
|
|
||||||
anim.stop( true );
|
|
||||||
};
|
|
||||||
// Empty animations, or finishing resolves immediately
|
// Empty animations, or finishing resolves immediately
|
||||||
if ( empty || data_priv.get( this, "finish" ) ) {
|
if ( empty || data_priv.get( this, "finish" ) ) {
|
||||||
anim.stop( true );
|
anim.stop( true );
|
||||||
@ -570,8 +568,8 @@ jQuery.fn.extend({
|
|||||||
// empty the queue first
|
// empty the queue first
|
||||||
jQuery.queue( this, type, [] );
|
jQuery.queue( this, type, [] );
|
||||||
|
|
||||||
if ( hooks && hooks.cur && hooks.cur.finish ) {
|
if ( hooks && hooks.stop ) {
|
||||||
hooks.cur.finish.call( this );
|
hooks.stop.call( this, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for any active animations, and finish them
|
// look for any active animations, and finish them
|
||||||
|
@ -35,7 +35,6 @@ jQuery.extend({
|
|||||||
startLength--;
|
startLength--;
|
||||||
}
|
}
|
||||||
|
|
||||||
hooks.cur = fn;
|
|
||||||
if ( fn ) {
|
if ( fn ) {
|
||||||
|
|
||||||
// Add a progress sentinel to prevent the fx queue from being
|
// Add a progress sentinel to prevent the fx queue from being
|
||||||
|
34
test/unit/effects.js
vendored
34
test/unit/effects.js
vendored
@ -2096,21 +2096,47 @@ test( ".finish( \"custom\" ) - custom queue animations", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test( ".finish() calls finish of custom queue functions", 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() {
|
queueTester.finish = function() {
|
||||||
|
outside++;
|
||||||
ok( true, "Finish called on custom queue function" );
|
ok( true, "Finish called on custom queue function" );
|
||||||
};
|
};
|
||||||
|
|
||||||
div.queue( queueTester ).queue( queueTester ).queue( queueTester ).finish();
|
div.queue( queueTester ).queue( queueTester ).queue( queueTester ).finish();
|
||||||
|
|
||||||
|
equal( inside, 1, "1 stop(true) callback" );
|
||||||
|
equal( outside, 2, "2 finish callbacks" );
|
||||||
|
|
||||||
div.remove();
|
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() {
|
asyncTest( "slideDown() after stop() (#13483)", 2, function() {
|
||||||
var ul = jQuery( "<ul style='height: 100px;display: block'></ul>" ),
|
var ul = jQuery( "<ul style='height: 100px;display: block'></ul>" ),
|
||||||
origHeight = ul.height();
|
origHeight = ul.height();
|
||||||
|
Loading…
Reference in New Issue
Block a user