From 4d10ba29a9ced368f66796b9201abf13a0b68245 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Tue, 15 Jul 2014 11:36:53 -0400 Subject: [PATCH] Use global vs. window for browserify resolution of global object, fixes shared watch events in Intercom --- lib/intercom.js | 8 ++++---- tests/lib/websql.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/intercom.js b/lib/intercom.js index b16b9b5..1d2151c 100644 --- a/lib/intercom.js +++ b/lib/intercom.js @@ -38,7 +38,7 @@ var localStorage = (function(window) { }; } return window.localStorage; -}(this)); +}(global)); function Intercom() { var self = this; @@ -54,14 +54,14 @@ function Intercom() { }; // If we're in node.js, skip event registration - if (typeof window === 'undefined' || typeof document === 'undefined') { + if (typeof document === 'undefined') { return; } if (document.attachEvent) { document.attachEvent('onstorage', storageHandler); } else { - window.addEventListener('storage', storageHandler, false); + global.addEventListener('storage', storageHandler, false); } } @@ -192,7 +192,7 @@ Intercom.prototype._localStorageChanged = function(event, field) { }; Intercom.prototype._onStorageEvent = function(event) { - event = event || window.event; + event = event || global.event; var self = this; if (this._localStorageChanged(event, INDEX_EMIT)) { diff --git a/tests/lib/websql.js b/tests/lib/websql.js index af3bdd8..9a02dcd 100644 --- a/tests/lib/websql.js +++ b/tests/lib/websql.js @@ -2,7 +2,7 @@ var Filer = require('../..'); var needsCleanup = []; if(global.addEventListener) { - window.addEventListener('beforeunload', function() { + global.addEventListener('beforeunload', function() { needsCleanup.forEach(function(f) { f(); }); }); }