]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/queue.js
199c56d366f6dd0099b03dde4488f0ad53b64513
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / jquery / src / queue.js
1 define([
2 "./core",
3 "./data/var/data_priv",
4 "./deferred",
5 "./callbacks"
6 ], function( jQuery, data_priv ) {
7
8 jQuery.extend({
9 queue: function( elem, type, data ) {
10 var queue;
11
12 if ( elem ) {
13 type = ( type || "fx" ) + "queue";
14 queue = data_priv.get( elem, type );
15
16 // Speed up dequeue by getting out quickly if this is just a lookup
17 if ( data ) {
18 if ( !queue || jQuery.isArray( data ) ) {
19 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
20 } else {
21 queue.push( data );
22 }
23 }
24 return queue || [];
25 }
26 },
27
28 dequeue: function( elem, type ) {
29 type = type || "fx";
30
31 var queue = jQuery.queue( elem, type ),
32 startLength = queue.length,
33 fn = queue.shift(),
34 hooks = jQuery._queueHooks( elem, type ),
35 next = function() {
36 jQuery.dequeue( elem, type );
37 };
38
39 // If the fx queue is dequeued, always remove the progress sentinel
40 if ( fn === "inprogress" ) {
41 fn = queue.shift();
42 startLength--;
43 }
44
45 if ( fn ) {
46
47 // Add a progress sentinel to prevent the fx queue from being
48 // automatically dequeued
49 if ( type === "fx" ) {
50 queue.unshift( "inprogress" );
51 }
52
53 // Clear up the last queue stop function
54 delete hooks.stop;
55 fn.call( elem, next, hooks );
56 }
57
58 if ( !startLength && hooks ) {
59 hooks.empty.fire();
60 }
61 },
62
63 // Not public - generate a queueHooks object, or return the current one
64 _queueHooks: function( elem, type ) {
65 var key = type + "queueHooks";
66 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
67 empty: jQuery.Callbacks("once memory").add(function() {
68 data_priv.remove( elem, [ type + "queue", key ] );
69 })
70 });
71 }
72 });
73
74 jQuery.fn.extend({
75 queue: function( type, data ) {
76 var setter = 2;
77
78 if ( typeof type !== "string" ) {
79 data = type;
80 type = "fx";
81 setter--;
82 }
83
84 if ( arguments.length < setter ) {
85 return jQuery.queue( this[0], type );
86 }
87
88 return data === undefined ?
89 this :
90 this.each(function() {
91 var queue = jQuery.queue( this, type, data );
92
93 // Ensure a hooks for this queue
94 jQuery._queueHooks( this, type );
95
96 if ( type === "fx" && queue[0] !== "inprogress" ) {
97 jQuery.dequeue( this, type );
98 }
99 });
100 },
101 dequeue: function( type ) {
102 return this.each(function() {
103 jQuery.dequeue( this, type );
104 });
105 },
106 clearQueue: function( type ) {
107 return this.queue( type || "fx", [] );
108 },
109 // Get a promise resolved when queues of a certain type
110 // are emptied (fx is the type by default)
111 promise: function( type, obj ) {
112 var tmp,
113 count = 1,
114 defer = jQuery.Deferred(),
115 elements = this,
116 i = this.length,
117 resolve = function() {
118 if ( !( --count ) ) {
119 defer.resolveWith( elements, [ elements ] );
120 }
121 };
122
123 if ( typeof type !== "string" ) {
124 obj = type;
125 type = undefined;
126 }
127 type = type || "fx";
128
129 while ( i-- ) {
130 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
131 if ( tmp && tmp.empty ) {
132 count++;
133 tmp.empty.add( resolve );
134 }
135 }
136 resolve();
137 return defer.promise( obj );
138 }
139 });
140
141 return jQuery;
142 });