Commit 3812f943 authored by Corey Frang's avatar Corey Frang Committed by Dave Methvin

Fix #12278. Promises on non-default queue wait until a dequeue is attempted on...

Fix #12278. Promises on non-default queue wait until a dequeue is attempted on an empty queue. Close gh-893.
parent 6b9fde13
...@@ -22,6 +22,7 @@ jQuery.extend({ ...@@ -22,6 +22,7 @@ jQuery.extend({
type = type || "fx"; type = type || "fx";
var queue = jQuery.queue( elem, type ), var queue = jQuery.queue( elem, type ),
startLength = queue.length,
fn = queue.shift(), fn = queue.shift(),
hooks = jQuery._queueHooks( elem, type ), hooks = jQuery._queueHooks( elem, type ),
next = function() { next = function() {
...@@ -31,6 +32,7 @@ jQuery.extend({ ...@@ -31,6 +32,7 @@ jQuery.extend({
// If the fx queue is dequeued, always remove the progress sentinel // If the fx queue is dequeued, always remove the progress sentinel
if ( fn === "inprogress" ) { if ( fn === "inprogress" ) {
fn = queue.shift(); fn = queue.shift();
startLength--;
} }
if ( fn ) { if ( fn ) {
...@@ -45,7 +47,8 @@ jQuery.extend({ ...@@ -45,7 +47,8 @@ jQuery.extend({
delete hooks.stop; delete hooks.stop;
fn.call( elem, next, hooks ); fn.call( elem, next, hooks );
} }
if ( !queue.length && hooks ) {
if ( !startLength && hooks ) {
hooks.empty.fire(); hooks.empty.fire();
} }
}, },
...@@ -131,7 +134,8 @@ jQuery.fn.extend({ ...@@ -131,7 +134,8 @@ jQuery.fn.extend({
type = type || "fx"; type = type || "fx";
while( i-- ) { while( i-- ) {
if ( (tmp = jQuery._data( elements[ i ], type + "queueHooks" )) && tmp.empty ) { tmp = jQuery._data( elements[ i ], type + "queueHooks" );
if ( tmp && tmp.empty ) {
count++; count++;
tmp.empty.add( resolve ); tmp.empty.add( resolve );
} }
......
module( "queue", { teardown: moduleTeardown }); module( "queue", { teardown: moduleTeardown });
test( "queue() with other types", 12, function() { test( "queue() with other types", 14, function() {
var counter = 0; var counter = 0;
stop(); stop();
...@@ -45,6 +45,12 @@ test( "queue() with other types", 12, function() { ...@@ -45,6 +45,12 @@ test( "queue() with other types", 12, function() {
equal( counter, 4, "Testing previous call to dequeue" ); equal( counter, 4, "Testing previous call to dequeue" );
equal( $div.queue("foo").length, 0, "Testing queue length" ); equal( $div.queue("foo").length, 0, "Testing queue length" );
$div.dequeue("foo");
equal( counter, 4, "Testing previous call to dequeue" );
equal( $div.queue("foo").length, 0, "Testing queue length" );
}); });
test("queue(name) passes in the next item in the queue as a parameter", function() { test("queue(name) passes in the next item in the queue as a parameter", function() {
...@@ -206,8 +212,8 @@ asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is deq ...@@ -206,8 +212,8 @@ asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is deq
}).queue( "queue", function( next ) { }).queue( "queue", function( next ) {
strictEqual( test++, 2, "step two" ); strictEqual( test++, 2, "step two" );
setTimeout( function() { setTimeout( function() {
strictEqual( test++, 4, "step four" );
next(); next();
strictEqual( test++, 4, "step four" );
start(); start();
}, 10 ); }, 10 );
}).promise( "queue" ).done( function() { }).promise( "queue" ).done( function() {
...@@ -217,6 +223,27 @@ asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is deq ...@@ -217,6 +223,27 @@ asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is deq
foo.dequeue( "queue" ); foo.dequeue( "queue" );
}); });
asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function() {
var foo = jQuery( "#foo" ),
test = 1;
foo.animate({
top: 100
}, {
duration: 1,
queue: "queue",
complete: function() {
strictEqual( test++, 1, "step one" );
}
}).dequeue( "queue" );
foo.promise( "queue" ).done( function() {
strictEqual( test++, 2, "step two" );
start();
});
});
test( ".promise(obj)", function() { test( ".promise(obj)", function() {
expect(2); expect(2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment