2010-09-08 19:54:33 +02:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2011-04-11 13:40:14 +02:00
|
|
|
function handleQueueMarkDefer( elem, type, src ) {
|
|
|
|
var deferDataKey = type + "defer",
|
|
|
|
queueDataKey = type + "queue",
|
|
|
|
markDataKey = type + "mark",
|
|
|
|
defer = jQuery.data( elem, deferDataKey, undefined, true );
|
|
|
|
if ( defer &&
|
|
|
|
( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) &&
|
2011-04-12 01:09:35 +02:00
|
|
|
( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) {
|
2011-04-11 13:40:14 +02:00
|
|
|
// Give room for hard-coded callbacks to fire first
|
|
|
|
// and eventually mark/queue something else on the element
|
|
|
|
setTimeout( function() {
|
|
|
|
if ( !jQuery.data( elem, queueDataKey, undefined, true ) &&
|
|
|
|
!jQuery.data( elem, markDataKey, undefined, true ) ) {
|
|
|
|
jQuery.removeData( elem, deferDataKey, true );
|
|
|
|
defer.resolve();
|
|
|
|
}
|
|
|
|
}, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-06 23:19:33 +01:00
|
|
|
jQuery.extend({
|
|
|
|
|
2011-04-11 13:40:14 +02:00
|
|
|
_mark: function( elem, type ) {
|
|
|
|
if ( elem ) {
|
|
|
|
type = (type || "fx") + "mark";
|
|
|
|
jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true );
|
|
|
|
}
|
|
|
|
},
|
2009-12-06 23:19:33 +01:00
|
|
|
|
2011-04-11 13:40:14 +02:00
|
|
|
_unmark: function( force, elem, type ) {
|
|
|
|
if ( force !== true ) {
|
|
|
|
type = elem;
|
|
|
|
elem = force;
|
|
|
|
force = false;
|
2009-12-22 01:58:13 +01:00
|
|
|
}
|
2011-04-11 13:40:14 +02:00
|
|
|
if ( elem ) {
|
|
|
|
type = type || "fx";
|
|
|
|
var key = type + "mark",
|
|
|
|
count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 );
|
|
|
|
if ( count ) {
|
|
|
|
jQuery.data( elem, key, count, true );
|
|
|
|
} else {
|
|
|
|
jQuery.removeData( elem, key, true );
|
|
|
|
handleQueueMarkDefer( elem, type, "mark" );
|
|
|
|
}
|
2009-12-06 23:19:33 +01:00
|
|
|
}
|
2011-04-11 13:40:14 +02:00
|
|
|
},
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2011-04-11 13:40:14 +02:00
|
|
|
queue: function( elem, type, data ) {
|
|
|
|
if ( elem ) {
|
|
|
|
type = (type || "fx") + "queue";
|
2011-04-12 01:09:35 +02:00
|
|
|
var q = jQuery.data( elem, type, undefined, true );
|
2011-04-11 13:40:14 +02:00
|
|
|
// Speed up dequeue by getting out quickly if this is just a lookup
|
|
|
|
if ( data ) {
|
2011-04-12 01:09:35 +02:00
|
|
|
if ( !q || jQuery.isArray(data) ) {
|
2011-04-11 13:40:14 +02:00
|
|
|
q = jQuery.data( elem, type, jQuery.makeArray(data), true );
|
|
|
|
} else {
|
|
|
|
q.push( data );
|
|
|
|
}
|
|
|
|
}
|
2011-04-12 01:09:35 +02:00
|
|
|
return q || [];
|
2011-04-11 13:40:14 +02:00
|
|
|
}
|
2009-12-06 23:19:33 +01:00
|
|
|
},
|
|
|
|
|
2009-12-22 01:58:13 +01:00
|
|
|
dequeue: function( elem, type ) {
|
2011-04-12 01:09:35 +02:00
|
|
|
type = type || "fx";
|
|
|
|
|
2010-11-09 17:09:07 +01:00
|
|
|
var queue = jQuery.queue( elem, type ),
|
2011-04-07 06:00:52 +02:00
|
|
|
fn = queue.shift(),
|
|
|
|
defer;
|
2009-12-06 23:19:33 +01:00
|
|
|
|
|
|
|
// If the fx queue is dequeued, always remove the progress sentinel
|
2009-12-22 01:58:13 +01:00
|
|
|
if ( fn === "inprogress" ) {
|
|
|
|
fn = queue.shift();
|
|
|
|
}
|
2009-12-06 23:19:33 +01:00
|
|
|
|
|
|
|
if ( fn ) {
|
|
|
|
// Add a progress sentinel to prevent the fx queue from being
|
|
|
|
// automatically dequeued
|
2009-12-22 01:58:13 +01:00
|
|
|
if ( type === "fx" ) {
|
|
|
|
queue.unshift("inprogress");
|
|
|
|
}
|
2009-12-06 23:19:33 +01:00
|
|
|
|
2009-12-22 01:58:13 +01:00
|
|
|
fn.call(elem, function() {
|
|
|
|
jQuery.dequeue(elem, type);
|
|
|
|
});
|
2009-12-06 23:19:33 +01:00
|
|
|
}
|
2011-01-09 22:58:23 +01:00
|
|
|
|
|
|
|
if ( !queue.length ) {
|
|
|
|
jQuery.removeData( elem, type + "queue", true );
|
2011-04-11 13:40:14 +02:00
|
|
|
handleQueueMarkDefer( elem, type, "queue" );
|
2011-01-09 22:58:23 +01:00
|
|
|
}
|
2009-12-06 23:19:33 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.fn.extend({
|
2009-12-22 01:58:13 +01:00
|
|
|
queue: function( type, data ) {
|
2009-12-06 23:19:33 +01:00
|
|
|
if ( typeof type !== "string" ) {
|
|
|
|
data = type;
|
|
|
|
type = "fx";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data === undefined ) {
|
|
|
|
return jQuery.queue( this[0], type );
|
|
|
|
}
|
2011-04-12 01:09:35 +02:00
|
|
|
return this.each(function() {
|
2009-12-06 23:19:33 +01:00
|
|
|
var queue = jQuery.queue( this, type, data );
|
|
|
|
|
2009-12-22 00:02:02 +01:00
|
|
|
if ( type === "fx" && queue[0] !== "inprogress" ) {
|
2009-12-06 23:19:33 +01:00
|
|
|
jQuery.dequeue( this, type );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2009-12-22 01:58:13 +01:00
|
|
|
dequeue: function( type ) {
|
|
|
|
return this.each(function() {
|
2009-12-06 23:19:33 +01: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 01:58:13 +01:00
|
|
|
clearQueue: function( type ) {
|
2009-12-06 23:19:33 +01:00
|
|
|
return this.queue( type || "fx", [] );
|
2011-04-07 06:00:52 +02: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",
|
2011-04-11 13:40:14 +02:00
|
|
|
queueDataKey = type + "queue",
|
|
|
|
markDataKey = type + "mark";
|
2011-04-07 06:00:52 +02:00
|
|
|
function resolve() {
|
|
|
|
if ( !( --count ) ) {
|
|
|
|
defer.resolveWith( elements, [ elements ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while( i-- ) {
|
|
|
|
if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
|
2011-04-11 13:40:14 +02:00
|
|
|
( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
|
|
|
|
jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
|
2011-04-07 06:00:52 +02:00
|
|
|
jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) {
|
|
|
|
count++;
|
|
|
|
tmp.done( resolve );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
return defer.promise();
|
2009-12-06 23:19:33 +01:00
|
|
|
}
|
|
|
|
});
|
2010-09-08 19:54:33 +02:00
|
|
|
|
|
|
|
})( jQuery );
|