Bug Tracker

/**
 * @author Abdur-Rahman Advany
 */
jQuery.fn.extend({
	queue: function(type,fn){
		if ( !fn ) {
			fn = type;
			type = "fx";
 		}
		return this.each(function(){
			if ( !this.queue )
				this.queue = {};
			if ( !this.limitQueue )
				this.limitQueue = {};
			if ( !this.queue[type] )
				this.queue[type] = [];
			if ( !jQuery.queue )
				jQuery.queue = {};
			if (!this.limitQueue[type] || this.queue[type].length < this.limitQueue[type])
				if (!this.scope)
					this.queue[type].push( fn );
			if (this.scope){
				if ( !jQuery.scope[this.scope] )
					jQuery.scope[this.scope] = [];
				if (!this.limitQueue[type] || jQuery.scope[this.scope].length < this.limitQueue[type])
					jQuery.scope[this.scope].push( new Array(this, fn) );
			}
			if ( this.scope && jQuery.scope[this.scope].length == 1 || this.queue[type].length == 1 )
				fn.apply(this);
		});
	},
	/**
	 * limit the amount of active queue items in a queue
	 *
	 * @example $("div").slideUp().limitQueue(1); // will not repeat slideUp until its done
	 *
	 * @name limitQueue
	 * @type jQuery.fn
	 * @param String to be used to match the queue type
	 * @param Integer to be used to specify the limit of queue
	 * @cat queue
	 */
	limitQueue: function(type, limit){
		if ( !limit ) {
			limit = type;
			type = 'fx';
		}
		return this.each(function(){
			if ( !this.limitQueue )
				this.limitQueue = {};
			this.limitQueue[type] = limit;
		});
	},
	scope: function(name){
		if ( !jQuery.scope )
			jQuery.scope = {};
		if ( !jQuery.scope[name] )
			jQuery.scope[name] = [];
		return this.each(function(){
			if ( !this.scope )
				this.scope = name;
		});
	},
	dequeue: function(elem,type){
		type = type || "fx";
		if ( !elem.scope && elem.queue && elem.queue[type]) {
			// Remove self
			elem.queue[type].shift();
			// Get next function
			var f = elem.queue[type][0];
			if ( f ) f.apply( elem );
		} else {
			// Remove self
			jQuery.scope[elem.scope].shift();
			if ( jQuery.scope[elem.scope][0] ){
				var elem_this = jQuery.scope[elem.scope][0][0];
				var f = jQuery.scope[elem.scope][0][1];
			}
			if ( f ) f.apply( elem_this );
		}
	}
});