Blame view

app/bower_components/jquery/src/queue.js 3.02 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
  	"./core",
87c93a029   Dang YoungWorld   add modal
3
  	"./data/var/dataPriv",
f986e111b   TRUONG   add libs
4
5
  	"./deferred",
  	"./callbacks"
87c93a029   Dang YoungWorld   add modal
6
  ], function( jQuery, dataPriv ) {
f986e111b   TRUONG   add libs
7

87c93a029   Dang YoungWorld   add modal
8
9
10
  "use strict";
  
  jQuery.extend( {
f986e111b   TRUONG   add libs
11
12
13
14
15
  	queue: function( elem, type, data ) {
  		var queue;
  
  		if ( elem ) {
  			type = ( type || "fx" ) + "queue";
87c93a029   Dang YoungWorld   add modal
16
  			queue = dataPriv.get( elem, type );
f986e111b   TRUONG   add libs
17
18
19
  
  			// Speed up dequeue by getting out quickly if this is just a lookup
  			if ( data ) {
87c93a029   Dang YoungWorld   add modal
20
21
  				if ( !queue || jQuery.isArray( data ) ) {
  					queue = dataPriv.access( elem, type, jQuery.makeArray( data ) );
f986e111b   TRUONG   add libs
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
  				} 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" );
  			}
87c93a029   Dang YoungWorld   add modal
54
  			// Clear up the last queue stop function
f986e111b   TRUONG   add libs
55
56
57
58
59
60
61
62
  			delete hooks.stop;
  			fn.call( elem, next, hooks );
  		}
  
  		if ( !startLength && hooks ) {
  			hooks.empty.fire();
  		}
  	},
87c93a029   Dang YoungWorld   add modal
63
  	// Not public - generate a queueHooks object, or return the current one
f986e111b   TRUONG   add libs
64
65
  	_queueHooks: function( elem, type ) {
  		var key = type + "queueHooks";
87c93a029   Dang YoungWorld   add modal
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 ] );
  			} )
  		} );
f986e111b   TRUONG   add libs
71
  	}
87c93a029   Dang YoungWorld   add modal
72
  } );
f986e111b   TRUONG   add libs
73

87c93a029   Dang YoungWorld   add modal
74
  jQuery.fn.extend( {
f986e111b   TRUONG   add libs
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 ) {
87c93a029   Dang YoungWorld   add modal
85
  			return jQuery.queue( this[ 0 ], type );
f986e111b   TRUONG   add libs
86
87
88
89
  		}
  
  		return data === undefined ?
  			this :
87c93a029   Dang YoungWorld   add modal
90
  			this.each( function() {
f986e111b   TRUONG   add libs
91
  				var queue = jQuery.queue( this, type, data );
87c93a029   Dang YoungWorld   add modal
92
  				// Ensure a hooks for this queue
f986e111b   TRUONG   add libs
93
  				jQuery._queueHooks( this, type );
87c93a029   Dang YoungWorld   add modal
94
  				if ( type === "fx" && queue[ 0 ] !== "inprogress" ) {
f986e111b   TRUONG   add libs
95
96
  					jQuery.dequeue( this, type );
  				}
87c93a029   Dang YoungWorld   add modal
97
  			} );
f986e111b   TRUONG   add libs
98
99
  	},
  	dequeue: function( type ) {
87c93a029   Dang YoungWorld   add modal
100
  		return this.each( function() {
f986e111b   TRUONG   add libs
101
  			jQuery.dequeue( this, type );
87c93a029   Dang YoungWorld   add modal
102
  		} );
f986e111b   TRUONG   add libs
103
104
105
106
  	},
  	clearQueue: function( type ) {
  		return this.queue( type || "fx", [] );
  	},
87c93a029   Dang YoungWorld   add modal
107

f986e111b   TRUONG   add libs
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  	// 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-- ) {
87c93a029   Dang YoungWorld   add modal
129
  			tmp = dataPriv.get( elements[ i ], type + "queueHooks" );
f986e111b   TRUONG   add libs
130
131
132
133
134
135
136
137
  			if ( tmp && tmp.empty ) {
  				count++;
  				tmp.empty.add( resolve );
  			}
  		}
  		resolve();
  		return defer.promise( obj );
  	}
87c93a029   Dang YoungWorld   add modal
138
  } );
f986e111b   TRUONG   add libs
139
140
  
  return jQuery;
87c93a029   Dang YoungWorld   add modal
141
  } );