Skip to content

Commit

Permalink
Merge pull request gabrielecirulli#115 from iirelu/jshint-compliance
Browse files Browse the repository at this point in the history
Made animframe_polyfill.js JSHint compliant
  • Loading branch information
gabrielecirulli committed Mar 27, 2014
2 parents 878098f + 82834df commit 2798bb0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions js/animframe_polyfill.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
(function() {
(function () {
var lastTime = 0;
var vendors = ['webkit', 'moz'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame =
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
window[vendors[x] + 'CancelRequestAnimationFrame'];
}

if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(callback, element) {
window.requestAnimationFrame = function (callback) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
var id = window.setTimeout(function () {
callback(currTime + timeToCall);
},
timeToCall);
lastTime = currTime + timeToCall;
return id;
};
}

if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
window.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
}
Expand Down

0 comments on commit 2798bb0

Please sign in to comment.