[Pkg-javascript-commits] [sockjs-client] 242/434: #15 Some transports require document.body to exist - wait for onload

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:16 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 038069a08be708414965c5b2d33cac871b090028
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Thu Dec 1 16:59:34 2011 +0000

    #15 Some transports require document.body to exist - wait for onload
    
    Some transports use document.body.appendChild. Thus, can be only used after onload event. For such transports we shall delay running them after onload event.
---
 lib/chunking-test.js            |  9 +++++++++
 lib/sockjs.js                   | 12 ++++++++++++
 lib/trans-iframe-eventsource.js |  1 +
 lib/trans-iframe-htmlfile.js    |  1 +
 lib/trans-iframe-xhr-polling.js |  2 ++
 lib/trans-jsonp-polling.js      |  3 +++
 6 files changed, 28 insertions(+)

diff --git a/lib/chunking-test.js b/lib/chunking-test.js
index 60ca84f..13007be 100644
--- a/lib/chunking-test.js
+++ b/lib/chunking-test.js
@@ -34,6 +34,15 @@ var chunkingTestUncached = SockJS.chunkingTest = function(base_url, callback, op
         doChunkingTest(base_url, callback, true);
         return;
     }
+    if(!_document.body) {
+        utils.attachEvent('load', function(){
+            chunkingTestWithBody(base_url, callback, options);
+        });
+    } else {
+        chunkingTestWithBody(base_url, callback, options);
+    }
+}
+var chunkingTestWithBody = function(base_url, callback, options) {
     // 2. Iframe
     if (IframeTransport.enabled()) {
         var ifr = new IframeTransport();
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 3adbbbc..5f7b7bd 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -166,6 +166,18 @@ SockJS.prototype._try_next_protocol = function(close_event) {
                          }, that._options);
             return true;
         }
+        // Some protocols require access to `body`, what if were in
+        // the `head`?
+        if (SockJS[protocol] &&
+            SockJS[protocol].need_body === true &&
+            !_document.body) {
+            that._protocols.unshift(protocol);
+            that.protocol = 'waiting-for-load';
+            utils.attachEvent('load', function(){
+                that._try_next_protocol();
+            });
+            return true;
+        }
 
         if (!SockJS[protocol] ||
               (SockJS[protocol].need_chunking === true &&
diff --git a/lib/trans-iframe-eventsource.js b/lib/trans-iframe-eventsource.js
index eaf691c..7b2e0e9 100644
--- a/lib/trans-iframe-eventsource.js
+++ b/lib/trans-iframe-eventsource.js
@@ -12,6 +12,7 @@ EventSourceIframeTransport.enabled = function () {
 };
 
 EventSourceIframeTransport.need_chunking = true;
+EventSourceIframeTransport.need_body = true;
 
 
 var EventSourceTransport = FacadeJS['w-iframe-eventsource'] = function (ri, trans_url) {
diff --git a/lib/trans-iframe-htmlfile.js b/lib/trans-iframe-htmlfile.js
index cf648c1..7348d4a 100644
--- a/lib/trans-iframe-htmlfile.js
+++ b/lib/trans-iframe-htmlfile.js
@@ -19,6 +19,7 @@ HtmlFileIframeTransport.enabled = function (options) {
 };
 
 HtmlFileIframeTransport.need_chunking = true;
+HtmlFileIframeTransport.need_body = true;
 
 
 var HtmlFileTransport = FacadeJS['w-iframe-htmlfile'] = function (ri, trans_url) {
diff --git a/lib/trans-iframe-xhr-polling.js b/lib/trans-iframe-xhr-polling.js
index 06ec114..412ea59 100644
--- a/lib/trans-iframe-xhr-polling.js
+++ b/lib/trans-iframe-xhr-polling.js
@@ -11,6 +11,8 @@ XhrPollingIframeTransport.enabled = function () {
     return window.XMLHttpRequest && IframeTransport.enabled();
 };
 
+XhrPollingIframeTransport.need_body = true;
+
 
 var XhrPollingITransport = FacadeJS['w-iframe-xhr-polling'] = function (ri, trans_url) {
     var that = this;
diff --git a/lib/trans-jsonp-polling.js b/lib/trans-jsonp-polling.js
index 29e9976..89635cc 100644
--- a/lib/trans-jsonp-polling.js
+++ b/lib/trans-jsonp-polling.js
@@ -42,6 +42,9 @@ JsonPTransport.enabled = function() {
     return true;
 };
 
+JsonPTransport.need_body = true;
+
+
 JsonPTransport.prototype.doCleanup = function() {
     var that = this;
     that._is_closing = true;

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