Blame view

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