Skip to main content

Bug Tracker

Side navigation

Ticket #6281: jquery.fx.slot.patch
File jquery.fx.slot.patch, 4.3 KB (added by AzaToth, March 14, 2010 03:13AM UTC)
diff --git a/src/effects.js b/src/effects.js
index 97456cc..3a02656 100644
--- a/src/effects.js
+++ b/src/effects.js
@@ -105,8 +105,8 @@ jQuery.fn.extend({
 					.animate({opacity: to}, speed, callback);
 	},
 
-	animate: function( prop, speed, easing, callback ) {
-		var optall = jQuery.speed(speed, easing, callback);
+	animate: function( prop, speed, easing, callback, slot ) {
+		var optall = jQuery.speed(speed, easing, callback, slot);
 
 		if ( jQuery.isEmptyObject( prop ) ) {
 			return this.each( optall.complete );
@@ -177,10 +177,10 @@ jQuery.fn.extend({
 							end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
 						}
 
-						e.custom( start, end, unit );
+						e.custom( start, end, unit, optall.slot );
 
 					} else {
-						e.custom( start, val, "" );
+						e.custom( start, val, "", optall.slot );
 					}
 				}
 			});
@@ -198,16 +198,23 @@ jQuery.fn.extend({
 		}
 
 		this.each(function() {
+		
 			// go in reverse order so anything added to the queue during the loop is ignored
 			for ( var i = timers.length - 1; i >= 0; i-- ) {
-				if ( timers[i].elem === this ) {
-					if (gotoEnd) {
-						// force the next step to be the last
-						timers[i](true);
+				var slot = timers[i];
+				for ( var j = slot.childs.length - 1; j >= 0; j-- ) {
+					if ( slot.childs[j].elem === this ) {
+						if (gotoEnd) {
+							// force the next step to be the last
+							slot.childs[j](true);
+						}
+						slot.childs.splice(j, 1);
 					}
-
+				}
+				if ( !slot.childs.length  ) {
 					timers.splice(i, 1);
 				}
+
 			}
 		});
 
@@ -245,7 +252,7 @@ jQuery.each({
 });
 
 jQuery.extend({
-	speed: function( speed, easing, fn ) {
+	speed: function( speed, easing, fn, slot ) {
 		var opt = speed && typeof speed === "object" ? speed : {
 			complete: fn || !fn && easing ||
 				jQuery.isFunction( speed ) && speed,
@@ -256,6 +263,7 @@ jQuery.extend({
 		opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
 			jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
 
+		opt.slot = slot || new jQuery.slot();
 		// Queueing
 		opt.old = opt.complete;
 		opt.complete = function() {
@@ -281,6 +289,12 @@ jQuery.extend({
 
 	timers: [],
 
+	slot: function(time) {
+		this.childs = [];
+		this.time = time || now();
+		this.added = false;
+	},
+
 	fx: function( elem, options, prop ) {
 		this.options = options;
 		this.elem = elem;
@@ -319,8 +333,8 @@ jQuery.fx.prototype = {
 	},
 
 	// Start an animation from one number to another
-	custom: function( from, to, unit ) {
-		this.startTime = now();
+	custom: function( from, to, unit, slot ) {
+		this.startTime = slot.time;
 		this.start = from;
 		this.end = to;
 		this.unit = unit || this.unit || "px";
@@ -329,13 +343,20 @@ jQuery.fx.prototype = {
 
 		var self = this;
 		function t( gotoEnd ) {
-			return self.step(gotoEnd);
+			return self.step(gotoEnd, slot);
 		}
 
 		t.elem = this.elem;
 
-		if ( t() && jQuery.timers.push(t) && !timerId ) {
-			timerId = setInterval(jQuery.fx.tick, 13);
+		if( t() ) {
+			slot.childs.push( t );
+			if( !slot.added ) {
+				jQuery.timers.push( slot );
+				slot.added = true;
+			}
+			if( ! timerId ) {
+				timerId = setInterval(jQuery.fx.tick, 13);
+			}
 		}
 	},
 
@@ -365,8 +386,8 @@ jQuery.fx.prototype = {
 	},
 
 	// Each step of an animation
-	step: function( gotoEnd ) {
-		var t = now(), done = true;
+	step: function( gotoEnd, slot ) {
+		var t = slot.time, done = true;
 
 		if ( gotoEnd || t >= this.options.duration + this.startTime ) {
 			this.now = this.end;
@@ -436,9 +457,17 @@ jQuery.extend( jQuery.fx, {
 		var timers = jQuery.timers;
 
 		for ( var i = 0; i < timers.length; i++ ) {
-			if ( !timers[i]() ) {
+			var slot = timers[i];
+			for ( var j = 0; j < slot.childs.length; j++ ) {
+				if ( !slot.childs[j]() ) {
+					slot.childs.splice(j--, 1);
+				}
+			}
+			slot.time = now();
+			if ( !slot.childs.length  ) {
 				timers.splice(i--, 1);
 			}
+
 		}
 
 		if ( !timers.length ) {
@@ -475,8 +504,10 @@ jQuery.extend( jQuery.fx, {
 
 if ( jQuery.expr && jQuery.expr.filters ) {
 	jQuery.expr.filters.animated = function( elem ) {
-		return jQuery.grep(jQuery.timers, function( fn ) {
-			return elem === fn.elem;
-		}).length;
+		return jQuery.grep(jQuery.timers, function( slot ) {
+				return jQuery.grep(slot.childs, function( fn ) {
+						return elem === fn.elem;
+					}).length;
+			}).length;
 	};
 }

Download in other formats:

Original Format