3 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
7 (function (exports, io) {
13 exports.htmlfile = HTMLFile;
16 * The HTMLFile transport creates a `forever iframe` based transport
17 * for Internet Explorer. Regular forever iframe implementations will
18 * continuously trigger the browsers buzy indicators. If the forever iframe
19 * is created inside a `htmlfile` these indicators will not be trigged.
22 * @extends {io.Transport.XHR}
26 function HTMLFile (socket) {
27 io.Transport.XHR.apply(this, arguments);
31 * Inherits from XHR transport.
34 io.util.inherit(HTMLFile, io.Transport.XHR);
42 HTMLFile.prototype.name = 'htmlfile';
45 * Creates a new ActiveX `htmlfile` with a forever loading iframe
46 * that can be used to listen to messages. Inside the generated
47 * `htmlfile` a reference will be made to the HTMLFile transport.
52 HTMLFile.prototype.get = function () {
53 this.doc = new ActiveXObject('htmlfile');
55 this.doc.write('<html></html>');
57 this.doc.parentWindow.s = this;
59 var iframeC = this.doc.createElement('div');
60 iframeC.className = 'socketio';
62 this.doc.body.appendChild(iframeC);
63 this.iframe = this.doc.createElement('iframe');
65 iframeC.appendChild(this.iframe);
68 , query = io.util.query(this.socket.options.query, 't='+ +new Date);
70 this.iframe.src = this.prepareUrl() + query;
72 io.util.on(window, 'unload', function () {
78 * The Socket.IO server will write script tags inside the forever
79 * iframe, this function will be used as callback for the incoming
82 * @param {String} data The message
83 * @param {document} doc Reference to the context
87 HTMLFile.prototype._ = function (data, doc) {
88 // unescape all forward slashes. see GH-1251
89 data = data.replace(/\\\//g, '/');
92 var script = doc.getElementsByTagName('script')[0];
93 script.parentNode.removeChild(script);
98 * Destroy the established connection, iframe and `htmlfile`.
99 * And calls the `CollectGarbage` function of Internet Explorer
100 * to release the memory.
105 HTMLFile.prototype.destroy = function () {
108 this.iframe.src = 'about:blank';
112 this.iframe.parentNode.removeChild(this.iframe);
120 * Disconnects the established connection.
122 * @returns {Transport} Chaining.
126 HTMLFile.prototype.close = function () {
128 return io.Transport.XHR.prototype.close.call(this);
132 * Checks if the browser supports this transport. The browser
133 * must have an `ActiveXObject` implementation.
139 HTMLFile.check = function (socket) {
140 if (typeof window != "undefined" && 'ActiveXObject' in window){
142 var a = new ActiveXObject('htmlfile');
143 return a && io.Transport.XHR.check(socket);
150 * Check if cross domain requests are supported.
156 HTMLFile.xdomainCheck = function () {
157 // we can probably do handling for sub-domains, we should
158 // test that it's cross domain but a subdomain here
163 * Add the transport to your public io.transports array.
168 io.transports.push('htmlfile');
171 'undefined' != typeof io ? io.Transport : module.exports
172 , 'undefined' != typeof io ? io : module.parent.exports