[Pkg-javascript-commits] [sockjs-client] 225/434: Move functions requiring dom from utils.js to dom.js
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:15 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 9ec3c653b5b33b5e0c58b6e34eaf9de8267fe77e
Author: Marek Majkowski <majek04 at gmail.com>
Date: Mon Nov 28 17:43:49 2011 +0000
Move functions requiring dom from utils.js to dom.js
In order to improve tests.
---
lib/dom.js | 248 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/index.js | 1 +
lib/utils.js | 250 -----------------------------------------------------------
3 files changed, 249 insertions(+), 250 deletions(-)
diff --git a/lib/dom.js b/lib/dom.js
new file mode 100644
index 0000000..8d56596
--- /dev/null
+++ b/lib/dom.js
@@ -0,0 +1,248 @@
+utils.attachMessage = function(listener) {
+ utils.attachEvent('message', listener);
+};
+utils.attachEvent = function(event, listener) {
+ if (typeof _window.addEventListener !== 'undefined') {
+ _window.addEventListener(event, listener, false);
+ } else {
+ // IE quirks.
+ // According to: http://stevesouders.com/misc/test-postmessage.php
+ // the message gets delivered only to 'document', not 'window'.
+ _document.attachEvent("on" + event, listener);
+ // I get 'window' for ie8.
+ _window.attachEvent("on" + event, listener);
+ }
+};
+
+utils.detachMessage = function(listener) {
+ utils.detachEvent('message', listener);
+};
+utils.detachEvent = function(event, listener) {
+ if (typeof _window.addEventListener !== 'undefined') {
+ _window.removeEventListener(event, listener, false);
+ } else {
+ _document.detachEvent("on" + event, listener);
+ _window.detachEvent("on" + event, listener);
+ }
+};
+
+// 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;
+ var unattach = function() {
+ clearTimeout(tref);
+ // Explorer had problems with that.
+ try {iframe.onload = null;} catch (x) {}
+ iframe.onerror = null;
+ };
+ var cleanup = function() {
+ if (iframe) {
+ unattach();
+ iframe.parentNode.removeChild(iframe);
+ iframe.src = "about:blank";
+ iframe = null;
+ utils.detachEvent('unload', cleanup);
+ }
+ };
+ var onerror = function(r) {
+ if (iframe) {
+ cleanup();
+ error_callback(r);
+ }
+ };
+ iframe.src = iframe_url;
+ iframe.style.display = 'none';
+ iframe.style.position = 'absolute';
+ iframe.onerror = function(){onerror('onerror');};
+ iframe.onload = function() {
+ // `onload` is triggered before scripts on the iframe are
+ // executed. Give it few seconds to actually load stuff.
+ clearTimeout(tref);
+ tref = setTimeout(function(){onerror('onload timeout');}, 2000);
+ };
+ _document.body.appendChild(iframe);
+ tref = setTimeout(function(){onerror('timeout');}, 5000);
+ utils.attachEvent('unload', cleanup);
+ return {
+ iframe: iframe,
+ cleanup: cleanup,
+ loaded: unattach
+ };
+};
+
+utils.createHtmlfile = function (iframe_url, error_callback) {
+ var doc = new ActiveXObject('htmlfile');
+ var tref;
+ var iframe;
+ var unattach = function() {
+ clearTimeout(tref);
+ };
+ var cleanup = function() {
+ if (doc) {
+ unattach();
+ utils.detachEvent('unload', cleanup);
+ try {
+ iframe.src = "about:blank";
+ } catch (x) {}
+ iframe.parentNode.removeChild(iframe);
+ iframe = doc = null;
+ CollectGarbage();
+ }
+ };
+ var onerror = function(r) {
+ if (doc) {
+ cleanup();
+ error_callback(r);
+ }
+ };
+
+ doc.open();
+ doc.write('<html><script>' +
+ 'document.domain="' + document.domain + '";' +
+ '</script></html>');
+ doc.close();
+ doc.parentWindow[WPrefix] = _window[WPrefix];
+ var c = doc.createElement('div');
+ doc.body.appendChild(c);
+ iframe = doc.createElement('iframe');
+ c.appendChild(iframe);
+ iframe.src = iframe_url;
+ tref = setTimeout(function(){onerror('timeout');}, 5000);
+ utils.attachEvent('unload', cleanup);
+ return {
+ iframe: iframe,
+ cleanup: cleanup,
+ loaded: unattach
+ };
+};
diff --git a/lib/index.js b/lib/index.js
index 88b5c9f..d8ee327 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -5,6 +5,7 @@ SockJS = (function(){
<!-- include lib/reventtarget.js -->
<!-- include lib/simpleevent.js -->
<!-- include lib/utils.js -->
+<!-- include lib/dom.js -->
<!-- include lib/sockjs.js -->
<!-- include lib/trans-websocket.js -->
<!-- include lib/trans-sender.js -->
diff --git a/lib/utils.js b/lib/utils.js
index 32a4925..17113d8 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -20,35 +20,6 @@ utils.random_number_string = function(max) {
return (p + utils.random_number(max)).slice(-t);
};
-utils.attachMessage = function(listener) {
- utils.attachEvent('message', listener);
-};
-utils.attachEvent = function(event, listener) {
- if (typeof _window.addEventListener !== 'undefined') {
- _window.addEventListener(event, listener, false);
- } else {
- // IE quirks.
- // According to: http://stevesouders.com/misc/test-postmessage.php
- // the message gets delivered only to 'document', not 'window'.
- _document.attachEvent("on" + event, listener);
- // I get 'window' for ie8.
- _window.attachEvent("on" + event, listener);
- }
-};
-
-utils.detachMessage = function(listener) {
- utils.detachEvent('message', listener);
-};
-utils.detachEvent = function(event, listener) {
- if (typeof _window.addEventListener !== 'undefined') {
- _window.removeEventListener(event, listener, false);
- } else {
- _document.detachEvent("on" + event, listener);
- _window.detachEvent("on" + event, listener);
- }
-};
-
-
// Assuming that url looks like: http://asdasd:111/asd
utils.getOrigin = function(url) {
url += '/';
@@ -65,137 +36,6 @@ utils.objectExtend = function(dst, src) {
return dst;
};
-// 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();
- }
- };
-};
-
var WPrefix = '_jp';
utils.polluteGlobalNamespace = function() {
@@ -204,96 +44,6 @@ utils.polluteGlobalNamespace = function() {
}
};
-utils.createIframe = function (iframe_url, error_callback) {
- var iframe = _document.createElement('iframe');
- var tref;
- var unattach = function() {
- clearTimeout(tref);
- // Explorer had problems with that.
- try {iframe.onload = null;} catch (x) {}
- iframe.onerror = null;
- };
- var cleanup = function() {
- if (iframe) {
- unattach();
- iframe.parentNode.removeChild(iframe);
- iframe.src = "about:blank";
- iframe = null;
- utils.detachEvent('unload', cleanup);
- }
- };
- var onerror = function(r) {
- if (iframe) {
- cleanup();
- error_callback(r);
- }
- };
- iframe.src = iframe_url;
- iframe.style.display = 'none';
- iframe.style.position = 'absolute';
- iframe.onerror = function(){onerror('onerror');};
- iframe.onload = function() {
- // `onload` is triggered before scripts on the iframe are
- // executed. Give it few seconds to actually load stuff.
- clearTimeout(tref);
- tref = setTimeout(function(){onerror('onload timeout');}, 2000);
- };
- _document.body.appendChild(iframe);
- tref = setTimeout(function(){onerror('timeout');}, 5000);
- utils.attachEvent('unload', cleanup);
- return {
- iframe: iframe,
- cleanup: cleanup,
- loaded: unattach
- };
-};
-
-utils.createHtmlfile = function (iframe_url, error_callback) {
- var doc = new ActiveXObject('htmlfile');
- var tref;
- var iframe;
- var unattach = function() {
- clearTimeout(tref);
- };
- var cleanup = function() {
- if (doc) {
- unattach();
- utils.detachEvent('unload', cleanup);
- try {
- iframe.src = "about:blank";
- } catch (x) {}
- iframe.parentNode.removeChild(iframe);
- iframe = doc = null;
- CollectGarbage();
- }
- };
- var onerror = function(r) {
- if (doc) {
- cleanup();
- error_callback(r);
- }
- };
-
- doc.open();
- doc.write('<html><script>' +
- 'document.domain="' + document.domain + '";' +
- '</script></html>');
- doc.close();
- doc.parentWindow[WPrefix] = _window[WPrefix];
- var c = doc.createElement('div');
- doc.body.appendChild(c);
- iframe = doc.createElement('iframe');
- c.appendChild(iframe);
- iframe.src = iframe_url;
- tref = setTimeout(function(){onerror('timeout');}, 5000);
- utils.attachEvent('unload', cleanup);
- return {
- iframe: iframe,
- cleanup: cleanup,
- loaded: unattach
- };
-};
-
utils.closeFrame = function (code, reason) {
return 'c'+JSON.stringify([code, reason]);
};
--
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