From: Ariel Flesler Date: Wed, 14 Jan 2009 23:09:52 +0000 (+0000) Subject: jquery fx: sync animations were being left on jQuery.timers (double callback) X-Git-Url: http://git.asbjorn.biz/?p=jquery.git;a=commitdiff_plain;h=34a9f8a210cfa0aabccc40a974646127d1871d1a jquery fx: sync animations were being left on jQuery.timers (double callback) jQuery.timerId is now a local var and it's not null'ed anymore. --- diff --git a/src/fx.js b/src/fx.js index 40bbc61..39456e0 100644 --- a/src/fx.js +++ b/src/fx.js @@ -1,4 +1,5 @@ var elemdisplay = {}, + timerId, fxAttrs = [ // height animations [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ], @@ -221,7 +222,6 @@ jQuery.extend({ }, timers: [], - timerId: null, fx: function( elem, options, prop ){ this.options = options; @@ -273,10 +273,8 @@ jQuery.fx.prototype = { t.elem = this.elem; - jQuery.timers.push(t); - - if ( t() && jQuery.timerId == null ) { - jQuery.timerId = setInterval(function(){ + if ( t() && jQuery.timers.push(t) == 1 ) { + timerId = setInterval(function(){ var timers = jQuery.timers; for ( var i = 0; i < timers.length; i++ ) @@ -284,8 +282,7 @@ jQuery.fx.prototype = { timers.splice(i--, 1); if ( !timers.length ) { - clearInterval( jQuery.timerId ); - jQuery.timerId = null; + clearInterval( timerId ); } }, 13); } @@ -351,11 +348,10 @@ jQuery.fx.prototype = { if ( this.options.hide || this.options.show ) for ( var p in this.options.curAnim ) jQuery.attr(this.elem.style, p, this.options.orig[p]); - } - - if ( done ) + // Execute the complete function this.options.complete.call( this.elem ); + } return false; } else { diff --git a/test/unit/fx.js b/test/unit/fx.js index 6de4254..db6210e 100644 --- a/test/unit/fx.js +++ b/test/unit/fx.js @@ -34,6 +34,39 @@ test("animate option (queue === false)", function () { }); }); +test("animate duration 0", function() { + expect(5); + + stop(); + + var $elems = jQuery([{ a:0 },{ a:0 }]), + counter = 0, + count = function(){ + counter++; + }; + + equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" ); + + $elems.eq(0).animate( {a:1}, 0, count ); + + // Failed until [6115] + equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" ); + + equals( counter, 1, "One synchronic animations" ); + + $elems.animate( { a:2 }, 0, count ); + + equals( counter, 3, "Multiple synchronic animations" ); + + $elems.eq(0).animate( {a:3}, 0, count ); + $elems.eq(1).animate( {a:3}, 20, function(){ + count(); + // Failed until [6115] + equals( counter, 5, "One synchronic and one asynchronic" ); + start(); + }); +}); + test("animate non-element", function(){ expect(1); stop();