Moved unload abort code so that the event is only bound if the xhr transport is used...
[jquery.git] / src / queue.js
1 (function( jQuery ) {
2
3 jQuery.extend({
4         queue: function( elem, type, data ) {
5                 if ( !elem ) {
6                         return;
7                 }
8
9                 type = (type || "fx") + "queue";
10                 var q = jQuery.data( elem, type );
11
12                 // Speed up dequeue by getting out quickly if this is just a lookup
13                 if ( !data ) {
14                         return q || [];
15                 }
16
17                 if ( !q || jQuery.isArray(data) ) {
18                         q = jQuery.data( elem, type, jQuery.makeArray(data) );
19
20                 } else {
21                         q.push( data );
22                 }
23
24                 return q;
25         },
26
27         dequeue: function( elem, type ) {
28                 type = type || "fx";
29
30                 var queue = jQuery.queue( elem, type ),
31                         fn = queue.shift();
32
33                 // If the fx queue is dequeued, always remove the progress sentinel
34                 if ( fn === "inprogress" ) {
35                         fn = queue.shift();
36                 }
37
38                 if ( fn ) {
39                         // Add a progress sentinel to prevent the fx queue from being
40                         // automatically dequeued
41                         if ( type === "fx" ) {
42                                 queue.unshift("inprogress");
43                         }
44
45                         fn.call(elem, function() {
46                                 jQuery.dequeue(elem, type);
47                         });
48                 }
49         }
50 });
51
52 jQuery.fn.extend({
53         queue: function( type, data ) {
54                 if ( typeof type !== "string" ) {
55                         data = type;
56                         type = "fx";
57                 }
58
59                 if ( data === undefined ) {
60                         return jQuery.queue( this[0], type );
61                 }
62                 return this.each(function( i ) {
63                         var queue = jQuery.queue( this, type, data );
64
65                         if ( type === "fx" && queue[0] !== "inprogress" ) {
66                                 jQuery.dequeue( this, type );
67                         }
68                 });
69         },
70         dequeue: function( type ) {
71                 return this.each(function() {
72                         jQuery.dequeue( this, type );
73                 });
74         },
75
76         // Based off of the plugin by Clint Helfers, with permission.
77         // http://blindsignals.com/index.php/2009/07/jquery-delay/
78         delay: function( time, type ) {
79                 time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
80                 type = type || "fx";
81
82                 return this.queue( type, function() {
83                         var elem = this;
84                         setTimeout(function() {
85                                 jQuery.dequeue( elem, type );
86                         }, time );
87                 });
88         },
89
90         clearQueue: function( type ) {
91                 return this.queue( type || "fx", [] );
92         }
93 });
94
95 })( jQuery );