Skip to content

Commit a769a01

Browse files
committed
Revert "Effects: Improve raf logic"
This reverts commit 9dc29a2.
1 parent 0b5e8db commit a769a01

File tree

2 files changed

+20
-121
lines changed

2 files changed

+20
-121
lines changed

src/effects.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ function raf() {
2929
}
3030
}
3131

32+
// Will get false negative for old browsers which is okay
33+
function isDocumentHidden() {
34+
return "hidden" in document && document.hidden;
35+
}
36+
3237
// Animations created synchronously will run synchronously
3338
function createFxNow() {
3439
window.setTimeout( function() {
@@ -408,15 +413,8 @@ jQuery.speed = function( speed, easing, fn ) {
408413
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
409414
};
410415

411-
// Go to the end state if fx are off or if document is hidden
412-
if ( jQuery.fx.off || document.hidden ) {
413-
opt.duration = 0;
414-
415-
} else {
416-
opt.duration = typeof opt.duration === "number" ?
417-
opt.duration : opt.duration in jQuery.fx.speeds ?
418-
jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
419-
}
416+
opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
417+
opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
420418

421419
// normalize opt.queue - true/undefined/null -> "fx"
422420
if ( opt.queue == null || opt.queue === true ) {
@@ -449,6 +447,10 @@ jQuery.fn.extend( {
449447
.end().animate( { opacity: to }, speed, easing, callback );
450448
},
451449
animate: function( prop, speed, easing, callback ) {
450+
if ( isDocumentHidden() ) {
451+
return this;
452+
}
453+
452454
var empty = jQuery.isEmptyObject( prop ),
453455
optall = jQuery.speed( speed, easing, callback ),
454456
doAnimation = function() {
@@ -620,18 +622,18 @@ jQuery.fx.timer = function( timer ) {
620622
jQuery.fx.interval = 13;
621623

622624
jQuery.fx.start = function() {
623-
timerId = window.requestAnimationFrame ?
624-
window.requestAnimationFrame( raf ) :
625-
window.setInterval( jQuery.fx.tick, jQuery.fx.interval );
625+
if ( !timerId ) {
626+
if ( window.requestAnimationFrame ) {
627+
timerId = true;
628+
window.requestAnimationFrame( raf );
629+
} else {
630+
timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
631+
}
632+
}
626633
};
627634

628635
jQuery.fx.stop = function() {
629-
if ( window.cancelAnimationFrame ) {
630-
window.cancelAnimationFrame( timerId );
631-
} else {
632-
window.clearInterval( timerId );
633-
}
634-
636+
clearInterval( timerId );
635637
timerId = null;
636638
};
637639

test/unit/effects.js

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,107 +2206,4 @@ test( "Respect display value on inline elements (#14824)", 2, function() {
22062206
clock.tick( 800 );
22072207
});
22082208

2209-
test( "Animation should go to its end state if document.hidden = true", 1, function() {
2210-
var height;
2211-
if ( Object.defineProperty ) {
2212-
2213-
// Can't rewrite document.hidden property if its host property
2214-
try {
2215-
Object.defineProperty( document, "hidden", {
2216-
get: function() {
2217-
return true;
2218-
}
2219-
});
2220-
} catch ( e ) {}
2221-
} else {
2222-
document.hidden = true;
2223-
}
2224-
2225-
if ( document.hidden ) {
2226-
height = jQuery( "#qunit-fixture" ).animate({ height: 500 } ).height();
2227-
2228-
equal( height, 500, "Animation should happen immediately if document.hidden = true" );
2229-
jQuery( document ).removeProp( "hidden" );
2230-
2231-
} else {
2232-
ok( true, "Can't run the test since we can't reproduce correct environment for it" );
2233-
}
2234-
});
2235-
2236-
test( "jQuery.easing._default (gh-2218)", function() {
2237-
expect( 2 );
2238-
2239-
jQuery( "#foo" )
2240-
.animate( { width: "5px" }, {
2241-
duration: 5,
2242-
start: function( anim ) {
2243-
equal( anim.opts.easing, jQuery.easing._default,
2244-
"anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
2245-
}
2246-
})
2247-
.animate( { height: "5px" }, {
2248-
duration: 5,
2249-
easing: "linear",
2250-
start: function( anim ) {
2251-
equal( anim.opts.easing, "linear",
2252-
"anim.opts.easing should be equal to the easing argument" );
2253-
}
2254-
})
2255-
.stop();
2256-
2257-
this.clock.tick( 25 );
2258-
});
2259-
2260-
test( "jQuery.easing._default in Animation (gh-2218", function() {
2261-
expect( 3 );
2262-
2263-
var animation,
2264-
defaultEasing = jQuery.easing._default,
2265-
called = false,
2266-
testObject = { "width": 100 },
2267-
testDest = { "width": 200 };
2268-
2269-
jQuery.easing.custom = function( p ) {
2270-
called = true;
2271-
return p;
2272-
};
2273-
jQuery.easing._default = "custom";
2274-
2275-
animation = jQuery.Animation( testObject, testDest, { "duration": 1 } );
2276-
animation.done( function() {
2277-
equal( testObject.width, testDest.width, "Animated width" );
2278-
ok( called, "Custom jQuery.easing._default called" );
2279-
strictEqual( animation.opts.easing, "custom",
2280-
"Animation used custom jQuery.easing._default" );
2281-
jQuery.easing._default = defaultEasing;
2282-
delete jQuery.easing.custom;
2283-
});
2284-
2285-
this.clock.tick( 10 );
2286-
});
2287-
2288-
test( "jQuery.easing._default in Tween (gh-2218)", function() {
2289-
expect( 3 );
2290-
2291-
var tween,
2292-
defaultEasing = jQuery.easing._default,
2293-
called = false,
2294-
testObject = { "width": 100 };
2295-
2296-
jQuery.easing.custom = function( p ) {
2297-
called = true;
2298-
return p;
2299-
};
2300-
jQuery.easing._default = "custom";
2301-
2302-
tween = jQuery.Tween( testObject, { "duration": 1 }, "width", 200 );
2303-
tween.run( 1 );
2304-
equal( testObject.width, 200, "Animated width" );
2305-
ok( called, "Custom jQuery.easing._default called" );
2306-
strictEqual( tween.easing, "custom",
2307-
"Animation used custom jQuery.easing._default" );
2308-
jQuery.easing._default = defaultEasing;
2309-
delete jQuery.easing.custom;
2310-
});
2311-
23122209
})();

0 commit comments

Comments
 (0)