[Pkg-javascript-commits] [sockjs-client] 365/434: #28 - Handle onunload / onbeforeunload more robustly.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:25 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository sockjs-client.
commit 8e97a4e82911a1aa358ca090867f467948cf756c
Author: Marek Majkowski <majek04 at gmail.com>
Date: Wed Mar 14 17:39:03 2012 +0000
#28 - Handle onunload / onbeforeunload more robustly.
---
lib/dom.js | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/lib/dom.js b/lib/dom.js
index 900590e..011d8d9 100644
--- a/lib/dom.js
+++ b/lib/dom.js
@@ -47,10 +47,32 @@ utils.detachEvent = function(event, listener) {
}
};
+
var on_unload = {};
+// Things registered after beforeunload are to be called immediately.
+var after_unload = false;
+
+var trigger_unload_callbacks = function() {
+ for(var ref in on_unload) {
+ on_unload[ref]();
+ delete on_unload[ref];
+ };
+};
+// Onbeforeunload alone is not reliable.
+utils.attachEvent('beforeunload', function() {
+ after_unload = true;
+});
+utils.attachEvent('unload', function() {
+ after_unload = true;
+ trigger_unload_callbacks();
+});
+
utils.unload_add = function(listener) {
var ref = utils.random_string(8);
on_unload[ref] = listener;
+ if (after_unload) {
+ utils.delay(trigger_unload_callbacks);
+ }
return ref;
};
utils.unload_del = function(ref) {
@@ -58,11 +80,6 @@ utils.unload_del = function(ref) {
delete on_unload[ref];
};
-utils.attachEvent('unload', function() {
- for(var k in on_unload) {
- on_unload[k]();
- };
-});
utils.createIframe = function (iframe_url, error_callback) {
var iframe = _document.createElement('iframe');
--
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