Skip to content

Commit 0a4bb2c

Browse files
committed
Merge pull request gnarf#11 from mgol/cleanup+fx
Drop unneeded polyfill & Firefox prefix.
2 parents 0b82fcc + 147478c commit 0a4bb2c

File tree

3 files changed

+14
-74
lines changed

3 files changed

+14
-74
lines changed

dist/jquery.requestAnimationFrame.js

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
/*! jQuery requestAnimationFrame - v0.1.3pre - 2015-04-27
1+
/*! jQuery requestAnimationFrame - v0.1.3pre - 2016-02-03
22
* https://github.com/gnarf37/jquery-requestAnimationFrame
3-
* Copyright (c) 2015 Corey Frang; Licensed MIT */
3+
* Copyright (c) 2016 Corey Frang; Licensed MIT */
44

55
// UMD factory https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
66
(function (factory) {
7-
if (typeof define === 'function' && define.amd) {
7+
if (typeof define === 'function' && define.amd) {
88
// AMD. Register as an anonymous module.
99
define(['jquery'], factory);
10-
} else {
10+
} else {
1111
// Browser globals
1212
factory(jQuery);
13-
}
13+
}
1414
}(function (jQuery) {
1515

1616
// requestAnimationFrame polyfill adapted from Erik Möller
@@ -19,30 +19,16 @@
1919
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
2020

2121

22-
var animating,
23-
lastTime = 0,
24-
vendors = ['webkit', 'moz'],
25-
requestAnimationFrame = window.requestAnimationFrame,
26-
cancelAnimationFrame = window.cancelAnimationFrame;
27-
28-
for(; lastTime < vendors.length && !requestAnimationFrame; lastTime++) {
29-
requestAnimationFrame = window[ vendors[lastTime] + "RequestAnimationFrame" ];
30-
cancelAnimationFrame = cancelAnimationFrame ||
31-
window[ vendors[lastTime] + "CancelAnimationFrame" ] ||
32-
window[ vendors[lastTime] + "CancelRequestAnimationFrame" ];
33-
}
22+
var animating;
3423

3524
function raf() {
3625
if ( animating ) {
37-
requestAnimationFrame( raf );
26+
window.requestAnimationFrame( raf );
3827
jQuery.fx.tick();
3928
}
4029
}
4130

42-
if ( requestAnimationFrame ) {
43-
// use rAF
44-
window.requestAnimationFrame = requestAnimationFrame;
45-
window.cancelAnimationFrame = cancelAnimationFrame;
31+
if ( window.requestAnimationFrame ) {
4632
jQuery.fx.timer = function( timer ) {
4733
if ( timer() && jQuery.timers.push( timer ) && !animating ) {
4834
animating = true;
@@ -53,22 +39,6 @@ if ( requestAnimationFrame ) {
5339
jQuery.fx.stop = function() {
5440
animating = false;
5541
};
56-
} else {
57-
// polyfill
58-
window.requestAnimationFrame = function( callback, element ) {
59-
var currTime = new Date().getTime(),
60-
timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) ),
61-
id = window.setTimeout( function() {
62-
callback( currTime + timeToCall );
63-
}, timeToCall );
64-
lastTime = currTime + timeToCall;
65-
return id;
66-
};
67-
68-
window.cancelAnimationFrame = function(id) {
69-
clearTimeout(id);
70-
};
71-
7242
}
7343

7444
}));

dist/jquery.requestAnimationFrame.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.requestAnimationFrame.js

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,16 @@
2323
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
2424

2525

26-
var animating,
27-
lastTime = 0,
28-
vendors = ['webkit', 'moz'],
29-
requestAnimationFrame = window.requestAnimationFrame,
30-
cancelAnimationFrame = window.cancelAnimationFrame;
31-
32-
for(; lastTime < vendors.length && !requestAnimationFrame; lastTime++) {
33-
requestAnimationFrame = window[ vendors[lastTime] + "RequestAnimationFrame" ];
34-
cancelAnimationFrame = cancelAnimationFrame ||
35-
window[ vendors[lastTime] + "CancelAnimationFrame" ] ||
36-
window[ vendors[lastTime] + "CancelRequestAnimationFrame" ];
37-
}
26+
var animating;
3827

3928
function raf() {
4029
if ( animating ) {
41-
requestAnimationFrame( raf );
30+
window.requestAnimationFrame( raf );
4231
jQuery.fx.tick();
4332
}
4433
}
4534

46-
if ( requestAnimationFrame ) {
47-
// use rAF
48-
window.requestAnimationFrame = requestAnimationFrame;
49-
window.cancelAnimationFrame = cancelAnimationFrame;
35+
if ( window.requestAnimationFrame ) {
5036
jQuery.fx.timer = function( timer ) {
5137
if ( timer() && jQuery.timers.push( timer ) && !animating ) {
5238
animating = true;
@@ -57,22 +43,6 @@ if ( requestAnimationFrame ) {
5743
jQuery.fx.stop = function() {
5844
animating = false;
5945
};
60-
} else {
61-
// polyfill
62-
window.requestAnimationFrame = function( callback, element ) {
63-
var currTime = new Date().getTime(),
64-
timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) ),
65-
id = window.setTimeout( function() {
66-
callback( currTime + timeToCall );
67-
}, timeToCall );
68-
lastTime = currTime + timeToCall;
69-
return id;
70-
};
71-
72-
window.cancelAnimationFrame = function(id) {
73-
clearTimeout(id);
74-
};
75-
7646
}
7747

7848
}));

0 commit comments

Comments
 (0)