Skip to content

Commit 5c03c8d

Browse files
committed
Add rAF polyfill
1 parent 2372893 commit 5c03c8d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

js/theme.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,33 @@ module.exports.ThemeNav = ThemeNav();
171171
if (typeof(window) != 'undefined') {
172172
window.SphinxRtdTheme = { StickyNav: module.exports.ThemeNav };
173173
}
174+
175+
176+
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
177+
// https://gist.github.com/paulirish/1579671
178+
// MIT license
179+
180+
(function() {
181+
var lastTime = 0;
182+
var vendors = ['ms', 'moz', 'webkit', 'o'];
183+
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
184+
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
185+
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
186+
|| window[vendors[x]+'CancelRequestAnimationFrame'];
187+
}
188+
189+
if (!window.requestAnimationFrame)
190+
window.requestAnimationFrame = function(callback, element) {
191+
var currTime = new Date().getTime();
192+
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
193+
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
194+
timeToCall);
195+
lastTime = currTime + timeToCall;
196+
return id;
197+
};
198+
199+
if (!window.cancelAnimationFrame)
200+
window.cancelAnimationFrame = function(id) {
201+
clearTimeout(id);
202+
};
203+
}());

0 commit comments

Comments
 (0)