[Pkg-javascript-commits] [sockjs-client] 124/350: Re-enable unload events

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:03:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit 4ed8d3b2bfc1fe0bb3019768e5e7745d031afe35
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Mon Oct 13 11:11:43 2014 -0400

    Re-enable unload events
---
 lib/transport/facade/info-receiver-iframe.js |  2 +-
 lib/utils/event.js                           | 44 +++++++++++++---------------
 2 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/lib/transport/facade/info-receiver-iframe.js b/lib/transport/facade/info-receiver-iframe.js
index 4800831..9a83e15 100644
--- a/lib/transport/facade/info-receiver-iframe.js
+++ b/lib/transport/facade/info-receiver-iframe.js
@@ -13,7 +13,7 @@ function WInfoReceiverIframe(transUrl, baseUrl) {
 
   var ir = new InfoReceiver(baseUrl, XHRLocalObject);
   ir.once('finish', function(info, rtt) {
-    self.emit('message', JSON3.stringify([info, rtt]) );
+    self.emit('message', JSON3.stringify([info, rtt]));
   });
 }
 
diff --git a/lib/utils/event.js b/lib/utils/event.js
index 9ae85d4..aa54af4 100644
--- a/lib/utils/event.js
+++ b/lib/utils/event.js
@@ -2,6 +2,10 @@
 
 var random = require('./random');
 
+var onUnload = {}
+  , afterUnload = false
+  ;
+
 module.exports = {
   attachMessage: function(listener) {
     this.attachEvent('message', listener);
@@ -10,7 +14,7 @@ module.exports = {
 , attachEvent: function(event, listener) {
     if (typeof global.addEventListener !== 'undefined') {
       global.addEventListener(event, listener, false);
-    } else {
+    } else if (global.document && global.attachEvent) {
       // IE quirks.
       // According to: http://stevesouders.com/misc/test-postmessage.php
       // the message gets delivered only to 'document', not 'window'.
@@ -27,49 +31,43 @@ module.exports = {
 , detachEvent: function(event, listener) {
     if (typeof global.addEventListener !== 'undefined') {
       global.removeEventListener(event, listener, false);
-    } else {
+    } else if (global.document && global.detachEvent) {
       global.document.detachEvent('on' + event, listener);
       global.detachEvent('on' + event, listener);
     }
   }
 
-, onUnload: {}
-// Things registered after beforeunload are to be called immediately.
-, afterUnload: false
-
 , unloadAdd: function(listener) {
     var ref = random.string(8);
-    this.onUnload[ref] = listener;
-    if (this.afterUnload) {
+    onUnload[ref] = listener;
+    if (afterUnload) {
       process.nextTick(this.triggerUnloadCallbacks);
     }
     return ref;
   }
 
 , unloadDel: function(ref) {
-    if (ref in this.onUnload) {
-      delete this.onUnload[ref];
+    if (ref in onUnload) {
+      delete onUnload[ref];
     }
   }
 
 , triggerUnloadCallbacks: function() {
-    for(var ref in this.onUnload) {
-      this.onUnload[ref]();
-      delete this.onUnload[ref];
+    for (var ref in onUnload) {
+      onUnload[ref]();
+      delete onUnload[ref];
     }
   }
 };
 
-// var unloadTriggered = function() {
-//   if (afterUnload) {
-//     return;
-//   }
-//   afterUnload = true;
-//   triggerUnloadCallbacks();
-// };
+var unloadTriggered = function() {
+  if (afterUnload) {
+    return;
+  }
+  afterUnload = true;
+  module.exports.triggerUnloadCallbacks();
+};
 
 // 'unload' alone is not reliable in opera within an iframe, but we
 // can't use `beforeunload` as IE fires it on javascript: links.
-
-// TODO see if we need to uncomment this
-//utils.attachEvent('unload', unloadTriggered);
+module.exports.attachEvent('unload', unloadTriggered);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list