[Pkg-javascript-commits] [sockjs-client] 383/434: #57 - Trigger cleanup also onbeforeunload, don't set iframe.src.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:27 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 99c36c4cea5b4eb2b2ffaf57bbcff3c0cc08466c
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Fri Apr 13 16:06:59 2012 +0100

    #57 - Trigger cleanup also onbeforeunload, don't set iframe.src.
    
    This is done o fight opera's habit not to fire onunload.
---
 lib/dom.js                     | 26 +++++++++-----------------
 tests/html/src/domtests.coffee | 12 +++++++++---
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/lib/dom.js b/lib/dom.js
index f813875..0863f21 100644
--- a/lib/dom.js
+++ b/lib/dom.js
@@ -58,14 +58,17 @@ var trigger_unload_callbacks = function() {
         delete on_unload[ref];
     };
 };
-// Onbeforeunload alone is not reliable.
-utils.attachEvent('beforeunload', function() {
-    after_unload = true;
-});
-utils.attachEvent('unload', function() {
+
+var unload_triggered = function() {
+    if(after_unload) return;
     after_unload = true;
     trigger_unload_callbacks();
-});
+};
+
+// Onbeforeunload alone is not reliable. We could use only 'unload'
+// but it's not working in opera within an iframe. Let's use both.
+utils.attachEvent('beforeunload', unload_triggered);
+utils.attachEvent('unload', unload_triggered);
 
 utils.unload_add = function(listener) {
     var ref = utils.random_string(8);
@@ -93,12 +96,6 @@ utils.createIframe = function (iframe_url, error_callback) {
     var cleanup = function() {
         if (iframe) {
             unattach();
-            // This is required, in order to force ie7 to fire the
-            // onunload event. Setting .src must happen before the
-            // removeChild step.
-            if('ActiveXObject' in _window) {
-                iframe.src = "about:blank";
-            }
             // This timeout makes chrome fire onbeforeunload event
             // within iframe. Without the timeout it goes straight to
             // onunload.
@@ -158,11 +155,6 @@ utils.createHtmlfile = function (iframe_url, error_callback) {
         if (doc) {
             unattach();
             utils.unload_del(unload_ref);
-            if('ActiveXObject' in _window) {
-                try {
-                    iframe.src = "about:blank";
-                } catch (x) {}
-            }
             iframe.parentNode.removeChild(iframe);
             iframe = doc = null;
             CollectGarbage();
diff --git a/tests/html/src/domtests.coffee b/tests/html/src/domtests.coffee
index 29ec0fe..bfbe802 100644
--- a/tests/html/src/domtests.coffee
+++ b/tests/html/src/domtests.coffee
@@ -37,9 +37,15 @@ else
                     u.attachEvent('load', function(){
                         hook.load();
                     });
-                    u.attachEvent('unload', function(){
-                        hook.unload();
-                    });
+                    var w = 0;
+                    var run = function(){
+                        if(w === 0) {
+                            w = 1;
+                            hook.unload();
+                        }
+                    };
+                    u.attachEvent('beforeunload', run);
+                    u.attachEvent('unload', run);
                 """))
 
 # if navigator.userAgent.indexOf('Konqueror') isnt -1 or $.browser.opera

-- 
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