PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  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. (function(){
  9. var io = this.io;
  10. var HTMLFile = io.Transport.htmlfile = function(){
  11. io.Transport.XHR.apply(this, arguments);
  12. };
  13. io.util.inherit(HTMLFile, io.Transport.XHR);
  14. HTMLFile.prototype.type = 'htmlfile';
  15. HTMLFile.prototype._get = function(){
  16. var self = this;
  17. this._open();
  18. window.attachEvent('onunload', function(){ self._destroy(); });
  19. };
  20. HTMLFile.prototype._open = function(){
  21. this._doc = new ActiveXObject('htmlfile');
  22. this._doc.open();
  23. this._doc.write('<html></html>');
  24. this._doc.parentWindow.s = this;
  25. this._doc.close();
  26. var _iframeC = this._doc.createElement('div');
  27. this._doc.body.appendChild(_iframeC);
  28. this._iframe = this._doc.createElement('iframe');
  29. _iframeC.appendChild(this._iframe);
  30. this._iframe.src = this._prepareUrl() + '/' + (+ new Date);
  31. };
  32. HTMLFile.prototype._ = function(data, doc){
  33. this._onData(data);
  34. var script = doc.getElementsByTagName('script')[0];
  35. script.parentNode.removeChild(script);
  36. };
  37. HTMLFile.prototype._destroy = function(){
  38. if (this._iframe){
  39. this._iframe.src = 'about:blank';
  40. this._doc = null;
  41. CollectGarbage();
  42. }
  43. };
  44. HTMLFile.prototype.disconnect = function(){
  45. this._destroy();
  46. return io.Transport.XHR.prototype.disconnect.call(this);
  47. };
  48. HTMLFile.check = function(){
  49. if ('ActiveXObject' in window){
  50. try {
  51. var a = new ActiveXObject('htmlfile');
  52. return a && io.Transport.XHR.check();
  53. } catch(e){}
  54. }
  55. return false;
  56. };
  57. HTMLFile.xdomainCheck = function(){
  58. // we can probably do handling for sub-domains, we should test that it's cross domain but a subdomain here
  59. return false;
  60. };
  61. })();