2010-09-08 17:54:33 +00:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
jQuery.extend({
|
|
|
|
queue: function( elem, type, data ) {
|
2009-12-22 00:58:13 +00:00
|
|
|
if ( !elem ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-12-06 22:19:33 +00:00
|
|
|
|
|
|
|
type = (type || "fx") + "queue";
|
2011-01-09 21:52:33 +00:00
|
|
|
var q = jQuery._data( elem, type );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
|
|
|
// Speed up dequeue by getting out quickly if this is just a lookup
|
2009-12-22 00:58:13 +00:00
|
|
|
if ( !data ) {
|
|
|
|
return q || [];
|
|
|
|
}
|
2009-12-06 22:19:33 +00:00
|
|
|
|
|
|
|
if ( !q || jQuery.isArray(data) ) {
|
2011-01-09 21:52:33 +00:00
|
|
|
q = jQuery._data( elem, type, jQuery.makeArray(data) );
|
2009-12-22 00:58:13 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
} else {
|
|
|
|
q.push( data );
|
|
|
|
}
|
2009-12-22 00:58:13 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
return q;
|
|
|
|
},
|
|
|
|
|
2009-12-22 00:58:13 +00:00
|
|
|
dequeue: function( elem, type ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
type = type || "fx";
|
|
|
|
|
2010-11-09 16:09:07 +00:00
|
|
|
var queue = jQuery.queue( elem, type ),
|
2011-04-07 04:00:52 +00:00
|
|
|
fn = queue.shift(),
|
|
|
|
defer;
|
2009-12-06 22:19:33 +00:00
|
|
|
|
|
|
|
// If the fx queue is dequeued, always remove the progress sentinel
|
2009-12-22 00:58:13 +00:00
|
|
|
if ( fn === "inprogress" ) {
|
|
|
|
fn = queue.shift();
|
|
|
|
}
|
2009-12-06 22:19:33 +00:00
|
|
|
|
|
|
|
if ( fn ) {
|
|
|
|
// Add a progress sentinel to prevent the fx queue from being
|
|
|
|
// automatically dequeued
|
2009-12-22 00:58:13 +00:00
|
|
|
if ( type === "fx" ) {
|
|
|
|
queue.unshift("inprogress");
|
|
|
|
}
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2009-12-22 00:58:13 +00:00
|
|
|
fn.call(elem, function() {
|
|
|
|
jQuery.dequeue(elem, type);
|
|
|
|
});
|
2009-12-06 22:19:33 +00:00
|
|
|
}
|
2011-01-09 21:58:23 +00:00
|
|
|
|
|
|
|
if ( !queue.length ) {
|
|
|
|
jQuery.removeData( elem, type + "queue", true );
|
2011-04-07 04:00:52 +00:00
|
|
|
// Look if we have observers and resolve if needed
|
|
|
|
if (( defer = jQuery.data( elem, type + "defer", undefined, true ) )) {
|
|
|
|
// Give room for hard-coded callbacks to fire first
|
|
|
|
// and eventually add another animation on the element
|
|
|
|
setTimeout( function() {
|
|
|
|
if ( !jQuery.data( elem, type + "queue", undefined, true ) ) {
|
|
|
|
jQuery.removeData( elem, type + "defer", true );
|
|
|
|
defer.resolve();
|
|
|
|
}
|
|
|
|
}, 0 );
|
|
|
|
}
|
2011-01-09 21:58:23 +00:00
|
|
|
}
|
2009-12-06 22:19:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.fn.extend({
|
2009-12-22 00:58:13 +00:00
|
|
|
queue: function( type, data ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
if ( typeof type !== "string" ) {
|
|
|
|
data = type;
|
|
|
|
type = "fx";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data === undefined ) {
|
|
|
|
return jQuery.queue( this[0], type );
|
|
|
|
}
|
2010-09-20 14:41:58 +00:00
|
|
|
return this.each(function( i ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
var queue = jQuery.queue( this, type, data );
|
|
|
|
|
2009-12-21 23:02:02 +00:00
|
|
|
if ( type === "fx" && queue[0] !== "inprogress" ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
jQuery.dequeue( this, type );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2009-12-22 00:58:13 +00:00
|
|
|
dequeue: function( type ) {
|
|
|
|
return this.each(function() {
|
2009-12-06 22:19:33 +00:00
|
|
|
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 );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-12-22 00:58:13 +00:00
|
|
|
clearQueue: function( type ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
return this.queue( type || "fx", [] );
|
2011-04-07 04:00:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Get a promise resolved when queues of a certain type
|
|
|
|
// are emptied (fx is the type by default)
|
|
|
|
promise: function( type, object ) {
|
|
|
|
if ( typeof type !== "string" ) {
|
|
|
|
object = type;
|
|
|
|
type = undefined;
|
|
|
|
}
|
|
|
|
type = type || "fx";
|
|
|
|
var defer = jQuery.Deferred(),
|
|
|
|
elements = this,
|
|
|
|
i = elements.length,
|
|
|
|
count = 1,
|
|
|
|
deferDataKey = type + "defer",
|
|
|
|
queueDataKey = type + "queue";
|
|
|
|
function resolve() {
|
|
|
|
if ( !( --count ) ) {
|
|
|
|
defer.resolveWith( elements, [ elements ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while( i-- ) {
|
|
|
|
if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
|
|
|
|
jQuery.data( elements[ i ], queueDataKey, undefined, true ) &&
|
|
|
|
jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) {
|
|
|
|
count++;
|
|
|
|
tmp.done( resolve );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
return defer.promise();
|
2009-12-06 22:19:33 +00:00
|
|
|
}
|
|
|
|
});
|
2010-09-08 17:54:33 +00:00
|
|
|
|
|
|
|
})( jQuery );
|