Skip to content
Merged
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
59 changes: 36 additions & 23 deletions dist/extras/request_animation_frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,41 @@

// MIT license

(function(){

'use strict';

'use strict';

if(!Date.now) {
Date.now = function() { return new Date().getTime(); };
}

var vendors = ['webkit', 'moz'];
for(var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
var vp = vendors[i];
window.requestAnimationFrame = window[vp + 'RequestAnimationFrame'];
window.cancelAnimationFrame = (window[vp + 'CancelAnimationFrame'] ||
window[vp + 'CancelRequestAnimationFrame']);
}
if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || // iOS6 is buggy
!window.requestAnimationFrame || !window.cancelAnimationFrame) {
if(!Date.now) {
Date.now = function() { return (new Date()).getTime(); };
}

var vendors = ['webkit', 'moz'];
var i = 0;
var l = vendors.length;
var vp;
var lastTime = 0;
window.requestAnimationFrame = function(callback) {
var now = Date.now();
var nextTime = Math.max(lastTime + 16, now);
return setTimeout(function() { callback(lastTime = nextTime); },
nextTime - now);
};
window.cancelAnimationFrame = clearTimeout;
}

for(; i < l && !window.requestAnimationFrame; ++i) {
vp = vendors[i];
window.requestAnimationFrame = window[vp + 'RequestAnimationFrame'];
window.cancelAnimationFrame = (window[vp + 'CancelAnimationFrame'] ||
window[vp + 'CancelRequestAnimationFrame']);
}

if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || // iOS6 is buggy
!window.requestAnimationFrame || !window.cancelAnimationFrame) {
window.requestAnimationFrame = function(callback) {
var now = Date.now();
var nextTime = Math.max(lastTime + 16, now);
return setTimeout(function() { callback(lastTime = nextTime); },
nextTime - now);
};
window.cancelAnimationFrame = clearTimeout;
}

vendors = null;
i = null;
l = null;
vp = null;

}());