"use strict";
var
- fxNow, timerId,
+ fxNow, inProgress,
rfxtypes = /^(?:toggle|show|hide)$/,
rrun = /queueHooks$/;
-function raf() {
- if ( timerId ) {
- window.requestAnimationFrame( raf );
+function schedule() {
+ if ( inProgress ) {
+ if ( document.hidden === false && window.requestAnimationFrame ) {
+ window.requestAnimationFrame( schedule );
+ } else {
+ window.setTimeout( schedule, jQuery.fx.interval );
+ }
+
jQuery.fx.tick();
}
}
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
};
- // Go to the end state if fx are off or if document is hidden
- if ( jQuery.fx.off || document.hidden ) {
+ // Go to the end state if fx are off
+ if ( jQuery.fx.off ) {
opt.duration = 0;
} else {
};
jQuery.fx.timer = function( timer ) {
- var i = jQuery.timers.push( timer ) - 1,
- timers = jQuery.timers;
-
- if ( timer() ) {
- jQuery.fx.start();
-
- // If the timer finished immediately, safely remove it (allowing for external removal)
- // Use a superfluous post-decrement for better compressibility w.r.t. jQuery.fx.tick above
- } else if ( timers[ i ] === timer ) {
- timers.splice( i--, 1 );
- }
+ jQuery.timers.push( timer );
+ jQuery.fx.start();
};
jQuery.fx.interval = 13;
jQuery.fx.start = function() {
- if ( !timerId ) {
- timerId = window.requestAnimationFrame ?
- window.requestAnimationFrame( raf ) :
- window.setInterval( jQuery.fx.tick, jQuery.fx.interval );
+ if ( inProgress ) {
+ return;
}
+
+ inProgress = true;
+ schedule();
};
jQuery.fx.stop = function() {
- if ( window.cancelAnimationFrame ) {
- window.cancelAnimationFrame( timerId );
- } else {
- window.clearInterval( timerId );
- }
-
- timerId = null;
+ inProgress = null;
};
jQuery.fx.speeds = {
} );
QUnit.test( "Animation callbacks (#11797)", function( assert ) {
- assert.expect( 16 );
+ assert.expect( 15 );
var prog = 0,
targets = jQuery( "#foo" ).children(),
done = false,
- expectedProgress = 0;
+ expectedProgress = 1;
targets.eq( 0 ).animate( {}, {
duration: 1,
assert.ok( true, "async: start" );
},
progress: function( anim, percent ) {
-
- // occasionally the progress handler is called twice in first frame.... *shrug*
- if ( percent === 0 && expectedProgress === 1 ) {
- return;
- }
assert.equal( percent, expectedProgress, "async: progress " + expectedProgress );
-
- // once at 0, once at 1
expectedProgress++;
},
done: function() {