Skip to content

Commit 0dd3b41

Browse files
committed
Merge pull request #83 from Khan/requestanimationframe
Provide fallback for requestAnimationFrame on IE 9 - Fixes #82
2 parents 78af627 + 8d0aa4f commit 0dd3b41

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

plugins/shared/annotate/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ require("./style.less");
2020
// and across.
2121
const MIN_HIGHLIGHT_SIZE = 25;
2222

23+
// Polyfill fallback for IE < 10
24+
window.requestAnimationFrame = window.requestAnimationFrame ||
25+
function(callback) {
26+
window.setTimeout(callback, 16);
27+
};
28+
2329
module.exports = (namespace) => {
2430
// The class that will be applied to any annotation generated in this
2531
// namespace
@@ -65,15 +71,14 @@ module.exports = (namespace) => {
6571
// Mount all annotations to the DOM in sequence. This is done by
6672
// picking items off the queue, where each item consists of the
6773
// annotation and the node to which we'll append it.
68-
function render() {
74+
(function loop() {
6975
for (let i = 0; queue.length > 0 && i < RENDER_CHUNK_SIZE; i++) {
7076
let item = queue.shift();
7177
item.$parent.append(item.$annotation);
7278
}
7379

74-
window.requestAnimationFrame(render);
75-
}
76-
window.requestAnimationFrame(render);
80+
window.requestAnimationFrame(loop);
81+
})();
7782

7883
// Handle resizes by repositioning all annotations in bulk
7984
$(window).resize(() => {

0 commit comments

Comments
 (0)