Skip to content

Commit

Permalink
Provide fallback for window.requestAnimationFrame on IE 9 and under - F…
Browse files Browse the repository at this point in the history
…ixes #82

Test plan:
* On line 70 of `annotate/index.js`, set window.requestAnimationFrame to `null`
* `npm run live-test`
* http://localhost:8080/test
* Activate the alt-text plugin
* Verify that errors pop up
  • Loading branch information
jdan committed Nov 23, 2015
1 parent 78af627 commit 8d0aa4f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugins/shared/annotate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ require("./style.less");
// and across.
const MIN_HIGHLIGHT_SIZE = 25;

// Polyfill fallback for IE < 10
window.requestAnimationFrame = window.requestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 16);
};

module.exports = (namespace) => {
// The class that will be applied to any annotation generated in this
// namespace
Expand Down Expand Up @@ -65,15 +71,14 @@ module.exports = (namespace) => {
// Mount all annotations to the DOM in sequence. This is done by
// picking items off the queue, where each item consists of the
// annotation and the node to which we'll append it.
function render() {
(function loop() {
for (let i = 0; queue.length > 0 && i < RENDER_CHUNK_SIZE; i++) {
let item = queue.shift();
item.$parent.append(item.$annotation);
}

window.requestAnimationFrame(render);
}
window.requestAnimationFrame(render);
window.requestAnimationFrame(loop);
})();

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

0 comments on commit 8d0aa4f

Please sign in to comment.