From d7f1af47e230f22db8b742766044eb544152236d Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Mon, 4 Sep 2017 17:59:35 -0500 Subject: [PATCH] Fix global var issue --- game-client.js | 12 ++++++++++-- player-client.js | 12 ++++++++++-- public/bundle.js | 24 ++++++++++++++++++++---- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/game-client.js b/game-client.js index b05837d..267d7a7 100644 --- a/game-client.js +++ b/game-client.js @@ -16,10 +16,18 @@ client.renderer = require("./game-renderer.js"); // window.requestAnimationFrame = function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { // window.setTimeout( callback, 1000 / 60 ); // }; -var window, requestAnimationFrame; +var hasWindow; +try { + window.document; + hasWindow = true; +} catch (e) { + hasWindow = false; +} + +var requestAnimationFrame; if ( !requestAnimationFrame ) { requestAnimationFrame = ( function() { - if (window) { + if (hasWindow) { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || diff --git a/player-client.js b/player-client.js index f4b8a99..759b19a 100644 --- a/player-client.js +++ b/player-client.js @@ -33,10 +33,18 @@ var grid = new Grid(consts.GRID_SIZE, function(row, col, before, after) { // window.setTimeout( callback, 1000 / 60 ); // }; -var window, requestAnimationFrame; +var hasWindow; +try { + window.document; + hasWindow = true; +} catch (e) { + hasWindow = false; +} + +var requestAnimationFrame; if ( !requestAnimationFrame ) { requestAnimationFrame = ( function() { - if (window) { + if (hasWindow) { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || diff --git a/public/bundle.js b/public/bundle.js index cf0531c..7c709c8 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -118,10 +118,18 @@ client.renderer = require("./game-renderer.js"); // window.requestAnimationFrame = function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { // window.setTimeout( callback, 1000 / 60 ); // }; -var window, requestAnimationFrame; +var hasWindow; +try { + window.document; + hasWindow = true; +} catch (e) { + hasWindow = false; +} + +var requestAnimationFrame; if ( !requestAnimationFrame ) { requestAnimationFrame = ( function() { - if (window) { + if (hasWindow) { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || @@ -8687,10 +8695,18 @@ var grid = new Grid(consts.GRID_SIZE, function(row, col, before, after) { // window.setTimeout( callback, 1000 / 60 ); // }; -var window, requestAnimationFrame; +var hasWindow; +try { + window.document; + hasWindow = true; +} catch (e) { + hasWindow = false; +} + +var requestAnimationFrame; if ( !requestAnimationFrame ) { requestAnimationFrame = ( function() { - if (window) { + if (hasWindow) { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame ||