From 30a11ee4cbdbe667b862be4f2f698592c5cc8548 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Tue, 5 Jan 2016 13:05:32 -0800 Subject: [PATCH] fix(animationFrame): req/cancel animationFrame has to be called within the context of root. --- src/util/AnimationFrame.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/util/AnimationFrame.ts b/src/util/AnimationFrame.ts index 4d7af194a7..d73ba95763 100644 --- a/src/util/AnimationFrame.ts +++ b/src/util/AnimationFrame.ts @@ -5,22 +5,22 @@ export class RequestAnimationFrameDefinition { requestAnimationFrame: (cb: () => void) => number; constructor(root: any) { if (root.requestAnimationFrame) { - this.cancelAnimationFrame = root.cancelAnimationFrame; - this.requestAnimationFrame = root.requestAnimationFrame; + this.cancelAnimationFrame = root.cancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.requestAnimationFrame.bind(root); } else if (root.mozRequestAnimationFrame) { - this.cancelAnimationFrame = root.mozCancelAnimationFrame; - this.requestAnimationFrame = root.mozRequestAnimationFrame; + this.cancelAnimationFrame = root.mozCancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.mozRequestAnimationFrame.bind(root); } else if (root.webkitRequestAnimationFrame) { - this.cancelAnimationFrame = root.webkitCancelAnimationFrame; - this.requestAnimationFrame = root.webkitRequestAnimationFrame; + this.cancelAnimationFrame = root.webkitCancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.webkitRequestAnimationFrame.bind(root); } else if (root.msRequestAnimationFrame) { - this.cancelAnimationFrame = root.msCancelAnimationFrame; - this.requestAnimationFrame = root.msRequestAnimationFrame; + this.cancelAnimationFrame = root.msCancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.msRequestAnimationFrame.bind(root); } else if (root.oRequestAnimationFrame) { - this.cancelAnimationFrame = root.oCancelAnimationFrame; - this.requestAnimationFrame = root.oRequestAnimationFrame; + this.cancelAnimationFrame = root.oCancelAnimationFrame.bind(root); + this.requestAnimationFrame = root.oRequestAnimationFrame.bind(root); } else { - this.cancelAnimationFrame = root.clearTimeout; + this.cancelAnimationFrame = root.clearTimeout.bind(root); this.requestAnimationFrame = function(cb) { return root.setTimeout(cb, 1000 / 60); }; } }