aboutsummaryrefslogtreecommitdiffstats
path: root/src/queue.js
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-12-06 17:19:33 -0500
committerJohn Resig <jeresig@gmail.com>2009-12-06 17:19:33 -0500
commitebad701751689b773afe29d1e3c4532c7810d02a (patch)
tree20358b0c3113083e491919ac0f8ec243baa0fb55 /src/queue.js
parent87ba780c69ac1af04afc40f2da39282d917f9108 (diff)
downloadjquery-ebad701751689b773afe29d1e3c4532c7810d02a.tar.gz
jquery-ebad701751689b773afe29d1e3c4532c7810d02a.zip
Split the queue code out from data.js into a dedicated queue.js file (also split tests accordingly).
Diffstat (limited to 'src/queue.js')
-rw-r--r--src/queue.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/queue.js b/src/queue.js
new file mode 100644
index 000000000..e636ffb41
--- /dev/null
+++ b/src/queue.js
@@ -0,0 +1,78 @@
+jQuery.extend({
+ queue: function( elem, type, data ) {
+ if ( !elem ) { return; }
+
+ type = (type || "fx") + "queue";
+ var q = jQuery.data( elem, type );
+
+ // Speed up dequeue by getting out quickly if this is just a lookup
+ if ( !data ) { return q || []; }
+
+ if ( !q || jQuery.isArray(data) ) {
+ q = jQuery.data( elem, type, jQuery.makeArray(data) );
+ } else {
+ q.push( data );
+ }
+ return q;
+ },
+
+ dequeue: function( elem, type ){
+ type = type || "fx";
+
+ var queue = jQuery.queue( elem, type ), fn = queue.shift();
+
+ // If the fx queue is dequeued, always remove the progress sentinel
+ if ( fn === "inprogress" ) { fn = queue.shift(); }
+
+ if ( fn ) {
+ // Add a progress sentinel to prevent the fx queue from being
+ // automatically dequeued
+ if ( type == "fx" ) { queue.unshift("inprogress"); }
+
+ fn.call(elem, function() { jQuery.dequeue(elem, type); });
+ }
+ }
+});
+
+jQuery.fn.extend({
+ queue: function(type, data){
+ if ( typeof type !== "string" ) {
+ data = type;
+ type = "fx";
+ }
+
+ if ( data === undefined ) {
+ return jQuery.queue( this[0], type );
+ }
+ return this.each(function(i, elem){
+ var queue = jQuery.queue( this, type, data );
+
+ if ( type == "fx" && queue[0] !== "inprogress" ) {
+ jQuery.dequeue( this, type );
+ }
+ });
+ },
+ dequeue: function(type){
+ return this.each(function(){
+ 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", [] );
+ }
+});