Skip to content

Commit 0bfebb2

Browse files
committed
The requestAnimationFrame polyfill no longer expects a Browserify environment and uses window through-out.
1 parent d0786e8 commit 0bfebb2

1 file changed

Lines changed: 20 additions & 35 deletions

File tree

src/polyfills/requestAnimationFrame.js

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,31 @@
55
// https://gist.github.com/timhall/4078614
66
// https://github.com/Financial-Times/polyfill-service/tree/master/polyfills/requestAnimationFrame
77

8-
// Expected to be used with Browserify
9-
// Browserify automatically detects the use of `global` and passes the
10-
// correct reference of `global`, `self`, and finally `window`
11-
12-
// Date.now
13-
if (!(Date.now && Date.prototype.getTime)) {
14-
Date.now = function now() {
15-
return new Date().getTime();
16-
};
17-
}
18-
19-
// performance.now
20-
if (!(global.performance && global.performance.now)) {
21-
var startTime = Date.now();
22-
if (!global.performance) {
23-
global.performance = {};
24-
}
25-
global.performance.now = function () {
26-
return Date.now() - startTime;
27-
};
28-
}
29-
308
// requestAnimationFrame
319
var lastTime = Date.now();
32-
var vendors = ['ms', 'moz', 'webkit', 'o'];
3310

34-
for(var x = 0; x < vendors.length && !global.requestAnimationFrame; ++x) {
35-
global.requestAnimationFrame = global[vendors[x] + 'RequestAnimationFrame'];
36-
global.cancelAnimationFrame = global[vendors[x] + 'CancelAnimationFrame'] ||
37-
global[vendors[x] + 'CancelRequestAnimationFrame'];
11+
var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
12+
13+
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++)
14+
{
15+
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
16+
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
3817
}
3918

40-
if (!global.requestAnimationFrame) {
41-
global.requestAnimationFrame = function (callback) {
42-
if (typeof callback !== 'function') {
19+
if (!window.requestAnimationFrame)
20+
{
21+
window.requestAnimationFrame = function (callback)
22+
{
23+
if (typeof callback !== 'function')
24+
{
4325
throw new TypeError(callback + 'is not a function');
4426
}
4527

46-
var currentTime = Date.now(),
47-
delay = 16 + lastTime - currentTime;
28+
var currentTime = Date.now();
29+
var delay = 16 + lastTime - currentTime;
4830

49-
if (delay < 0) {
31+
if (delay < 0)
32+
{
5033
delay = 0;
5134
}
5235

@@ -59,8 +42,10 @@ if (!global.requestAnimationFrame) {
5942
};
6043
}
6144

62-
if (!global.cancelAnimationFrame) {
63-
global.cancelAnimationFrame = function(id) {
45+
if (!window.cancelAnimationFrame)
46+
{
47+
window.cancelAnimationFrame = function(id)
48+
{
6449
clearTimeout(id);
6550
};
6651
}

0 commit comments

Comments
 (0)