aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/effects.js38
-rw-r--r--test/unit/effects.js103
2 files changed, 20 insertions, 121 deletions
diff --git a/src/effects.js b/src/effects.js
index 2e6cf2529..87dedc430 100644
--- a/src/effects.js
+++ b/src/effects.js
@@ -29,6 +29,11 @@ function raf() {
}
}
+// Will get false negative for old browsers which is okay
+function isDocumentHidden() {
+ return "hidden" in document && document.hidden;
+}
+
// Animations created synchronously will run synchronously
function createFxNow() {
window.setTimeout( function() {
@@ -408,15 +413,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 ) {
- opt.duration = 0;
-
- } else {
- opt.duration = typeof opt.duration === "number" ?
- opt.duration : opt.duration in jQuery.fx.speeds ?
- jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
- }
+ opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
+ opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
// normalize opt.queue - true/undefined/null -> "fx"
if ( opt.queue == null || opt.queue === true ) {
@@ -449,6 +447,10 @@ jQuery.fn.extend( {
.end().animate( { opacity: to }, speed, easing, callback );
},
animate: function( prop, speed, easing, callback ) {
+ if ( isDocumentHidden() ) {
+ return this;
+ }
+
var empty = jQuery.isEmptyObject( prop ),
optall = jQuery.speed( speed, easing, callback ),
doAnimation = function() {
@@ -620,18 +622,18 @@ jQuery.fx.timer = function( timer ) {
jQuery.fx.interval = 13;
jQuery.fx.start = function() {
- timerId = window.requestAnimationFrame ?
- window.requestAnimationFrame( raf ) :
- window.setInterval( jQuery.fx.tick, jQuery.fx.interval );
+ if ( !timerId ) {
+ if ( window.requestAnimationFrame ) {
+ timerId = true;
+ window.requestAnimationFrame( raf );
+ } else {
+ timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
+ }
+ }
};
jQuery.fx.stop = function() {
- if ( window.cancelAnimationFrame ) {
- window.cancelAnimationFrame( timerId );
- } else {
- window.clearInterval( timerId );
- }
-
+ clearInterval( timerId );
timerId = null;
};
diff --git a/test/unit/effects.js b/test/unit/effects.js
index 9f4dcea1d..2e65a62ed 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -2206,107 +2206,4 @@ test( "Respect display value on inline elements (#14824)", 2, function() {
clock.tick( 800 );
});
-test( "Animation should go to its end state if document.hidden = true", 1, function() {
- var height;
- if ( Object.defineProperty ) {
-
- // Can't rewrite document.hidden property if its host property
- try {
- Object.defineProperty( document, "hidden", {
- get: function() {
- return true;
- }
- });
- } catch ( e ) {}
- } else {
- document.hidden = true;
- }
-
- if ( document.hidden ) {
- height = jQuery( "#qunit-fixture" ).animate({ height: 500 } ).height();
-
- equal( height, 500, "Animation should happen immediately if document.hidden = true" );
- jQuery( document ).removeProp( "hidden" );
-
- } else {
- ok( true, "Can't run the test since we can't reproduce correct environment for it" );
- }
-});
-
-test( "jQuery.easing._default (gh-2218)", function() {
- expect( 2 );
-
- jQuery( "#foo" )
- .animate( { width: "5px" }, {
- duration: 5,
- start: function( anim ) {
- equal( anim.opts.easing, jQuery.easing._default,
- "anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
- }
- })
- .animate( { height: "5px" }, {
- duration: 5,
- easing: "linear",
- start: function( anim ) {
- equal( anim.opts.easing, "linear",
- "anim.opts.easing should be equal to the easing argument" );
- }
- })
- .stop();
-
- this.clock.tick( 25 );
-});
-
-test( "jQuery.easing._default in Animation (gh-2218", function() {
- expect( 3 );
-
- var animation,
- defaultEasing = jQuery.easing._default,
- called = false,
- testObject = { "width": 100 },
- testDest = { "width": 200 };
-
- jQuery.easing.custom = function( p ) {
- called = true;
- return p;
- };
- jQuery.easing._default = "custom";
-
- animation = jQuery.Animation( testObject, testDest, { "duration": 1 } );
- animation.done( function() {
- equal( testObject.width, testDest.width, "Animated width" );
- ok( called, "Custom jQuery.easing._default called" );
- strictEqual( animation.opts.easing, "custom",
- "Animation used custom jQuery.easing._default" );
- jQuery.easing._default = defaultEasing;
- delete jQuery.easing.custom;
- });
-
- this.clock.tick( 10 );
-});
-
-test( "jQuery.easing._default in Tween (gh-2218)", function() {
- expect( 3 );
-
- var tween,
- defaultEasing = jQuery.easing._default,
- called = false,
- testObject = { "width": 100 };
-
- jQuery.easing.custom = function( p ) {
- called = true;
- return p;
- };
- jQuery.easing._default = "custom";
-
- tween = jQuery.Tween( testObject, { "duration": 1 }, "width", 200 );
- tween.run( 1 );
- equal( testObject.width, 200, "Animated width" );
- ok( called, "Custom jQuery.easing._default called" );
- strictEqual( tween.easing, "custom",
- "Animation used custom jQuery.easing._default" );
- jQuery.easing._default = defaultEasing;
- delete jQuery.easing.custom;
-});
-
})();