Fix #12803. Add jQuery.fx.start as a hook point. Close gh-1024.

This commit is contained in:
Corey Frang 2012-11-08 00:02:14 -06:00 committed by Dave Methvin
parent 84629a9b87
commit 516a7a8792
2 changed files with 35 additions and 2 deletions

10
src/effects.js vendored
View File

@ -640,13 +640,19 @@ jQuery.fx.tick = function() {
}; };
jQuery.fx.timer = function( timer ) { jQuery.fx.timer = function( timer ) {
if ( timer() && jQuery.timers.push( timer ) && !timerId ) { if ( timer() && jQuery.timers.push( timer ) ) {
timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval ); jQuery.fx.start();
} }
}; };
jQuery.fx.interval = 13; jQuery.fx.interval = 13;
jQuery.fx.start = function() {
if ( !timerId ) {
timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
}
};
jQuery.fx.stop = function() { jQuery.fx.stop = function() {
clearInterval( timerId ); clearInterval( timerId );
timerId = null; timerId = null;

27
test/unit/effects.js vendored
View File

@ -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 ) } // if ( jQuery.fx )