X Tutup
Skip to content

Commit 9679fc9

Browse files
mgoltbosch
authored andcommitted
fix(shims): Don't rely on prefixed requestAnimationFrame
The `ms` & `moz` prefixes are not needed. `ms` was never available in a public IE release (IE 10 has an unprefixed version) and Firefox has unprefixed rAF since v24 - current version is 41. Even more, Firefox versions below 22 don't have cancelAnimationFrame so it's better to not use the prefixed version at all to avoid surprises. The `o` prefix is also useless - Opera Presto never had rAF and the Chromium-based Opera doesn't use the `o` prefix. Also, switched from `new Date().getTime()` to `Date.now()` as it's supported everywhere (even in Android 2.3) except IE<9 and it avoids a useless date object construction. See http://caniuse.com/#feat=requestanimationframe for more info. Refs 4f56a01 Closes #4394
1 parent 076191c commit 9679fc9

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

modules/angular2/src/test_lib/shims_for_IE.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,17 @@ if (!window.console.assert) window.console.assert = function () { };
112112

113113
(function() {
114114
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-
115+
122116
if (!window.requestAnimationFrame)
123117
window.requestAnimationFrame = function(callback, element) {
124-
var currTime = new Date().getTime();
118+
var currTime = Date.now();
125119
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
126-
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
120+
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
127121
timeToCall);
128122
lastTime = currTime + timeToCall;
129123
return id;
130124
};
131-
125+
132126
if (!window.cancelAnimationFrame)
133127
window.cancelAnimationFrame = function(id) {
134128
clearTimeout(id);

0 commit comments

Comments
 (0)
X Tutup