From: Corey Frang Date: Thu, 8 Nov 2012 06:02:14 +0000 (-0600) Subject: Fix #12803. Add jQuery.fx.start as a hook point. Close gh-1024. X-Git-Tag: 1.9.0b1~85 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=516a7a8792200614d43caf1c9a004760fb5fec68;p=jquery.git Fix #12803. Add jQuery.fx.start as a hook point. Close gh-1024. --- diff --git a/src/effects.js b/src/effects.js index bfe282aa5..d5ff7464c 100644 --- a/src/effects.js +++ b/src/effects.js @@ -640,13 +640,19 @@ jQuery.fx.tick = function() { }; jQuery.fx.timer = function( timer ) { - if ( timer() && jQuery.timers.push( timer ) && !timerId ) { - timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval ); + if ( timer() && jQuery.timers.push( timer ) ) { + jQuery.fx.start(); } }; jQuery.fx.interval = 13; +jQuery.fx.start = function() { + if ( !timerId ) { + timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval ); + } +}; + jQuery.fx.stop = function() { clearInterval( timerId ); timerId = null; diff --git a/test/unit/effects.js b/test/unit/effects.js index af2eddc4e..b615dfd6d 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -1877,4 +1877,31 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) { }); }); +test( "jQuery.fx.start & jQuery.fx.stop hook points", function() { + var oldStart = jQuery.fx.start, + oldStop = jQuery.fx.stop, + foo = jQuery({ foo: 0 }); + + expect( 3 ); + + jQuery.fx.start = function() { + ok( true, "start called" ); + }; + jQuery.fx.stop = function() { + ok( true, "stop called" ); + }; + + // calls start + foo.animate({ foo: 1 }, { queue: false }); + // calls start + foo.animate({ foo: 2 }, { queue: false }); + foo.stop(); + // calls stop + jQuery.fx.tick(); + + // cleanup + jQuery.fx.start = oldStart; + jQuery.fx.stop = oldStop; +}); + } // if ( jQuery.fx )