aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/effects.js47
-rw-r--r--test/unit/effects.js11
2 files changed, 21 insertions, 37 deletions
diff --git a/src/effects.js b/src/effects.js
index 8fa2e56e6..879b36135 100644
--- a/src/effects.js
+++ b/src/effects.js
@@ -23,13 +23,18 @@ define( [
"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();
}
}
@@ -458,8 +463,8 @@ jQuery.speed = function( speed, easing, fn ) {
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 {
@@ -664,36 +669,22 @@ jQuery.fx.tick = function() {
};
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 = {
diff --git a/test/unit/effects.js b/test/unit/effects.js
index d64a639a1..54c7f7995 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -1847,12 +1847,12 @@ QUnit.test( "non-px animation handles non-numeric start (#11971)", function( ass
} );
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,
@@ -1910,14 +1910,7 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) {
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() {