[Pkg-javascript-commits] [sockjs-client] 289/434: Drop old ajax creation methods, copy over some comments to new code.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:20 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 191fd7b8ca952530cf59aa865778767ed4390227
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Wed Jan 11 16:28:54 2012 +0000

    Drop old ajax creation methods, copy over some comments to new code.
---
 lib/dom.js  | 131 ------------------------------------------------------------
 lib/dom2.js |   6 +++
 2 files changed, 6 insertions(+), 131 deletions(-)

diff --git a/lib/dom.js b/lib/dom.js
index 0fd959d..0157265 100644
--- a/lib/dom.js
+++ b/lib/dom.js
@@ -64,137 +64,6 @@ utils.attachEvent('unload', function() {
     };
 });
 
-// Try to clear some headers, in order to save bandwidth. For
-// reference see:
-//   http://blog.mibbit.com/?p=143
-//   http://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest
-var xhrDefaultHeaders = {
-    "User-Agent": '',
-    "Accept": '',
-    "Accept-Language": '',
-    "Content-Type": "text/plain;charset=UTF-8"
-};
-
-if (navigator &&
-    (navigator.userAgent.indexOf('Chrome')!= -1 ||
-     navigator.userAgent.indexOf('Safari') != -1)) {
-    delete xhrDefaultHeaders['User-Agent'];
-}
-
-// References:
-//   http://ajaxian.com/archives/100-line-ajax-wrapper
-//   http://msdn.microsoft.com/en-us/library/cc288060(v=VS.85).aspx
-utils.createXDR = function(method, url, payload, callback) {
-    var mock_xhr = {status: null, responseText:'', readyState:1};
-    var xdr = new XDomainRequest();
-    // IE caches even POSTs
-    url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+utils.random_string(8);
-    var cleanup = function() {
-        if (xdr) {
-            onerror = xdr.onerror = xdr.ontimeout = xdr.onprogress =
-                xdr.onload = null;
-            try {
-                xdr.abort();
-            } catch (x) {}
-            xdr = callback = null;
-        }
-    };
-    var onerror = xdr.ontimeout = xdr.onerror = function() {
-        mock_xhr.status = 500;
-        mock_xhr.readyState = 4;
-        callback(mock_xhr);
-        cleanup();
-    };
-    xdr.onload = function() {
-        mock_xhr.status = 200;
-        mock_xhr.readyState = 4;
-        mock_xhr.responseText = xdr.responseText;
-        callback(mock_xhr);
-        cleanup();
-    };
-    xdr.onprogress = function() {
-        mock_xhr.status = 200;
-        mock_xhr.readyState = 3;
-        mock_xhr.responseText = xdr.responseText;
-        callback(mock_xhr);
-    };
-    try {
-        // Fails with AccessDenied if port number is bogus
-        xdr.open(method, url);
-        xdr.send(payload);
-    } catch (x) {
-        utils.delay(onerror);
-    }
-    return function (abort_reason) {
-        if (callback) {
-            callback(mock_xhr, null, abort_reason);
-            cleanup();
-        }
-    };
-};
-
-utils.createXHR = function(method, url, payload, callback) {
-    var xhr;
-    if (_window.ActiveXObject) {
-        // IE caches POSTs
-        url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+(+new Date);
-        try {
-            xhr = new ActiveXObject('Microsoft.XMLHTTP');
-        } catch(x) {}
-    }
-    if (!xhr) {
-        xhr = new XMLHttpRequest();
-    }
-    xhr.open(method, url, true);
-
-    for (var k in xhrDefaultHeaders) {
-        try {
-            xhr.setRequestHeader(k, xhrDefaultHeaders[k]);
-        } catch(x) {
-            delete xhrDefaultHeaders[k];
-        }
-    }
-    if ('withCredentials' in xhr) {
-        // Set cookies on CORS, please.
-        xhr.withCredentials = "true";
-    }
-
-    var cleanup = function() {
-        if (xhr) {
-            // IE needs this field to be a function
-            try {
-                xhr.onreadystatechange = null;
-            } catch (x) {
-                xhr.onreadystatechange = function(){};
-            }
-            // Explorer tends to keep connection open, even after the
-            // tab gets closed: http://bugs.jquery.com/ticket/5280
-            try {
-                xhr.abort();
-            } catch(e) {};
-            utils.detachEvent('unload', cleanup);
-        }
-        callback = xhr = null;
-    };
-
-    xhr.onreadystatechange = function (e) {
-        if (xhr && callback) {
-            callback(xhr, e);
-            if (xhr && xhr.readyState === 4) {
-                cleanup();
-            }
-        }
-    };
-    xhr.send(payload);
-    utils.attachEvent('unload', cleanup);
-    return function (abort_reason) {
-        if (callback) {
-            callback(xhr, null, abort_reason);
-            cleanup();
-        }
-    };
-};
-
 utils.createIframe = function (iframe_url, error_callback) {
     var iframe = _document.createElement('iframe');
     var tref;
diff --git a/lib/dom2.js b/lib/dom2.js
index 56108a1..996308f 100644
--- a/lib/dom2.js
+++ b/lib/dom2.js
@@ -17,6 +17,9 @@ XHRObject.prototype._start = function(method, url, payload) {
     if (!that.xhr) {
         that.xhr = new XMLHttpRequest();
     }
+
+    // Explorer tends to keep connection open, even after the
+    // tab gets closed: http://bugs.jquery.com/ticket/5280
     that.unload_ref = utils.unload_add(function(){that._cleanup(true);});
     try {
         that.xhr.open(method, url, true);
@@ -77,6 +80,9 @@ XHRObject.prototype.close = function() {
 };
 
 
+// References:
+//   http://ajaxian.com/archives/100-line-ajax-wrapper
+//   http://msdn.microsoft.com/en-us/library/cc288060(v=VS.85).aspx
 var XDRObject = utils.XDRObject = function(method, url, payload) {
     var that = this;
     utils.delay(function(){that._start(method, url, payload);});

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