Skip to content

Commit 4f56a01

Browse files
committed
fix(shims): add requestAnimationFrame shim for IE9 and Android
Fixes #4209
1 parent 29f75c3 commit 4f56a01

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎modules/angular2/src/test_lib/shims_for_IE.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,38 @@ if (!window.console.log) window.console.log = function () { };
9999
if (!window.console.error) window.console.error = function () { };
100100
if (!window.console.warn) window.console.warn = function () { };
101101
if (!window.console.assert) window.console.assert = function () { };
102+
103+
//RequestAnimationFrame (IE9, Android 4.1, 4.2, 4.3)
104+
/*! @author Paul Irish */
105+
/*! @source https://gist.github.com/paulirish/1579671 */
106+
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
107+
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
108+
109+
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
110+
111+
// MIT license
112+
113+
(function() {
114+
var lastTime = 0;
115+
var vendors = ['ms', 'moz', 'webkit', 'o'];
116+
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
117+
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
118+
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
119+
|| window[vendors[x]+'CancelRequestAnimationFrame'];
120+
}
121+
122+
if (!window.requestAnimationFrame)
123+
window.requestAnimationFrame = function(callback, element) {
124+
var currTime = new Date().getTime();
125+
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
126+
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
127+
timeToCall);
128+
lastTime = currTime + timeToCall;
129+
return id;
130+
};
131+
132+
if (!window.cancelAnimationFrame)
133+
window.cancelAnimationFrame = function(id) {
134+
clearTimeout(id);
135+
};
136+
}());

0 commit comments

Comments
 (0)