[Pkg-javascript-commits] [sockjs-client] 12/434: Use local references to document and window
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 f6e4eab211d2438312efed6e684fe50fb769e508
Author: Marek Majkowski <majek04 at gmail.com>
Date: Sat Jul 23 22:05:28 2011 +0100
Use local references to document and window
---
lib/main.js | 2 ++
lib/sockjs.js | 2 +-
lib/trans-jsonp.js | 30 +++++++++++++++---------------
lib/utils.js | 12 ++++++------
4 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/lib/main.js b/lib/main.js
index 1b80b9a..aac4e45 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -1,5 +1,7 @@
// Public object
SockJS = (function(){
+ var _document = document;
+ var _window = window;
<!-- include lib/reventtarget.js -->
<!-- include lib/simpleevent.js -->
<!-- include lib/utils.js -->
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 0d78bc2..567b852 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -29,7 +29,7 @@ SockJS.CLOSING = 2;
SockJS.CLOSED = 3;
SockJS.prototype._debug = function() {
- if (this._options.debug && 'console' in window && console.log) {
+ if (this._options.debug && 'console' in _window && console.log) {
console.log.apply(console, arguments);
}
};
diff --git a/lib/trans-jsonp.js b/lib/trans-jsonp.js
index 1e6523e..88066af 100644
--- a/lib/trans-jsonp.js
+++ b/lib/trans-jsonp.js
@@ -2,7 +2,7 @@ var JsonPrefix = '_jp';
var JsonPTransport = SockJS.jsonp = function(ri, trans_url){
// Unavoidable namespace pollution.
- if (!(JsonPrefix in window)) {window[JsonPrefix] = {};}
+ if (!(JsonPrefix in _window)) {_window[JsonPrefix] = {};}
this.ri = ri;
this.url = trans_url;
this._send_buffer = [];
@@ -81,14 +81,14 @@ var jsonPReceiverWrapper = function(url, constructReceiver, user_callback) {
var id = 'a' + utils.random_string(6);
var url_id = url + '?c=' + escape(JsonPrefix + '.' + id);
var callback = function(e, t) {
- delete window[JsonPrefix][id];
+ delete _window[JsonPrefix][id];
user_callback(e, t);
};
var close_script = constructReceiver(url_id, callback);
- window[JsonPrefix][id] = close_script;
+ _window[JsonPrefix][id] = close_script;
var stop = function() {
- if (window[JsonPrefix][id]) {
+ if (_window[JsonPrefix][id]) {
close_script({status:1000, reson:"Normal closure"}, 'stop');
}
};
@@ -100,7 +100,7 @@ var jsonPReceiverWrapper = function(url, constructReceiver, user_callback) {
// and jQuery-JSONP:
// https://code.google.com/p/jquery-jsonp/source/browse/trunk/core/jquery.jsonp.js
var jsonPGenericReceiver = function(url, callback) {
- var script = document.createElement('script');
+ var script = _document.createElement('script');
var script2;
var close_script = function(v, t) {
setTimeout(function(){
@@ -156,16 +156,16 @@ var jsonPGenericReceiver = function(url, callback) {
// According to mozilla docs, in recent browsers script.async defaults
// to 'true', so we may use it to detect a good browser:
// https://developer.mozilla.org/en/HTML/Element/script
- if (typeof document.attachEvent === 'object') {
+ if (typeof _document.attachEvent === 'object') {
// ie
try {
script.htmlFor = script.id;
script.event = "onclick";
} catch (x) {}
script.async = true;
- } else if (typeof document.attachEvent === 'function') {
- // opera
- script2 = document.createElement('script');
+ } else if (typeof _document.attachEvent === 'function') {
+ // opera, second sync script hack
+ script2 = _document.createElement('script');
script2.text = "try{document.getElementById('"+script.id+"').onerror();}catch(x){};";
script.async = script2.async = false;
} else {
@@ -180,7 +180,7 @@ var jsonPGenericReceiver = function(url, callback) {
script.async = true;
}
- var head = document.getElementsByTagName('head')[0];
+ var head = _document.getElementsByTagName('head')[0];
head.insertBefore(script, head.firstChild);
if (script2){
head.insertBefore(script2, head.firstChild);
@@ -191,8 +191,8 @@ var jsonPGenericReceiver = function(url, callback) {
var jsonPGenericSender = function(url, messages, callback) {
var that = this;
if (!('_send_form' in that)) {
- var form = that._send_form = document.createElement('form');
- var area = document.createElement('textarea');
+ var form = that._send_form = _document.createElement('form');
+ var area = _document.createElement('textarea');
area.name = 'd';
form.style.display = 'none';
form.style.position = 'absolute';
@@ -200,7 +200,7 @@ var jsonPGenericSender = function(url, messages, callback) {
form.enctype = 'application/x-www-form-urlencoded';
form.acceptCharset = "UTF-8";
form.appendChild(area);
- document.body.appendChild(form);
+ _document.body.appendChild(form);
}
var form = that._send_form;
var id = 'a' + utils.random_string(8);
@@ -210,9 +210,9 @@ var jsonPGenericSender = function(url, messages, callback) {
var iframe;
try {
// ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
- iframe = document.createElement('<iframe name="'+ id +'">');
+ iframe = _document.createElement('<iframe name="'+ id +'">');
} catch(x) {
- iframe = document.createElement('iframe');
+ iframe = _document.createElement('iframe');
iframe.name = id;
}
iframe.id = id;
diff --git a/lib/utils.js b/lib/utils.js
index 8b401de..fef6c9e 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -21,21 +21,21 @@ utils.random_number_string = function(max) {
};
utils.attachMessage = function(listener) {
- if (typeof window.addEventListener !== 'undefined') {
- window.addEventListener("message", listener, false);
+ if (typeof _window.addEventListener !== 'undefined') {
+ _window.addEventListener("message", 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("onmessage", listener);
+ _document.attachEvent("onmessage", listener);
}
};
utils.dettachMessage = function(listener) {
- if (typeof window.addEventListener !== 'undefined') {
- window.removeEventListener("message", listener, false);
+ if (typeof _window.addEventListener !== 'undefined') {
+ _window.removeEventListener("message", listener, false);
} else {
- document.removeEvent("onmessage", listener);
+ _document.removeEvent("onmessage", listener);
}
};
--
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