[Pkg-javascript-commits] [sockjs-client] 08/434: Error on script now works even for konqueror.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:46:57 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 20cf91d6aa6054db3ce9912769c3d7f52441609c
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Sat Jul 23 01:33:33 2011 +0100

    Error on script now works even for konqueror.
---
 lib/trans-jsonp.js | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/lib/trans-jsonp.js b/lib/trans-jsonp.js
index 5302d05..1e6523e 100644
--- a/lib/trans-jsonp.js
+++ b/lib/trans-jsonp.js
@@ -103,17 +103,19 @@ var jsonPGenericReceiver = function(url, callback) {
     var script = document.createElement('script');
     var script2;
     var close_script = function(v, t) {
-        if (typeof script2 !== 'undefined') {
-            script2.parentNode.removeChild(script2);
-            script2 = undefined;
-        }
-        if (typeof script !== 'undefined') {
-            callback(v, t);
-            script.parentNode.removeChild(script);
-            script.onreadystatechange = script.onerror = script.onload = script.onclick = null;
-            delete script;
-            script = callback = undefined;
-        }
+        setTimeout(function(){
+                       if (typeof script2 !== 'undefined') {
+                           script2.parentNode.removeChild(script2);
+                           script2 = undefined;
+                       }
+                       if (typeof script !== 'undefined') {
+                           callback(v, t);
+                           script.parentNode.removeChild(script);
+                           script.onreadystatechange = script.onerror = script.onload = script.onclick = null;
+                           delete script;
+                           script = callback = undefined;
+                       }
+                   }, 0);
     };
     script.id = 'a' + utils.random_string(8);
     script.src = url;
@@ -147,7 +149,9 @@ var jsonPGenericReceiver = function(url, callback) {
     // script object. Later, onreadystatechange, manually execute this
     // code. FF and Chrome doesn't work with 'event' and 'htmlFor'
     // set. For reference see:
-    // http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
+    //   http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
+    // Also, read on that about script ordering:
+    //   http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
     if (typeof script.async === 'undefined') {
         // According to mozilla docs, in recent browsers script.async defaults
         // to 'true', so we may use it to detect a good browser:
@@ -159,20 +163,26 @@ var jsonPGenericReceiver = function(url, callback) {
                 script.event = "onclick";
             } catch (x) {}
             script.async = true;
-            script.defer = true;
-        } else {
+        } else if (typeof document.attachEvent === 'function') {
             // opera
             script2 = document.createElement('script');
             script2.text = "try{document.getElementById('"+script.id+"').onerror();}catch(x){};";
+            script.async = script2.async = false;
+        } else {
+            // konqueror. fallback to a stupid timer, 5 seconds shall be plenty.
+            setTimeout(function(){
+                           if (script && script.onerror) {
+                               script.onerror();
+                           }
+                       }, 5000);
         }
     } else {
         script.async = true;
-        script.defer = true;
     }
 
     var head = document.getElementsByTagName('head')[0];
     head.insertBefore(script, head.firstChild);
-    if (script2) {
+    if (script2){
         head.insertBefore(script2, head.firstChild);
     }
     return close_script;

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