From e1945924034d66480d320f8b93f3366beacc98c5 Mon Sep 17 00:00:00 2001 From: Max New Date: Wed, 22 Jan 2014 20:24:03 -0600 Subject: [PATCH] Better window workaround. Thanks @raynos --- runtime/Utils.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/Utils.js b/runtime/Utils.js index 581c038..e95fb19 100644 --- a/runtime/Utils.js +++ b/runtime/Utils.js @@ -34,18 +34,18 @@ ElmRuntime.filterDeadInputs = function(inputs) { // define the draw function var vendors = ['ms', 'moz', 'webkit', 'o']; -var window = window || {}; -for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { - window.requestAnimationFrame = window[vendors[i]+'RequestAnimationFrame']; - window.cancelAnimationFrame = window[vendors[i]+'CancelAnimationFrame'] || - window[vendors[i]+'CancelRequestAnimationFrame']; +var win = typeof window !== 'undefined' ? window : {}; +for (var i = 0; i < vendors.length && !win.requestAnimationFrame; ++i) { + win.requestAnimationFrame = win[vendors[i]+'RequestAnimationFrame']; + win.cancelAnimationFrame = win[vendors[i]+'CancelAnimationFrame'] || + win[vendors[i]+'CancelRequestAnimationFrame']; } -if (window.requestAnimationFrame && window.cancelAnimationFrame) { +if (win.requestAnimationFrame && win.cancelAnimationFrame) { var previous = 0; ElmRuntime.draw = function(callback) { - window.cancelAnimationFrame(previous); - previous = window.requestAnimationFrame(callback); + win.cancelAnimationFrame(previous); + previous = win.requestAnimationFrame(callback); }; } else { ElmRuntime.draw = function(callback) { callback(); };