/js/lib/Socket.IO-node/support/socket.io-client/lib/transports/htmlfile.js
JavaScript | 74 lines | 53 code | 13 blank | 8 comment | 3 complexity | 2de729c958406dc51ba7c15c7a87d5b3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
- /**
- * Socket.IO client
- *
- * @author Guillermo Rauch <guillermo@learnboost.com>
- * @license The MIT license.
- * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
- */
- (function(){
- var io = this.io;
-
- var HTMLFile = io.Transport.htmlfile = function(){
- io.Transport.XHR.apply(this, arguments);
- };
-
- io.util.inherit(HTMLFile, io.Transport.XHR);
-
- HTMLFile.prototype.type = 'htmlfile';
-
- HTMLFile.prototype._get = function(){
- var self = this;
- this._open();
- window.attachEvent('onunload', function(){ self._destroy(); });
- };
-
- HTMLFile.prototype._open = function(){
- this._doc = new ActiveXObject('htmlfile');
- this._doc.open();
- this._doc.write('<html></html>');
- this._doc.parentWindow.s = this;
- this._doc.close();
- var _iframeC = this._doc.createElement('div');
- this._doc.body.appendChild(_iframeC);
- this._iframe = this._doc.createElement('iframe');
- _iframeC.appendChild(this._iframe);
- this._iframe.src = this._prepareUrl() + '/' + (+ new Date);
- };
-
- HTMLFile.prototype._ = function(data, doc){
- this._onData(data);
- var script = doc.getElementsByTagName('script')[0];
- script.parentNode.removeChild(script);
- };
- HTMLFile.prototype._destroy = function(){
- if (this._iframe){
- this._iframe.src = 'about:blank';
- this._doc = null;
- CollectGarbage();
- }
- };
-
- HTMLFile.prototype.disconnect = function(){
- this._destroy();
- return io.Transport.XHR.prototype.disconnect.call(this);
- };
-
- HTMLFile.check = function(){
- if ('ActiveXObject' in window){
- try {
- var a = new ActiveXObject('htmlfile');
- return a && io.Transport.XHR.check();
- } catch(e){}
- }
- return false;
- };
- HTMLFile.xdomainCheck = function(){
- // we can probably do handling for sub-domains, we should test that it's cross domain but a subdomain here
- return false;
- };
-
- })();