PageRenderTime 94ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 1ms

/public/javascripts/socket.io.js

https://github.com/subtleGradient/Tutti
JavaScript | 1705 lines | 1254 code | 223 blank | 228 comment | 271 complexity | 2510c0281a1a0c57b5c89001e873f271 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /** Socket.IO 0.5.4 - Built with build.js */
  2. /**
  3. * Socket.IO client
  4. *
  5. * @author Guillermo Rauch <guillermo@learnboost.com>
  6. * @license The MIT license.
  7. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  8. */
  9. this.io = {
  10. version: '0.5.4',
  11. setPath: function(path){
  12. this.path = /\/$/.test(path) ? path : path + '/';
  13. // this is temporary until we get a fix for injecting Flash WebSocket javascript files dynamically,
  14. // as io.js shouldn't be aware of specific transports.
  15. if ('WebSocket' in window){
  16. WebSocket.__swfLocation = path + 'lib/vendor/web-socket-js/WebSocketMain.swf';
  17. }
  18. }
  19. };
  20. if ('jQuery' in this) jQuery.io = this.io;
  21. /**
  22. * Socket.IO client
  23. *
  24. * @author Guillermo Rauch <guillermo@learnboost.com>
  25. * @license The MIT license.
  26. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  27. */
  28. (function(){
  29. var _pageLoaded = false;
  30. io.util = {
  31. ios: false,
  32. load: function(fn){
  33. if (document.readyState == 'complete' || _pageLoaded) return fn();
  34. if ('attachEvent' in window){
  35. window.attachEvent('onload', fn);
  36. } else {
  37. window.addEventListener('load', fn, false);
  38. }
  39. },
  40. inherit: function(ctor, superCtor){
  41. // no support for `instanceof` for now
  42. for (var i in superCtor.prototype){
  43. ctor.prototype[i] = superCtor.prototype[i];
  44. }
  45. },
  46. indexOf: function(arr, item, from){
  47. for (var l = arr.length, i = (from < 0) ? Math.max(0, l + from) : from || 0; i < l; i++){
  48. if (arr[i] === item) return i;
  49. }
  50. return -1;
  51. },
  52. isArray: function(obj){
  53. return Object.prototype.toString.call(obj) === '[object Array]';
  54. }
  55. };
  56. io.util.ios = /iphone|ipad/i.test(navigator.userAgent);
  57. io.util.android = /android/i.test(navigator.userAgent);
  58. io.util.load(function(){
  59. _pageLoaded = true;
  60. });
  61. })();
  62. /**
  63. * Socket.IO client
  64. *
  65. * @author Guillermo Rauch <guillermo@learnboost.com>
  66. * @license The MIT license.
  67. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  68. */
  69. // abstract
  70. (function(){
  71. var frame = '~m~',
  72. Transport = io.Transport = function(base, options){
  73. this.base = base;
  74. this.options = options;
  75. };
  76. Transport.prototype.send = function(){
  77. throw new Error('Missing send() implementation');
  78. };
  79. Transport.prototype.connect = function(){
  80. throw new Error('Missing connect() implementation');
  81. };
  82. Transport.prototype.disconnect = function(){
  83. throw new Error('Missing disconnect() implementation');
  84. };
  85. Transport.prototype._encode = function(messages){
  86. var ret = '', message,
  87. messages = io.util.isArray(messages) ? messages : [messages];
  88. for (var i = 0, l = messages.length; i < l; i++){
  89. message = messages[i] === null || messages[i] === undefined ? '' : String(messages[i]);
  90. ret += frame + message.length + frame + message;
  91. }
  92. return ret;
  93. };
  94. Transport.prototype._decode = function(data){
  95. var messages = [], number, n;
  96. do {
  97. if (data.substr(0, 3) !== frame) return messages;
  98. data = data.substr(3);
  99. number = '', n = '';
  100. for (var i = 0, l = data.length; i < l; i++){
  101. n = Number(data.substr(i, 1));
  102. if (data.substr(i, 1) == n){
  103. number += n;
  104. } else {
  105. data = data.substr(number.length + frame.length)
  106. number = Number(number);
  107. break;
  108. }
  109. }
  110. messages.push(data.substr(0, number)); // here
  111. data = data.substr(number);
  112. } while(data !== '');
  113. return messages;
  114. };
  115. Transport.prototype._onData = function(data){
  116. var msgs = this._decode(data);
  117. if (msgs){
  118. for (var i = 0, l = msgs.length; i < l; i++){
  119. this._onMessage(msgs[i]);
  120. }
  121. }
  122. };
  123. Transport.prototype._onMessage = function(message){
  124. if (!('sessionid' in this)){
  125. this.sessionid = message;
  126. this._onConnect();
  127. } else if (message.substr(0, 3) == '~h~'){
  128. this._onHeartbeat(message.substr(3));
  129. } else {
  130. this.base._onMessage(message);
  131. }
  132. },
  133. Transport.prototype._onHeartbeat = function(heartbeat){
  134. this.send('~h~' + heartbeat); // echo
  135. };
  136. Transport.prototype._onConnect = function(){
  137. this.connected = true;
  138. this.base._onConnect();
  139. };
  140. Transport.prototype._onDisconnect = function(){
  141. if (!this.connected) return;
  142. this.connected = false;
  143. this.base._onDisconnect();
  144. };
  145. Transport.prototype._prepareUrl = function(){
  146. return (this.base.options.secure ? 'https' : 'http')
  147. + '://' + this.base.host
  148. + ':' + this.base.options.port
  149. + '/' + this.base.options.resource
  150. + '/' + this.type
  151. + (this.sessionid ? ('/' + this.sessionid) : '/');
  152. };
  153. })();
  154. /**
  155. * Socket.IO client
  156. *
  157. * @author Guillermo Rauch <guillermo@learnboost.com>
  158. * @license The MIT license.
  159. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  160. */
  161. (function(){
  162. var empty = new Function,
  163. request = function(xdomain){
  164. if ('XDomainRequest' in window && xdomain) return new XDomainRequest();
  165. if ('XMLHttpRequest' in window) return new XMLHttpRequest();
  166. try {
  167. var a = new ActiveXObject('MSXML2.XMLHTTP');
  168. return a;
  169. } catch(e){}
  170. try {
  171. var b = new ActiveXObject('Microsoft.XMLHTTP');
  172. return b;
  173. } catch(e){}
  174. return false;
  175. },
  176. XHR = io.Transport.XHR = function(){
  177. io.Transport.apply(this, arguments);
  178. };
  179. io.util.inherit(XHR, io.Transport);
  180. XHR.prototype.connect = function(){
  181. if (!('_sendBuffer' in this)) this._sendBuffer = [];
  182. this._get();
  183. return this;
  184. };
  185. XHR.prototype._checkSend = function(){
  186. if (!this._posting && this._sendBuffer.length){
  187. var encoded = this._encode(this._sendBuffer);
  188. this._sendBuffer = [];
  189. this._send(encoded);
  190. }
  191. };
  192. XHR.prototype.send = function(data){
  193. if (io.util.isArray(data)){
  194. this._sendBuffer.push.apply(this._sendBuffer, data);
  195. } else {
  196. this._sendBuffer.push(data);
  197. }
  198. this._checkSend();
  199. return this;
  200. };
  201. XHR.prototype._send = function(data){
  202. var self = this;
  203. this._posting = true;
  204. this._sendXhr = this._request('send', 'POST');
  205. this._sendXhr.onreadystatechange = function(){
  206. var status;
  207. if (self._sendXhr.readyState == 4){
  208. self._sendXhr.onreadystatechange = empty;
  209. try { status = self._sendXhr.status; } catch(e){}
  210. if (status == 200){
  211. self._posting = false;
  212. self._checkSend();
  213. }
  214. }
  215. };
  216. this._sendXhr.send('data=' + encodeURIComponent(data));
  217. },
  218. XHR.prototype.disconnect = function(){
  219. if (this._xhr){
  220. this._xhr.onreadystatechange = this._xhr.onload = empty;
  221. this._xhr.abort();
  222. }
  223. if (this._sendXhr){
  224. try{
  225. this._sendXhr.onreadystatechange = this._sendXhr.onload = empty;
  226. this._sendXhr.abort();
  227. }catch(e){}
  228. }
  229. this._onDisconnect();
  230. return this;
  231. }
  232. XHR.prototype._request = function(url, method, multipart){
  233. var req = request(this.base._isXDomain());
  234. if (multipart) req.multipart = true;
  235. req.open(method || 'GET', this._prepareUrl() + (url ? '/' + url : ''));
  236. if (method == 'POST'){
  237. req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');
  238. }
  239. return req;
  240. };
  241. XHR.check = function(){
  242. try {
  243. if (request()) return true;
  244. } catch(e){}
  245. return false;
  246. };
  247. XHR.request = request;
  248. })();
  249. /**
  250. * Socket.IO client
  251. *
  252. * @author Guillermo Rauch <guillermo@learnboost.com>
  253. * @license The MIT license.
  254. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  255. */
  256. (function(){
  257. var WS = io.Transport.websocket = function(){
  258. io.Transport.apply(this, arguments);
  259. };
  260. io.util.inherit(WS, io.Transport);
  261. WS.prototype.type = 'websocket';
  262. WS.prototype.connect = function(){
  263. var self = this;
  264. this.socket = new WebSocket(this._prepareUrl());
  265. this.socket.onmessage = function(ev){ self._onData(ev.data); };
  266. this.socket.onclose = function(ev){ self._onClose(); };
  267. return this;
  268. };
  269. WS.prototype.send = function(data){
  270. this.socket.send(this._encode(data));
  271. return this;
  272. }
  273. WS.prototype.disconnect = function(){
  274. this.socket.close();
  275. return this;
  276. };
  277. WS.prototype._onClose = function(){
  278. this._onDisconnect();
  279. return this;
  280. };
  281. WS.prototype._prepareUrl = function(){
  282. return (this.base.options.secure ? 'wss' : 'ws')
  283. + '://' + this.base.host
  284. + ':' + this.base.options.port
  285. + '/' + this.base.options.resource
  286. + '/' + this.type
  287. + (this.sessionid ? ('/' + this.sessionid) : '');
  288. };
  289. WS.check = function(){
  290. // we make sure WebSocket is not confounded with a previously loaded flash WebSocket
  291. return 'WebSocket' in window && !('__initialize' in WebSocket);
  292. };
  293. WS.xdomainCheck = function(){
  294. return true;
  295. };
  296. })();
  297. /**
  298. * Socket.IO client
  299. *
  300. * @author Guillermo Rauch <guillermo@learnboost.com>
  301. * @license The MIT license.
  302. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  303. */
  304. (function(){
  305. var Flashsocket = io.Transport.flashsocket = function(){
  306. io.Transport.websocket.apply(this, arguments);
  307. };
  308. io.util.inherit(Flashsocket, io.Transport.websocket);
  309. Flashsocket.prototype.type = 'flashsocket';
  310. Flashsocket.prototype._onClose = function(){
  311. if (!this.base.connected){
  312. // something failed, we might be behind a proxy, so we'll try another transport
  313. this.base.options.transports.splice(io.util.indexOf(this.base.options.transports, 'flashsocket'), 1);
  314. this.base.transport = this.base.getTransport();
  315. this.base.connect();
  316. return;
  317. }
  318. return io.Transport.websocket.prototype._onClose.call(this);
  319. };
  320. Flashsocket.check = function(){
  321. if (!('path' in io)) throw new Error('The `flashsocket` transport requires that you call io.setPath() with the path to the socket.io client dir.');
  322. if ('navigator' in window && 'plugins' in navigator && navigator.plugins['Shockwave Flash']){
  323. return !!navigator.plugins['Shockwave Flash'].description;
  324. }
  325. if ('ActiveXObject' in window) {
  326. try {
  327. return !!new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
  328. } catch (e) {}
  329. }
  330. return false;
  331. };
  332. Flashsocket.xdomainCheck = function(){
  333. return true;
  334. };
  335. })();
  336. /**
  337. * Socket.IO client
  338. *
  339. * @author Guillermo Rauch <guillermo@learnboost.com>
  340. * @license The MIT license.
  341. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  342. */
  343. (function(){
  344. var HTMLFile = io.Transport.htmlfile = function(){
  345. io.Transport.XHR.apply(this, arguments);
  346. };
  347. io.util.inherit(HTMLFile, io.Transport.XHR);
  348. HTMLFile.prototype.type = 'htmlfile';
  349. HTMLFile.prototype._get = function(){
  350. var self = this;
  351. this._open();
  352. window.attachEvent('onunload', function(){ self._destroy(); });
  353. };
  354. HTMLFile.prototype._open = function(){
  355. this._doc = new ActiveXObject('htmlfile');
  356. this._doc.open();
  357. this._doc.write('<html></html>');
  358. this._doc.parentWindow.s = this;
  359. this._doc.close();
  360. var _iframeC = this._doc.createElement('div');
  361. this._doc.body.appendChild(_iframeC);
  362. this._iframe = this._doc.createElement('iframe');
  363. _iframeC.appendChild(this._iframe);
  364. this._iframe.src = this._prepareUrl() + '/' + (+ new Date);
  365. var self = this;
  366. this._checkIframeCompleteIntervalID = setInterval(function(){
  367. self._checkIframeComplete()
  368. }, 5000)
  369. };
  370. HTMLFile.prototype._checkIframeComplete = function(){
  371. if (this._iframe.readyState == 'complete'){
  372. if (this._checkIframeCompleteIntervalID){
  373. clearInterval(this._checkIframeCompleteIntervalID);
  374. delete this._checkIframeCompleteIntervalID;
  375. }
  376. this.disconnect();
  377. }
  378. };
  379. HTMLFile.prototype._ = function(data, doc){
  380. this._onData(data);
  381. var script = doc.getElementsByTagName('script')[0];
  382. script.parentNode.removeChild(script);
  383. console.log('readyState: ' + this._iframe.readyState)
  384. };
  385. HTMLFile.prototype._destroy = function(){
  386. this._iframe.src = 'about:blank';
  387. this._doc = null;
  388. CollectGarbage();
  389. };
  390. HTMLFile.prototype.disconnect = function(){
  391. this._destroy();
  392. return io.Transport.XHR.prototype.disconnect.call(this);
  393. };
  394. HTMLFile.check = function(){
  395. if ('ActiveXObject' in window){
  396. try {
  397. var a = new ActiveXObject('htmlfile');
  398. return a && io.Transport.XHR.check();
  399. } catch(e){}
  400. }
  401. return false;
  402. };
  403. HTMLFile.xdomainCheck = function(){
  404. return false; // send() is not cross domain. we need to POST to an iframe to fix it
  405. };
  406. })();
  407. /**
  408. * Socket.IO client
  409. *
  410. * @author Guillermo Rauch <guillermo@learnboost.com>
  411. * @license The MIT license.
  412. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  413. */
  414. (function(){
  415. var XHRMultipart = io.Transport['xhr-multipart'] = function(){
  416. io.Transport.XHR.apply(this, arguments);
  417. };
  418. io.util.inherit(XHRMultipart, io.Transport.XHR);
  419. XHRMultipart.prototype.type = 'xhr-multipart';
  420. XHRMultipart.prototype._get = function(){
  421. var self = this;
  422. this._xhr = this._request('', 'GET', true);
  423. this._xhr.onreadystatechange = function(){
  424. if (self._xhr.readyState == 3) self._onData(self._xhr.responseText);
  425. };
  426. this._xhr.send();
  427. };
  428. XHRMultipart.check = function(){
  429. return 'XMLHttpRequest' in window && 'multipart' in XMLHttpRequest.prototype;
  430. };
  431. XHRMultipart.xdomainCheck = function(){
  432. return true;
  433. };
  434. })();
  435. /**
  436. * Socket.IO client
  437. *
  438. * @author Guillermo Rauch <guillermo@learnboost.com>
  439. * @license The MIT license.
  440. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  441. */
  442. (function(){
  443. var empty = new Function(),
  444. XHRPolling = io.Transport['xhr-polling'] = function(){
  445. io.Transport.XHR.apply(this, arguments);
  446. };
  447. io.util.inherit(XHRPolling, io.Transport.XHR);
  448. XHRPolling.prototype.type = 'xhr-polling';
  449. XHRPolling.prototype.connect = function(){
  450. if (io.util.ios || io.util.android){
  451. var self = this;
  452. io.util.load(function(){
  453. setTimeout(function(){
  454. io.Transport.XHR.prototype.connect.call(self);
  455. }, 10);
  456. });
  457. } else {
  458. io.Transport.XHR.prototype.connect.call(this);
  459. }
  460. };
  461. XHRPolling.prototype._get = function(){
  462. var self = this;
  463. var url = + new Date
  464. this._xhr = this._request(url, 'GET');
  465. /*if ('onload' in this._xhr){
  466. console.log('setting onload')
  467. this._xhr.onload = function(){
  468. console.log('onload: ' + url + ' ' + this.responseText)
  469. if (this.responseText.length) self._onData(this.responseText);
  470. self.connect();
  471. };
  472. } else {*/
  473. this._xhr.onreadystatechange = function(){
  474. var status;
  475. if (self._xhr.readyState == 4){
  476. self._xhr.onreadystatechange = empty;
  477. try { status = self._xhr.status; } catch(e){}
  478. if (status == 200){
  479. if (self._xhr.responseText.length) self._onData(self._xhr.responseText);
  480. self.connect();
  481. }else{
  482. self.disconnect();
  483. }
  484. }
  485. };
  486. //}
  487. this._xhr.send();
  488. };
  489. XHRPolling.check = function(){
  490. return io.Transport.XHR.check();
  491. };
  492. XHRPolling.xdomainCheck = function(){
  493. return 'XDomainRequest' in window || 'XMLHttpRequest' in window;
  494. };
  495. })();
  496. /**
  497. * Socket.IO client
  498. *
  499. * @author Guillermo Rauch <guillermo@learnboost.com>
  500. * @license The MIT license.
  501. * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
  502. */
  503. (function(){
  504. var Socket = io.Socket = function(host, options){
  505. this.host = host || document.domain;
  506. this.options = {
  507. secure: false,
  508. document: document,
  509. heartbeatInterval: 4000,
  510. port: document.location.port || 80,
  511. resource: 'socket.io',
  512. transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling'],
  513. transportOptions: {},
  514. rememberTransport: false
  515. };
  516. for (var i in options)
  517. if (this.options.hasOwnProperty(i))
  518. this.options[i] = options[i];
  519. this.connected = false;
  520. this.connecting = false;
  521. this._events = {};
  522. this.transport = this.getTransport();
  523. if (!this.transport && 'console' in window) console.error('No transport available');
  524. };
  525. Socket.prototype.getTransport = function(){
  526. var transports = this.options.transports, match;
  527. if (this.options.rememberTransport){
  528. match = this.options.document.cookie.match('(?:^|;)\\s*socket\.io=([^;]*)');
  529. if (match) transports = [decodeURIComponent(match[1])];
  530. }
  531. for (var i = 0, transport; transport = transports[i]; i++){
  532. if (io.Transport[transport]
  533. && io.Transport[transport].check()
  534. && (!this._isXDomain() || io.Transport[transport].xdomainCheck())){
  535. return new io.Transport[transport](this, this.options.transportOptions[transport] || {});
  536. }
  537. }
  538. return null;
  539. };
  540. Socket.prototype.connect = function(){
  541. if (this.transport && !this.connected && !this.connecting){
  542. this.connecting = true;
  543. this.transport.connect();
  544. }
  545. return this;
  546. };
  547. Socket.prototype.send = function(data){
  548. if (!this.transport || !this.transport.connected) return this._queue(data);
  549. this.transport.send(data);
  550. return this;
  551. };
  552. Socket.prototype.disconnect = function(){
  553. this.transport.disconnect();
  554. return this;
  555. };
  556. Socket.prototype.on = function(name, fn){
  557. if (!(name in this._events)) this._events[name] = [];
  558. this._events[name].push(fn);
  559. return this;
  560. };
  561. Socket.prototype.fire = function(name, args){
  562. if (name in this._events){
  563. var i, ii;
  564. for (i = 0, ii = this._events[name].length; i < ii; i++)
  565. this._events[name][i].apply(this, args || []);
  566. }
  567. return this;
  568. };
  569. Socket.prototype.removeEvent = function(name, fn){
  570. if (name in this._events){
  571. for (var a = 0, l = this._events[name].length; a < l; a++)
  572. if (this._events[name][a] == fn) this._events[name].splice(a, 1);
  573. }
  574. return this;
  575. };
  576. Socket.prototype._queue = function(message){
  577. if (!('_queueStack' in this)) this._queueStack = [];
  578. this._queueStack.push(message);
  579. return this;
  580. };
  581. Socket.prototype._doQueue = function(){
  582. if (!('_queueStack' in this) || !this._queueStack.length) return this;
  583. this.transport.send(this._queueStack);
  584. this._queueStack = [];
  585. return this;
  586. };
  587. Socket.prototype._isXDomain = function(){
  588. return this.host !== document.domain;
  589. };
  590. Socket.prototype._onConnect = function(){
  591. this.connected = true;
  592. this.connecting = false;
  593. this._doQueue();
  594. if (this.options.rememberTransport) this.options.document.cookie = 'socket.io=' + encodeURIComponent(this.transport.type);
  595. this.fire('connect');
  596. };
  597. Socket.prototype._onMessage = function(data){
  598. this.fire('message', [data]);
  599. };
  600. Socket.prototype._onDisconnect = function(){
  601. this.fire('disconnect');
  602. };
  603. Socket.prototype.addListener = Socket.prototype.addEvent = Socket.prototype.addEventListener = Socket.prototype.on;
  604. })();
  605. /* SWFObject v2.2 <http://code.google.com/p/swfobject/>
  606. is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
  607. */
  608. var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
  609. /*
  610. /*
  611. Copyright 2006 Adobe Systems Incorporated
  612. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
  613. to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  614. and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  615. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  616. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  617. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  618. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  619. OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  620. */
  621. /*
  622. * The Bridge class, responsible for navigating AS instances
  623. */
  624. function FABridge(target,bridgeName)
  625. {
  626. this.target = target;
  627. this.remoteTypeCache = {};
  628. this.remoteInstanceCache = {};
  629. this.remoteFunctionCache = {};
  630. this.localFunctionCache = {};
  631. this.bridgeID = FABridge.nextBridgeID++;
  632. this.name = bridgeName;
  633. this.nextLocalFuncID = 0;
  634. FABridge.instances[this.name] = this;
  635. FABridge.idMap[this.bridgeID] = this;
  636. return this;
  637. }
  638. // type codes for packed values
  639. FABridge.TYPE_ASINSTANCE = 1;
  640. FABridge.TYPE_ASFUNCTION = 2;
  641. FABridge.TYPE_JSFUNCTION = 3;
  642. FABridge.TYPE_ANONYMOUS = 4;
  643. FABridge.initCallbacks = {};
  644. FABridge.userTypes = {};
  645. FABridge.addToUserTypes = function()
  646. {
  647. for (var i = 0; i < arguments.length; i++)
  648. {
  649. FABridge.userTypes[arguments[i]] = {
  650. 'typeName': arguments[i],
  651. 'enriched': false
  652. };
  653. }
  654. }
  655. FABridge.argsToArray = function(args)
  656. {
  657. var result = [];
  658. for (var i = 0; i < args.length; i++)
  659. {
  660. result[i] = args[i];
  661. }
  662. return result;
  663. }
  664. function instanceFactory(objID)
  665. {
  666. this.fb_instance_id = objID;
  667. return this;
  668. }
  669. function FABridge__invokeJSFunction(args)
  670. {
  671. var funcID = args[0];
  672. var throughArgs = args.concat();//FABridge.argsToArray(arguments);
  673. throughArgs.shift();
  674. var bridge = FABridge.extractBridgeFromID(funcID);
  675. return bridge.invokeLocalFunction(funcID, throughArgs);
  676. }
  677. FABridge.addInitializationCallback = function(bridgeName, callback)
  678. {
  679. var inst = FABridge.instances[bridgeName];
  680. if (inst != undefined)
  681. {
  682. callback.call(inst);
  683. return;
  684. }
  685. var callbackList = FABridge.initCallbacks[bridgeName];
  686. if(callbackList == null)
  687. {
  688. FABridge.initCallbacks[bridgeName] = callbackList = [];
  689. }
  690. callbackList.push(callback);
  691. }
  692. // updated for changes to SWFObject2
  693. function FABridge__bridgeInitialized(bridgeName) {
  694. var objects = document.getElementsByTagName("object");
  695. var ol = objects.length;
  696. var activeObjects = [];
  697. if (ol > 0) {
  698. for (var i = 0; i < ol; i++) {
  699. if (typeof objects[i].SetVariable != "undefined") {
  700. activeObjects[activeObjects.length] = objects[i];
  701. }
  702. }
  703. }
  704. var embeds = document.getElementsByTagName("embed");
  705. var el = embeds.length;
  706. var activeEmbeds = [];
  707. if (el > 0) {
  708. for (var j = 0; j < el; j++) {
  709. if (typeof embeds[j].SetVariable != "undefined") {
  710. activeEmbeds[activeEmbeds.length] = embeds[j];
  711. }
  712. }
  713. }
  714. var aol = activeObjects.length;
  715. var ael = activeEmbeds.length;
  716. var searchStr = "bridgeName="+ bridgeName;
  717. if ((aol == 1 && !ael) || (aol == 1 && ael == 1)) {
  718. FABridge.attachBridge(activeObjects[0], bridgeName);
  719. }
  720. else if (ael == 1 && !aol) {
  721. FABridge.attachBridge(activeEmbeds[0], bridgeName);
  722. }
  723. else {
  724. var flash_found = false;
  725. if (aol > 1) {
  726. for (var k = 0; k < aol; k++) {
  727. var params = activeObjects[k].childNodes;
  728. for (var l = 0; l < params.length; l++) {
  729. var param = params[l];
  730. if (param.nodeType == 1 && param.tagName.toLowerCase() == "param" && param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0) {
  731. FABridge.attachBridge(activeObjects[k], bridgeName);
  732. flash_found = true;
  733. break;
  734. }
  735. }
  736. if (flash_found) {
  737. break;
  738. }
  739. }
  740. }
  741. if (!flash_found && ael > 1) {
  742. for (var m = 0; m < ael; m++) {
  743. var flashVars = activeEmbeds[m].attributes.getNamedItem("flashVars").nodeValue;
  744. if (flashVars.indexOf(searchStr) >= 0) {
  745. FABridge.attachBridge(activeEmbeds[m], bridgeName);
  746. break;
  747. }
  748. }
  749. }
  750. }
  751. return true;
  752. }
  753. // used to track multiple bridge instances, since callbacks from AS are global across the page.
  754. FABridge.nextBridgeID = 0;
  755. FABridge.instances = {};
  756. FABridge.idMap = {};
  757. FABridge.refCount = 0;
  758. FABridge.extractBridgeFromID = function(id)
  759. {
  760. var bridgeID = (id >> 16);
  761. return FABridge.idMap[bridgeID];
  762. }
  763. FABridge.attachBridge = function(instance, bridgeName)
  764. {
  765. var newBridgeInstance = new FABridge(instance, bridgeName);
  766. FABridge[bridgeName] = newBridgeInstance;
  767. /* FABridge[bridgeName] = function() {
  768. return newBridgeInstance.root();
  769. }
  770. */
  771. var callbacks = FABridge.initCallbacks[bridgeName];
  772. if (callbacks == null)
  773. {
  774. return;
  775. }
  776. for (var i = 0; i < callbacks.length; i++)
  777. {
  778. callbacks[i].call(newBridgeInstance);
  779. }
  780. delete FABridge.initCallbacks[bridgeName]
  781. }
  782. // some methods can't be proxied. You can use the explicit get,set, and call methods if necessary.
  783. FABridge.blockedMethods =
  784. {
  785. toString: true,
  786. get: true,
  787. set: true,
  788. call: true
  789. };
  790. FABridge.prototype =
  791. {
  792. // bootstrapping
  793. root: function()
  794. {
  795. return this.deserialize(this.target.getRoot());
  796. },
  797. //clears all of the AS objects in the cache maps
  798. releaseASObjects: function()
  799. {
  800. return this.target.releaseASObjects();
  801. },
  802. //clears a specific object in AS from the type maps
  803. releaseNamedASObject: function(value)
  804. {
  805. if(typeof(value) != "object")
  806. {
  807. return false;
  808. }
  809. else
  810. {
  811. var ret = this.target.releaseNamedASObject(value.fb_instance_id);
  812. return ret;
  813. }
  814. },
  815. //create a new AS Object
  816. create: function(className)
  817. {
  818. return this.deserialize(this.target.create(className));
  819. },
  820. // utilities
  821. makeID: function(token)
  822. {
  823. return (this.bridgeID << 16) + token;
  824. },
  825. // low level access to the flash object
  826. //get a named property from an AS object
  827. getPropertyFromAS: function(objRef, propName)
  828. {
  829. if (FABridge.refCount > 0)
  830. {
  831. throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
  832. }
  833. else
  834. {
  835. FABridge.refCount++;
  836. retVal = this.target.getPropFromAS(objRef, propName);
  837. retVal = this.handleError(retVal);
  838. FABridge.refCount--;
  839. return retVal;
  840. }
  841. },
  842. //set a named property on an AS object
  843. setPropertyInAS: function(objRef,propName, value)
  844. {
  845. if (FABridge.refCount > 0)
  846. {
  847. throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
  848. }
  849. else
  850. {
  851. FABridge.refCount++;
  852. retVal = this.target.setPropInAS(objRef,propName, this.serialize(value));
  853. retVal = this.handleError(retVal);
  854. FABridge.refCount--;
  855. return retVal;
  856. }
  857. },
  858. //call an AS function
  859. callASFunction: function(funcID, args)
  860. {
  861. if (FABridge.refCount > 0)
  862. {
  863. throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
  864. }
  865. else
  866. {
  867. FABridge.refCount++;
  868. retVal = this.target.invokeASFunction(funcID, this.serialize(args));
  869. retVal = this.handleError(retVal);
  870. FABridge.refCount--;
  871. return retVal;
  872. }
  873. },
  874. //call a method on an AS object
  875. callASMethod: function(objID, funcName, args)
  876. {
  877. if (FABridge.refCount > 0)
  878. {
  879. throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
  880. }
  881. else
  882. {
  883. FABridge.refCount++;
  884. args = this.serialize(args);
  885. retVal = this.target.invokeASMethod(objID, funcName, args);
  886. retVal = this.handleError(retVal);
  887. FABridge.refCount--;
  888. return retVal;
  889. }
  890. },
  891. // responders to remote calls from flash
  892. //callback from flash that executes a local JS function
  893. //used mostly when setting js functions as callbacks on events
  894. invokeLocalFunction: function(funcID, args)
  895. {
  896. var result;
  897. var func = this.localFunctionCache[funcID];
  898. if(func != undefined)
  899. {
  900. result = this.serialize(func.apply(null, this.deserialize(args)));
  901. }
  902. return result;
  903. },
  904. // Object Types and Proxies
  905. // accepts an object reference, returns a type object matching the obj reference.
  906. getTypeFromName: function(objTypeName)
  907. {
  908. return this.remoteTypeCache[objTypeName];
  909. },
  910. //create an AS proxy for the given object ID and type
  911. createProxy: function(objID, typeName)
  912. {
  913. var objType = this.getTypeFromName(typeName);
  914. instanceFactory.prototype = objType;
  915. var instance = new instanceFactory(objID);
  916. this.remoteInstanceCache[objID] = instance;
  917. return instance;
  918. },
  919. //return the proxy associated with the given object ID
  920. getProxy: function(objID)
  921. {
  922. return this.remoteInstanceCache[objID];
  923. },
  924. // accepts a type structure, returns a constructed type
  925. addTypeDataToCache: function(typeData)
  926. {
  927. newType = new ASProxy(this, typeData.name);
  928. var accessors = typeData.accessors;
  929. for (var i = 0; i < accessors.length; i++)
  930. {
  931. this.addPropertyToType(newType, accessors[i]);
  932. }
  933. var methods = typeData.methods;
  934. for (var i = 0; i < methods.length; i++)
  935. {
  936. if (FABridge.blockedMethods[methods[i]] == undefined)
  937. {
  938. this.addMethodToType(newType, methods[i]);
  939. }
  940. }
  941. this.remoteTypeCache[newType.typeName] = newType;
  942. return newType;
  943. },
  944. //add a property to a typename; used to define the properties that can be called on an AS proxied object
  945. addPropertyToType: function(ty, propName)
  946. {
  947. var c = propName.charAt(0);
  948. var setterName;
  949. var getterName;
  950. if(c >= "a" && c <= "z")
  951. {
  952. getterName = "get" + c.toUpperCase() + propName.substr(1);
  953. setterName = "set" + c.toUpperCase() + propName.substr(1);
  954. }
  955. else
  956. {
  957. getterName = "get" + propName;
  958. setterName = "set" + propName;
  959. }
  960. ty[setterName] = function(val)
  961. {
  962. this.bridge.setPropertyInAS(this.fb_instance_id, propName, val);
  963. }
  964. ty[getterName] = function()
  965. {
  966. return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
  967. }
  968. },
  969. //add a method to a typename; used to define the methods that can be callefd on an AS proxied object
  970. addMethodToType: function(ty, methodName)
  971. {
  972. ty[methodName] = function()
  973. {
  974. return this.bridge.deserialize(this.bridge.callASMethod(this.fb_instance_id, methodName, FABridge.argsToArray(arguments)));
  975. }
  976. },
  977. // Function Proxies
  978. //returns the AS proxy for the specified function ID
  979. getFunctionProxy: function(funcID)
  980. {
  981. var bridge = this;
  982. if (this.remoteFunctionCache[funcID] == null)
  983. {
  984. this.remoteFunctionCache[funcID] = function()
  985. {
  986. bridge.callASFunction(funcID, FABridge.argsToArray(arguments));
  987. }
  988. }
  989. return this.remoteFunctionCache[funcID];
  990. },
  991. //reutrns the ID of the given function; if it doesnt exist it is created and added to the local cache
  992. getFunctionID: function(func)
  993. {
  994. if (func.__bridge_id__ == undefined)
  995. {
  996. func.__bridge_id__ = this.makeID(this.nextLocalFuncID++);
  997. this.localFunctionCache[func.__bridge_id__] = func;
  998. }
  999. return func.__bridge_id__;
  1000. },
  1001. // serialization / deserialization
  1002. serialize: function(value)
  1003. {
  1004. var result = {};
  1005. var t = typeof(value);
  1006. //primitives are kept as such
  1007. if (t == "number" || t == "string" || t == "boolean" || t == null || t == undefined)
  1008. {
  1009. result = value;
  1010. }
  1011. else if (value instanceof Array)
  1012. {
  1013. //arrays are serializesd recursively
  1014. result = [];
  1015. for (var i = 0; i < value.length; i++)
  1016. {
  1017. result[i] = this.serialize(value[i]);
  1018. }
  1019. }
  1020. else if (t == "function")
  1021. {
  1022. //js functions are assigned an ID and stored in the local cache
  1023. result.type = FABridge.TYPE_JSFUNCTION;
  1024. result.value = this.getFunctionID(value);
  1025. }
  1026. else if (value instanceof ASProxy)
  1027. {
  1028. result.type = FABridge.TYPE_ASINSTANCE;
  1029. result.value = value.fb_instance_id;
  1030. }
  1031. else
  1032. {
  1033. result.type = FABridge.TYPE_ANONYMOUS;
  1034. result.value = value;
  1035. }
  1036. return result;
  1037. },
  1038. //on deserialization we always check the return for the specific error code that is used to marshall NPE's into JS errors
  1039. // the unpacking is done by returning the value on each pachet for objects/arrays
  1040. deserialize: function(packedValue)
  1041. {
  1042. var result;
  1043. var t = typeof(packedValue);
  1044. if (t == "number" || t == "string" || t == "boolean" || packedValue == null || packedValue == undefined)
  1045. {
  1046. result = this.handleError(packedValue);
  1047. }
  1048. else if (packedValue instanceof Array)
  1049. {
  1050. result = [];
  1051. for (var i = 0; i < packedValue.length; i++)
  1052. {
  1053. result[i] = this.deserialize(packedValue[i]);
  1054. }
  1055. }
  1056. else if (t == "object")
  1057. {
  1058. for(var i = 0; i < packedValue.newTypes.length; i++)
  1059. {
  1060. this.addTypeDataToCache(packedValue.newTypes[i]);
  1061. }
  1062. for (var aRefID in packedValue.newRefs)
  1063. {
  1064. this.createProxy(aRefID, packedValue.newRefs[aRefID]);
  1065. }
  1066. if (packedValue.type == FABridge.TYPE_PRIMITIVE)
  1067. {
  1068. result = packedValue.value;
  1069. }
  1070. else if (packedValue.type == FABridge.TYPE_ASFUNCTION)
  1071. {
  1072. result = this.getFunctionProxy(packedValue.value);
  1073. }
  1074. else if (packedValue.type == FABridge.TYPE_ASINSTANCE)
  1075. {
  1076. result = this.getProxy(packedValue.value);
  1077. }
  1078. else if (packedValue.type == FABridge.TYPE_ANONYMOUS)
  1079. {
  1080. result = packedValue.value;
  1081. }
  1082. }
  1083. return result;
  1084. },
  1085. //increases the reference count for the given object
  1086. addRef: function(obj)
  1087. {
  1088. this.target.incRef(obj.fb_instance_id);
  1089. },
  1090. //decrease the reference count for the given object and release it if needed
  1091. release:function(obj)
  1092. {
  1093. this.target.releaseRef(obj.fb_instance_id);
  1094. },
  1095. // check the given value for the components of the hard-coded error code : __FLASHERROR
  1096. // used to marshall NPE's into flash
  1097. handleError: function(value)
  1098. {
  1099. if (typeof(value)=="string" && value.indexOf("__FLASHERROR")==0)
  1100. {
  1101. var myErrorMessage = value.split("||");
  1102. if(FABridge.refCount > 0 )
  1103. {
  1104. FABridge.refCount--;
  1105. }
  1106. throw new Error(myErrorMessage[1]);
  1107. return value;
  1108. }
  1109. else
  1110. {
  1111. return value;
  1112. }
  1113. }
  1114. };
  1115. // The root ASProxy class that facades a flash object
  1116. ASProxy = function(bridge, typeName)
  1117. {
  1118. this.bridge = bridge;
  1119. this.typeName = typeName;
  1120. return this;
  1121. };
  1122. //methods available on each ASProxy object
  1123. ASProxy.prototype =
  1124. {
  1125. get: function(propName)
  1126. {
  1127. return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
  1128. },
  1129. set: function(propName, value)
  1130. {
  1131. this.bridge.setPropertyInAS(this.fb_instance_id, propName, value);
  1132. },
  1133. call: function(funcName, args)
  1134. {
  1135. this.bridge.callASMethod(this.fb_instance_id, funcName, args);
  1136. },
  1137. addRef: function() {
  1138. this.bridge.addRef(this);
  1139. },
  1140. release: function() {
  1141. this.bridge.release(this);
  1142. }
  1143. };
  1144. // Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
  1145. // License: New BSD License
  1146. // Reference: http://dev.w3.org/html5/websockets/
  1147. // Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
  1148. (function() {
  1149. if (window.WebSocket) return;
  1150. var console = window.console;
  1151. if (!console) console = {log: function(){ }, error: function(){ }};
  1152. function hasFlash() {
  1153. if ('navigator' in window && 'plugins' in navigator && navigator.plugins['Shockwave Flash']) {
  1154. return !!navigator.plugins['Shockwave Flash'].description;
  1155. }
  1156. if ('ActiveXObject' in window) {
  1157. try {
  1158. return !!new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
  1159. } catch (e) {}
  1160. }
  1161. return false;
  1162. }
  1163. if (!hasFlash()) {
  1164. console.error("Flash Player is not installed.");
  1165. return;
  1166. }
  1167. //console.log(location.protocol);
  1168. if (location.protocol == "file:") {
  1169. console.error(
  1170. "web-socket-js doesn't work in file:///... URL (without special configuration). " +
  1171. "Open the page via Web server i.e. http://...");
  1172. }
  1173. WebSocket = function(url, protocol, proxyHost, proxyPort, headers) {
  1174. var self = this;
  1175. self.readyState = WebSocket.CONNECTING;
  1176. self.bufferedAmount = 0;
  1177. // Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
  1178. // Otherwise, when onopen fires immediately, onopen is called before it is set.
  1179. setTimeout(function() {
  1180. WebSocket.__addTask(function() {
  1181. self.__createFlash(url, protocol, proxyHost, proxyPort, headers);
  1182. });
  1183. }, 1);
  1184. }
  1185. WebSocket.prototype.__createFlash = function(url, protocol, proxyHost, proxyPort, headers) {
  1186. var self = this;
  1187. self.__flash =
  1188. WebSocket.__flash.create(url, protocol, proxyHost || null, proxyPort || 0, headers || null);
  1189. self.__flash.addEventListener("open", function(fe) {
  1190. try {
  1191. self.readyState = self.__flash.getReadyState();
  1192. if (self.__timer) clearInterval(self.__timer);
  1193. if (window.opera) {
  1194. // Workaround for weird behavior of Opera which sometimes drops events.
  1195. self.__timer = setInterval(function () {
  1196. self.__handleMessages();
  1197. }, 500);
  1198. }
  1199. if (self.onopen) self.onopen();
  1200. } catch (e) {
  1201. console.error(e.toString());
  1202. }
  1203. });
  1204. self.__flash.addEventListener("close", function(fe) {
  1205. try {
  1206. self.readyState = self.__flash.getReadyState();
  1207. if (self.__timer) clearInterval(self.__timer);
  1208. if (self.onclose) self.onclose();
  1209. } catch (e) {
  1210. console.error(e.toString());
  1211. }
  1212. });
  1213. self.__flash.addEventListener("message", function() {
  1214. try {
  1215. self.__handleMessages();
  1216. } catch (e) {
  1217. console.error(e.toString());
  1218. }
  1219. });
  1220. self.__flash.addEventListener("error", function(fe) {
  1221. try {
  1222. if (self.__timer) clearInterval(self.__timer);
  1223. if (self.onerror) self.onerror();
  1224. } catch (e) {
  1225. console.error(e.toString());
  1226. }
  1227. });
  1228. self.__flash.addEventListener("stateChange", function(fe) {
  1229. try {
  1230. self.readyState = self.__flash.getReadyState();
  1231. self.bufferedAmount = fe.getBufferedAmount();
  1232. } catch (e) {
  1233. console.error(e.toString());
  1234. }
  1235. });
  1236. //console.log("[WebSocket] Flash object is ready");
  1237. };
  1238. WebSocket.prototype.send = function(data) {
  1239. if (this.__flash) {
  1240. this.readyState = this.__flash.getReadyState();
  1241. }
  1242. if (!this.__flash || this.readyState == WebSocket.CONNECTING) {
  1243. throw "INVALID_STATE_ERR: Web Socket connection has not been established";
  1244. }
  1245. var result = this.__flash.send(encodeURIComponent(data));
  1246. if (result < 0) { // success
  1247. return true;
  1248. } else {
  1249. this.bufferedAmount = result

Large files files are truncated, but you can click here to view the full file