Commit bbd933cb authored by jeresig's avatar jeresig

Added in the .delay() method for delaying the execution of queued functions and animations.

parent d42afd0f
...@@ -166,6 +166,21 @@ jQuery.fn.extend({ ...@@ -166,6 +166,21 @@ jQuery.fn.extend({
jQuery.dequeue( this, type ); jQuery.dequeue( this, type );
}); });
}, },
// Based off of the plugin by Clint Helfers, with permission.
// http://blindsignals.com/index.php/2009/07/jquery-delay/
delay: function( time, type ) {
time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
type = type || "fx";
return this.queue( type, function() {
var elem = this;
setTimeout(function() {
jQuery.dequeue( elem, type );
}, time );
});
},
clearQueue: function(type){ clearQueue: function(type){
return this.queue( type || "fx", [] ); return this.queue( type || "fx", [] );
} }
......
...@@ -257,6 +257,21 @@ test("queue() passes in the next item in the queue as a parameter to fx queues", ...@@ -257,6 +257,21 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
}); });
test("delay()", function() {
expect(2);
stop();
var foo = jQuery({}), run = 0;
foo.delay(100).queue(function(){
run = 1;
ok( true, "The function was dequeued." );
start();
});
equals( run, 0, "The delay delayed the next function from running." );
});
test("clearQueue(name) clears the queue", function() { test("clearQueue(name) clears the queue", function() {
expect(1); expect(1);
......
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