Skip to content

Drop unneeded polyfill & Firefox prefix. #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 8 additions & 38 deletions dist/jquery.requestAnimationFrame.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*! jQuery requestAnimationFrame - v0.1.3pre - 2015-04-27
/*! jQuery requestAnimationFrame - v0.1.3pre - 2016-02-03
* https://github.com/gnarf37/jquery-requestAnimationFrame
* Copyright (c) 2015 Corey Frang; Licensed MIT */
* Copyright (c) 2016 Corey Frang; Licensed MIT */

// UMD factory https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
(function (factory) {
if (typeof define === 'function' && define.amd) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
} else {
// Browser globals
factory(jQuery);
}
}
}(function (jQuery) {

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


var animating,
lastTime = 0,
vendors = ['webkit', 'moz'],
requestAnimationFrame = window.requestAnimationFrame,
cancelAnimationFrame = window.cancelAnimationFrame;

for(; lastTime < vendors.length && !requestAnimationFrame; lastTime++) {
requestAnimationFrame = window[ vendors[lastTime] + "RequestAnimationFrame" ];
cancelAnimationFrame = cancelAnimationFrame ||
window[ vendors[lastTime] + "CancelAnimationFrame" ] ||
window[ vendors[lastTime] + "CancelRequestAnimationFrame" ];
}
var animating;

function raf() {
if ( animating ) {
requestAnimationFrame( raf );
window.requestAnimationFrame( raf );
jQuery.fx.tick();
}
}

if ( requestAnimationFrame ) {
// use rAF
window.requestAnimationFrame = requestAnimationFrame;
window.cancelAnimationFrame = cancelAnimationFrame;
if ( window.requestAnimationFrame ) {
jQuery.fx.timer = function( timer ) {
if ( timer() && jQuery.timers.push( timer ) && !animating ) {
animating = true;
Expand All @@ -53,22 +39,6 @@ if ( requestAnimationFrame ) {
jQuery.fx.stop = function() {
animating = false;
};
} else {
// polyfill
window.requestAnimationFrame = function( callback, element ) {
var currTime = new Date().getTime(),
timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) ),
id = window.setTimeout( function() {
callback( currTime + timeToCall );
}, timeToCall );
lastTime = currTime + timeToCall;
return id;
};

window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};

}

}));
6 changes: 3 additions & 3 deletions dist/jquery.requestAnimationFrame.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 3 additions & 33 deletions src/jquery.requestAnimationFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,16 @@
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating


var animating,
lastTime = 0,
vendors = ['webkit', 'moz'],
requestAnimationFrame = window.requestAnimationFrame,
cancelAnimationFrame = window.cancelAnimationFrame;

for(; lastTime < vendors.length && !requestAnimationFrame; lastTime++) {
requestAnimationFrame = window[ vendors[lastTime] + "RequestAnimationFrame" ];
cancelAnimationFrame = cancelAnimationFrame ||
window[ vendors[lastTime] + "CancelAnimationFrame" ] ||
window[ vendors[lastTime] + "CancelRequestAnimationFrame" ];
}
var animating;

function raf() {
if ( animating ) {
requestAnimationFrame( raf );
window.requestAnimationFrame( raf );
jQuery.fx.tick();
}
}

if ( requestAnimationFrame ) {
// use rAF
window.requestAnimationFrame = requestAnimationFrame;
window.cancelAnimationFrame = cancelAnimationFrame;
if ( window.requestAnimationFrame ) {
jQuery.fx.timer = function( timer ) {
if ( timer() && jQuery.timers.push( timer ) && !animating ) {
animating = true;
Expand All @@ -57,22 +43,6 @@ if ( requestAnimationFrame ) {
jQuery.fx.stop = function() {
animating = false;
};
} else {
// polyfill
window.requestAnimationFrame = function( callback, element ) {
var currTime = new Date().getTime(),
timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) ),
id = window.setTimeout( function() {
callback( currTime + timeToCall );
}, timeToCall );
lastTime = currTime + timeToCall;
return id;
};

window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};

}

}));