From 8f53c564dab2858e9acd5faa747a5566a58edd0b Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 23 May 2013 09:48:38 -0700 Subject: [PATCH 1/3] Our requestAnimationFrame no longer changes the global window object --- src/openseadragon.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index c0586583..57828044 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1644,33 +1644,31 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ }; - // Adding support for HTML5's requestAnimationFrame as suggested by acdha - // implementation taken from matt synders post here:s + // Adding support for HTML5's requestAnimationFrame as suggested by acdha. + // Implementation taken from matt synder's post here: // http://mattsnider.com/cross-browser-and-legacy-supported-requestframeanimation/ (function( w ) { // most browsers have an implementation - w.requestAnimationFrame = w.requestAnimationFrame || + var requestAnimationFrame = w.requestAnimationFrame || w.mozRequestAnimationFrame || w.webkitRequestAnimationFrame || w.msRequestAnimationFrame; - w.cancelAnimationFrame = w.cancelAnimationFrame || + var cancelAnimationFrame = w.cancelAnimationFrame || w.mozCancelAnimationFrame || w.webkitCancelAnimationFrame || w.msCancelAnimationFrame; - // polyfill, when necessary - if ( w.requestAnimationFrame && w.cancelAnimationFrame ) { - //we cant assign window.requestAnimationFrame directly to $.requestAnimationFrame - //without getting Illegal Invocation errors in webkit so call in a - //wrapper - $.requestAnimationFrame = function( callback ){ - return w.requestAnimationFrame( callback ); + if ( requestAnimationFrame && cancelAnimationFrame ) { + // We can't assign these window methods directly to $ because they + // expect their "this" to be "window", so we call them in wrappers. + $.requestAnimationFrame = function(){ + return requestAnimationFrame.apply( w, arguments ); }; - $.cancelAnimationFrame = function( requestId ){ - return w.cancelAnimationFrame( requestId ); + $.cancelAnimationFrame = function(){ + return cancelAnimationFrame.apply( w, arguments ); }; } else { var aAnimQueue = [], From 1c60f90ee5ec6b5872b35749fc2b978862b7c3f0 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Thu, 23 May 2013 09:48:53 -0700 Subject: [PATCH 2/3] Tests for requestAnimationFrame and cancelAnimationFrame --- test/utils.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/utils.js b/test/utils.js index 3b7d6c49..7489f03b 100644 --- a/test/utils.js +++ b/test/utils.js @@ -62,4 +62,30 @@ }); }); + // ---------- + asyncTest("requestAnimationFrame", function() { + var timeWatcher = Util.timeWatcher(); + + OpenSeadragon.requestAnimationFrame(function() { + ok(true, 'frame fired'); + timeWatcher.done(); + }); + }); + + // ---------- + asyncTest("cancelAnimationFrame", function() { + var frameFired = false; + + setTimeout(function() { + strictEqual(frameFired, false, 'the frame never fired'); + start(); + }, 150); + + var frameId = OpenSeadragon.requestAnimationFrame(function() { + frameFired = true; + }); + + OpenSeadragon.cancelAnimationFrame(frameId); + }); + })(); From 8e37633c49acbc286b309ab84024539f3ff4ab42 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Fri, 24 May 2013 09:17:26 -0700 Subject: [PATCH 3/3] Whitespace nits --- src/openseadragon.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index 57828044..83f417fa 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1664,10 +1664,10 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ if ( requestAnimationFrame && cancelAnimationFrame ) { // We can't assign these window methods directly to $ because they // expect their "this" to be "window", so we call them in wrappers. - $.requestAnimationFrame = function(){ + $.requestAnimationFrame = function(){ return requestAnimationFrame.apply( w, arguments ); }; - $.cancelAnimationFrame = function(){ + $.cancelAnimationFrame = function(){ return cancelAnimationFrame.apply( w, arguments ); }; } else {