]> source.dussan.org Git - jquery.git/commitdiff
Revert "Effects: Improve raf logic"
authorOleg Gaidarenko <markelog@gmail.com>
Tue, 22 Dec 2015 15:05:38 +0000 (18:05 +0300)
committerOleg Gaidarenko <markelog@gmail.com>
Tue, 22 Dec 2015 15:05:38 +0000 (18:05 +0300)
This reverts commit 9dc29a2b130e6bbcdbcaf8fdc1433a41e6b7a585.

src/effects.js
test/unit/effects.js

index 2e6cf2529ae6b0d68ea74e08bd94d3282f01e44a..87dedc430464427a4ab991a2ded9137592b64dc4 100644 (file)
@@ -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;
 };
 
index 9f4dcea1dbdd2a61855ca758115171585648fd30..2e65a62ed55ef5814ff1862b28bc99e8edb2d2d7 100644 (file)
@@ -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;
-});
-
 })();