PageRenderTime 290ms CodeModel.GetById 141ms app.highlight 51ms RepoModel.GetById 90ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/transports/htmlfile.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 74 lines | 53 code | 13 blank | 8 comment | 3 complexity | 2de729c958406dc51ba7c15c7a87d5b3 MD5 | raw file
 1/**
 2 * Socket.IO client
 3 * 
 4 * @author Guillermo Rauch <guillermo@learnboost.com>
 5 * @license The MIT license.
 6 * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
 7 */
 8
 9(function(){
10	var io = this.io;
11	
12	var HTMLFile = io.Transport.htmlfile = function(){
13		io.Transport.XHR.apply(this, arguments);
14	};
15	
16	io.util.inherit(HTMLFile, io.Transport.XHR);
17	
18	HTMLFile.prototype.type = 'htmlfile';
19	
20	HTMLFile.prototype._get = function(){
21		var self = this;
22		this._open();
23		window.attachEvent('onunload', function(){ self._destroy(); });
24	};
25	
26	HTMLFile.prototype._open = function(){
27		this._doc = new ActiveXObject('htmlfile');
28		this._doc.open();
29		this._doc.write('<html></html>');
30		this._doc.parentWindow.s = this;
31		this._doc.close();
32
33		var _iframeC = this._doc.createElement('div');
34		this._doc.body.appendChild(_iframeC);
35		this._iframe = this._doc.createElement('iframe');
36		_iframeC.appendChild(this._iframe);
37		this._iframe.src = this._prepareUrl() + '/' + (+ new Date);
38	};
39	
40	HTMLFile.prototype._ = function(data, doc){
41		this._onData(data);
42		var script = doc.getElementsByTagName('script')[0];
43		script.parentNode.removeChild(script);
44	};
45
46  HTMLFile.prototype._destroy = function(){
47    if (this._iframe){
48      this._iframe.src = 'about:blank';
49      this._doc = null;
50      CollectGarbage();
51    }
52  };
53	
54	HTMLFile.prototype.disconnect = function(){
55		this._destroy();
56		return io.Transport.XHR.prototype.disconnect.call(this);
57	};
58	
59	HTMLFile.check = function(){
60		if ('ActiveXObject' in window){
61			try {
62				var a = new ActiveXObject('htmlfile');
63				return a && io.Transport.XHR.check();
64			} catch(e){}
65		}
66		return false;
67	};
68
69	HTMLFile.xdomainCheck = function(){
70		// we can probably do handling for sub-domains, we should test that it's cross domain but a subdomain here
71		return false;
72	};
73	
74})();