]> source.dussan.org Git - jquery.git/commitdiff
Added in the .delay() method for delaying the execution of queued functions and anima...
authorjeresig <jeresig@gmail.com>
Fri, 4 Dec 2009 17:06:47 +0000 (12:06 -0500)
committerjeresig <jeresig@gmail.com>
Fri, 4 Dec 2009 17:06:47 +0000 (12:06 -0500)
src/data.js
test/unit/data.js

index 079cf99d54e7221ab4b3c3dec626885eee822871..3e6eb19f6d99e9bacb5048ee0f636a21b46e65f9 100644 (file)
@@ -166,6 +166,21 @@ jQuery.fn.extend({
                        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){
                return this.queue( type || "fx", [] );
        }
index d3241c9eacba1ece9acd603aa6d57d5ab66ecd25..d18377d5933fafaf0ef4d3efdc5a943a395feff6 100644 (file)
@@ -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() {
        expect(1);