Add clearQueue for clearing non-fx queues

This commit is contained in:
Yehuda Katz 2009-07-12 15:14:01 +00:00
parent 89b4bc53ca
commit d857315967
2 changed files with 101 additions and 2 deletions

View File

@ -93,7 +93,7 @@ jQuery.extend({
if( fn !== undefined ) if( fn !== undefined )
fn.call(elem, function() { jQuery(elem).dequeue(type); }); fn.call(elem, function() { jQuery(elem).dequeue(type); });
} },
}); });
jQuery.fn.extend({ jQuery.fn.extend({
@ -141,5 +141,8 @@ jQuery.fn.extend({
return this.each(function(){ return this.each(function(){
jQuery.dequeue( this, type ); jQuery.dequeue( this, type );
}); });
},
clearQueue: function(type){
return this.queue( type, [] );
} }
}); });

View File

@ -159,7 +159,7 @@ test("queue() with other types",function() {
$div.removeData(); $div.removeData();
}); });
test("queue() 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() {
expect(2); expect(2);
var div = jQuery({}); var div = jQuery({});
@ -178,4 +178,100 @@ test("queue() passes in the next item in the queue as a parameter", function() {
div.dequeue("foo"); div.dequeue("foo");
div.removeData(); div.removeData();
});
expect(1);
var div = jQuery({});
var counter = 0;
div.queue("foo", function(next) {
counter++;
jQuery(this).clearQueue("foo");
next();
}).queue("foo", function(next) {
counter++;
});
div.dequeue("foo");
equals(counter, 1, "the queue was cleared");
test("queue(name) passes in the next item in the queue as a parameter", function() {
expect(2);
var div = jQuery({});
var counter = 0;
div.queue("foo", function(next) {
equals(++counter, 1, "Dequeueing");
next();
}).queue("foo", function(next) {
equals(++counter, 2, "Next was called");
next();
}).queue("bar", function() {
equals(++counter, 3, "Other queues are not triggered by next()")
});
div.dequeue("foo");
div.removeData();
});
test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
expect(2);
var div = jQuery({});
var counter = 0;
div.queue(function(next) {
equals(++counter, 1, "Dequeueing");
next();
}).queue(function(next) {
equals(++counter, 2, "Next was called");
next();
}).queue(function() {
equals(++counter, 3, "Other queues are not triggered by next()")
});
div.dequeue();
div.removeData();
});
test("clearQueue(name) clears the queue", function() {
expect(1);
var div = jQuery({});
var counter = 0;
div.queue("foo", function(next) {
counter++;
jQuery(this).clearQueue("foo");
next();
}).queue("foo", function(next) {
counter++;
});
div.dequeue("foo");
equals(counter, 1, "the queue was cleared");
});
test("clearQueue() clears the fx queue", function() {
expect(1);
var div = jQuery({});
var counter = 0;
div.queue(function(next) {
counter++;
jQuery(this).clearQueue();
next();
}).queue(function(next) {
counter++;
});
div.dequeue();
equals(counter, 1, "the queue was cleared");
}) })