omnomirc.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /*
  2. OmnomIRC COPYRIGHT 2010,2011 Netham45
  3. OmnomIRC3 rewrite COPYRIGHT 2013 Nathaniel 'Eeems' van Diepen
  4. This file is part of OmnomIRC.
  5. OmnomIRC is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. OmnomIRC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with OmnomIRC. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. (function(window,$,io,undefined){
  17. var $o = window.OmnomIRC = window.$o = function(){
  18. return 'Version: '+$o.version
  19. },
  20. event = function(msg,type){
  21. type=typeof type == 'undefined'?'event':type;
  22. switch(type){
  23. case 'ready':type='document_ready';break;
  24. }
  25. log('['+type.toUpperCase()+'] '+msg);
  26. },
  27. log = function(){
  28. console.log.apply(console,arguments);
  29. },
  30. exists = function(object){
  31. return typeof object != 'undefined';
  32. },
  33. prevent = function(e){
  34. e.stopImmediatePropagation();
  35. e.stopPropagation();
  36. e.preventDefault();
  37. return false;
  38. },
  39. selectedTab=0,
  40. settings = {
  41. colour: false,
  42. timestamp: 'exact',
  43. server: location.origin,
  44. autoconnect: true,
  45. autojoin: [
  46. '#omnimaga',
  47. '#omnimaga-fr',
  48. '#irp'
  49. ],
  50. scrollspeed: 100,
  51. theme: 'default',
  52. nick: 'User'
  53. },
  54. tabs = [],
  55. properties = {
  56. nick: 'User',
  57. sig: '',
  58. tabs: tabs,
  59. themes: [
  60. 'default'
  61. ]
  62. },
  63. commands = [
  64. { // names
  65. cmd: 'names',
  66. fn: function(args){
  67. socket.emit('names',{
  68. name: tabs[selectedTab].name
  69. });
  70. }
  71. },
  72. { // me
  73. cmd: 'me',
  74. help: 'Say something in third person',
  75. fn: function(args){
  76. var i,ret='';
  77. for(i=1;i<args.length;i++){
  78. ret += ' '+args[i];
  79. }
  80. socket.emit('message',{
  81. from: 0,
  82. message: properties.nick+' '+ret,
  83. room: tabs[selectedTab].name
  84. });
  85. }
  86. },
  87. { // connect
  88. cmd: 'connect',
  89. fn: function(){
  90. if(!$o.connected()){
  91. $o.connect();
  92. }
  93. }
  94. },
  95. { // disconnect
  96. cmd: 'disconnect',
  97. fn: function(){
  98. $o.disconnect();
  99. }
  100. },
  101. { // nick
  102. cmd: 'nick',
  103. fn: function(args){
  104. $o.set('nick',args[1]);
  105. }
  106. },
  107. { // help
  108. cmd: 'help',
  109. fn: function(args){
  110. if(typeof args[1] == 'undefined'){
  111. var m = 'Commands:',i;
  112. for(i in commands){
  113. m += ' '+commands[i].cmd;
  114. }
  115. $o.msg(m);
  116. }else{
  117. var i,cmd;
  118. for(i in commands){
  119. cmd = commands[i];
  120. if(cmd.cmd == args[1] && typeof cmd.help != 'undefined'){
  121. $o.msg('Command /'+cmd.cmd+': '+cmd.help);
  122. return;
  123. }
  124. }
  125. $o.send('/help');
  126. }
  127. }
  128. },
  129. { // open
  130. cmd: 'open',
  131. fn: function(args){
  132. $o.addTab(args[1]);
  133. }
  134. },
  135. { // clear
  136. cmd: 'clear',
  137. fn: function(args){
  138. $cl.html('');
  139. tabs[selectedTab].body = document.createDocumentFragment();
  140. socket.emit('echo',{
  141. room: tabs[selectedTab].name,
  142. message: 'messages cleared',
  143. name: 0
  144. });
  145. }
  146. },
  147. { // close
  148. cmd: 'close',
  149. fn: function(args){
  150. if(args.length > 1){
  151. $o.removeTab(args[1]);
  152. }else{
  153. $o.removeTab(selectedTab);
  154. }
  155. }
  156. },
  157. { // tabs
  158. cmd: 'tabs',
  159. fn: function(args){
  160. $o.msg('tabs:');
  161. for(var i in tabs){
  162. $o.msg(' ['+i+'] '+tabs[i].name);
  163. }
  164. }
  165. }
  166. ],
  167. handles = [
  168. { // names
  169. on: 'names',
  170. fn: function(data){
  171. tabs[$o.tabIdForName(data.room)].users = data.names;
  172. if($o.tabIdForName(data.room) == selectedTab){
  173. $o.renderUsers();
  174. }
  175. }
  176. },
  177. { // authorized
  178. on: 'authorized',
  179. fn: function(data){
  180. properties.nick = data.nick;
  181. for(var i in settings.autojoin){
  182. socket.emit('join',{
  183. name: settings.autojoin[i]
  184. });
  185. }
  186. }
  187. },
  188. { // join
  189. on: 'join',
  190. fn: function(data){
  191. event('joined '+data.name);
  192. var flag = tabs.length == 0;
  193. $o.addTab(data.name);
  194. if(flag){
  195. $o.selectTab(0);
  196. }
  197. }
  198. },
  199. { // reconnect
  200. on: 'reconnect',
  201. fn: function(data){
  202. event('reconnected');
  203. $o.auth();
  204. }
  205. },
  206. { // message
  207. on: 'message',
  208. fn: function(data){
  209. event('recieved message');
  210. var date = new Date(),
  211. string,
  212. time = date.getTime(),
  213. child,
  214. i,
  215. msg = function(msg){
  216. string = '<span class="cell date_cell">[<abbr class="date date_'+time+'" title="'+date.toISOString()+'"></abbr>]</span>';
  217. child = $('<li>').html(string+'<span class="cell">'+
  218. msg
  219. .htmlentities()
  220. .replace(
  221. /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/g,
  222. "<a href=\"$1\" title=\"\">$1</a>"
  223. )
  224. +'</span>');
  225. $o.msg({html:child},data.room);
  226. };
  227. if(data.from != 0){
  228. msg(' <'+data.from+'> '+data.message);
  229. }else{
  230. msg(' * '+data.message);
  231. }
  232. abbrDate('abbr.date_'+time);
  233. if(settings.timestamp == ''){
  234. $('.date_cell').css('visibility','hidden');
  235. }else{
  236. $('.date_cell').css('visibility','visible');
  237. }
  238. }
  239. }
  240. ],
  241. hooks = [
  242. {
  243. type: 'style',
  244. hook: 'load',
  245. fn: function(){
  246. }
  247. }
  248. ],
  249. abbrDate = function(selector){
  250. if(settings.timestamp == 'fuzzy'){
  251. $(selector).timeago();
  252. }else{
  253. $(selector).each(function(){
  254. var timestamp = settings.timestamp,
  255. i,
  256. text='',
  257. date = new Date($(this).attr('title'));
  258. if(timestamp == 'exact'){
  259. timestamp = 'H:m:s t';
  260. }
  261. for(i=0;i<timestamp.length;i++){
  262. switch(timestamp[i]){
  263. case 'H':text+=((date.getHours()+11)%12)+1;break;
  264. case 'h':text+=date.getHours();break;
  265. case 'm':text+=(date.getMinutes()>9?'':'0')+date.getMinutes();break;
  266. case 's':text+=(date.getSeconds()>9?'':'0')+date.getSeconds();break;
  267. case 't':text+=(date.getHours()>11)?'pm':'am';break;
  268. default:text+=timestamp[i];
  269. }
  270. }
  271. $(this).text(text);
  272. }).timeago('dispose');
  273. }
  274. },
  275. socket,$i,$s,$h,$cl,$tl,hht;
  276. $.extend($o,{
  277. version: '3.0',
  278. register: {
  279. theme: function(name){
  280. if(-1==$.inArray(properties.themes,name)){
  281. properties.themes.push(name);
  282. return true;
  283. }
  284. return false;
  285. },
  286. command: function(name,fn,help){
  287. if(-1==$.inArray(commands,name)){
  288. var o = {
  289. cmd: name,
  290. fn: fn
  291. };
  292. if(typeof help != 'undefined'){
  293. o.help = help;
  294. }
  295. commands.push(o);
  296. return true;
  297. }
  298. return false;
  299. },
  300. plugin: function(){
  301. }
  302. },
  303. connect: function(server){
  304. if($o.connected()){
  305. $o.disconnect();
  306. }
  307. if(typeof server == 'undefined'){
  308. server = settings.server;
  309. }
  310. socket = io.connect(server);
  311. for(var i in handles){
  312. socket.on(handles[i].on,handles[i].fn);
  313. }
  314. $o.auth();
  315. },
  316. disconnect: function(){
  317. if($o.connected()){
  318. socket.disconnect();
  319. socket = undefined;
  320. }
  321. },
  322. auth: function(){
  323. if(settings.nick == ''){
  324. $o.set('nick','User');
  325. return;
  326. }
  327. socket.emit('auth',{
  328. nick: settings.nick
  329. // TODO - send authorization info
  330. });
  331. },
  332. connected: function(){
  333. return typeof socket != 'undefined';
  334. },
  335. get: function(name,formatted){
  336. if(typeof formatted == 'undefined'){
  337. return exists(settings[name])?settings[name]:false;
  338. }else{
  339. var val = $o.get(name),
  340. type,
  341. values = false;
  342. switch(name){
  343. case 'theme':
  344. type = 'select';
  345. values = properties.themes;
  346. break;
  347. case 'autojoin':type = 'array';break;
  348. case 'timestamp':type = 'string';break;
  349. default:
  350. type = typeof val;
  351. }
  352. return {
  353. type: type,
  354. val: val,
  355. values: values,
  356. name: name
  357. };
  358. }
  359. },
  360. set: function(name,value,render){
  361. if(exists(settings[name])){
  362. settings[name] = value;
  363. $.localStorage('settings',JSON.stringify(settings));
  364. switch(name){
  365. case 'timestamp':
  366. abbrDate('abbr.date');
  367. if(settings.timestamp == ''){
  368. $('.date_cell').css('visibility','hidden');
  369. }else{
  370. $('.date_cell').css('visibility','visible');
  371. }
  372. break;
  373. case 'nick':
  374. $o.auth();
  375. break;
  376. }
  377. if(typeof render == 'undefined'){
  378. $o.renderSettings();
  379. }
  380. return true;
  381. }else{
  382. return false;
  383. }
  384. },
  385. renderSettings: function(){
  386. var name,setting,frag = document.createDocumentFragment(),item;
  387. for(name in settings){
  388. setting = $o.get(name,true);
  389. switch(setting.type){
  390. case 'select':
  391. item = $('<select>')
  392. .attr('id','setting_'+name)
  393. .change(function(){
  394. $o.set(this.id.substr(8),$(this).find(':selected').text(),false);
  395. });
  396. for(var i in setting.values){
  397. item.append(
  398. $('<option>')
  399. .text(setting.values[i])
  400. );
  401. }
  402. item.find(':contains('+setting.val+')').attr('selected','selected');
  403. break;
  404. case 'array':
  405. item = $('<input>')
  406. .attr({
  407. type: 'text',
  408. id: 'setting_'+name
  409. })
  410. .val(setting.val)
  411. .change(function(){
  412. $o.set(this.id.substr(8),$(this).val().split(','),false);
  413. });
  414. break;
  415. case 'boolean':
  416. item = $('<input>')
  417. .attr({
  418. type: 'checkbox',
  419. id: 'setting_'+name
  420. })
  421. .change(function(){
  422. $o.set(this.id.substr(8),$(this).is(':checked'),false);
  423. });
  424. if(setting.val){
  425. item.attr('checked','checked');
  426. }
  427. break;
  428. case 'number':
  429. case 'string':default:
  430. item = $('<input>')
  431. .attr({
  432. type: 'text',
  433. id: 'setting_'+name
  434. })
  435. .val(setting.val)
  436. .change(function(){
  437. $o.set(this.id.substr(8),$(this).val(),false);
  438. });
  439. }
  440. $(frag).append(
  441. $('<li>')
  442. .addClass('row')
  443. .append(
  444. $('<span>')
  445. .text(name)
  446. .addClass('cell')
  447. )
  448. .append(
  449. $('<span>')
  450. .append(item)
  451. .addClass('cell')
  452. )
  453. );
  454. }
  455. $('#settings-list').html(frag);
  456. },
  457. renderUsers: function(){
  458. event('Rendering userlist');
  459. var $ul = $('#user-list').html(''),
  460. i,
  461. names = tabs[selectedTab].users;
  462. for(i in names){
  463. $ul.append(
  464. $('<li>').text(names[i])
  465. );
  466. }
  467. },
  468. selectedTab: function(){
  469. return selectedTab;
  470. },
  471. prop: function(name){
  472. return exists(properties[name])?properties[name]:null;
  473. },
  474. send: function(msg){
  475. if(msg !== ''){
  476. if(msg[0] == '/' && msg[1] != '/'){
  477. var args = msg.split(' '),
  478. cmd = args[0].substr(1),
  479. i;
  480. event(msg,'command');
  481. for(i in commands){
  482. if(commands[i].cmd == cmd){
  483. commands[i].fn(args);
  484. return;
  485. }
  486. }
  487. $o.msg(cmd+' is not a valid command.');
  488. }else{
  489. event(msg,'send');
  490. socket.emit('message',{
  491. message: msg,
  492. room: tabs[selectedTab].name,
  493. from: properties.nick
  494. });
  495. }
  496. }
  497. },
  498. msg: function(msg,tabName){
  499. var frag;
  500. if(typeof tabName == 'undefined' || tabName == tabs[selectedTab].name){
  501. frag = document.createDocumentFragment();
  502. }else{
  503. frag = tabs[$o.tabIdForName(tabName)].body;
  504. }
  505. switch(typeof msg){
  506. case 'string':
  507. $(frag).append($('<li>').html(msg.htmlentities()));
  508. break;
  509. case 'object':
  510. if(typeof msg.html == 'undefined'){
  511. $(frag).append($('<li>').html('&lt;'+msg.user+'&gt;&nbsp;'+msg.text.htmlentities()));
  512. }else{
  513. $(frag).append(msg.html);
  514. }
  515. break;
  516. }
  517. $(tabs[$o.tabIdForName(tabName) || selectedTab].body).append(frag);
  518. var scroll = [],i,html;
  519. for(i in tabs){
  520. html = '';
  521. $(tabs[i].body).children().each(function(){
  522. html += this.outerHTML;
  523. });
  524. scroll.push({
  525. name: tabs[i].name,
  526. body: html,
  527. date: new Date().toString()
  528. });
  529. }
  530. $.localStorage('tabs',scroll);
  531. if(typeof tabName == 'undefined' || tabName == tabs[selectedTab].name){
  532. $o.selectTab(selectedTab);
  533. }
  534. },
  535. event: function(event_name,message){
  536. event(message,event_name);
  537. },
  538. selectTab: function(id){
  539. event(id+' '+tabs[id].name,'tab_select');
  540. if(id<tabs.length&&id>=0){
  541. selectedTab=id;
  542. }
  543. $tl.children('.clicked').removeClass('clicked');
  544. $($tl.children().get(id)).addClass('clicked');
  545. $('#title').text(tabs[id].name);
  546. $('#topic').text(tabs[id].topic);
  547. $cl.html($(tabs[id].body).clone());
  548. abbrDate('abbr.date');
  549. $o.renderUsers();
  550. setTimeout(function scrollContent(){
  551. if($c.scrollTop() < $c[0].scrollHeight){
  552. $c.scrollTop($c.scrollTop()+1);
  553. setTimeout(scrollContent,settings.scrollspeed);
  554. }else{
  555. event('scrolling stopped');
  556. }
  557. },settings.scrollspeed);
  558. },
  559. tabIdForName: function(name){
  560. for(var i in tabs){
  561. if(tabs[i].name == name){
  562. return i;
  563. }
  564. }
  565. return false;
  566. },
  567. tabDOM: function(id){
  568. return tabs[id].body;
  569. },
  570. addTab: function(name){
  571. event('Tab added: '+name);
  572. if(!(function(){
  573. for(var i in tabs){
  574. if(name==tabs[i].name){
  575. return true;
  576. }
  577. }
  578. return false;
  579. })()){
  580. var scroll = $.localStorage('tabs'),
  581. i,
  582. frag = document.createDocumentFragment(),
  583. id = tabs.length;
  584. for(i in scroll){
  585. if(scroll[i].name == name){
  586. scroll[i].body = $(scroll[i].body).slice(-10);
  587. $(frag)
  588. .append(scroll[i].body)
  589. .append(
  590. $('<li>').html('<span class="to_remove">-- loaded old scrollback for '+scroll[i].date+' --</span>')
  591. )
  592. .children()
  593. .children('.remove')
  594. .remove();
  595. $(frag)
  596. .children()
  597. .children('.to_remove')
  598. .removeClass('to_remove')
  599. .addClass('remove');
  600. event('loading old tab scrollback for '+name+' last saved +'+scroll[i].date);
  601. }
  602. }
  603. tabs.push({
  604. name: name,
  605. body: frag,
  606. users: [],
  607. close: function(){
  608. $o.removeTab(id);
  609. }
  610. });
  611. $tl.append($o.tabObj(id));
  612. $o.refreshTabs();
  613. $o.renderUsers();
  614. }else{
  615. event('Attempted to add an existing tab');
  616. }
  617. },
  618. removeTab: function(id){
  619. if(typeof tabs[id] != 'undefined'){
  620. event('Tab removed: '+tabs[id].name);
  621. socket.emit('part',{
  622. name: tabs[id].name
  623. });
  624. tabs.splice(id,1);
  625. if(selectedTab==id&&selectedTab>0){
  626. selectedTab--;
  627. }
  628. }
  629. $o.refreshTabs();
  630. $cl.html(tabs[selectedTab].body);
  631. $o.renderUsers();
  632. },
  633. tabObj: function(id){
  634. if(typeof id !== 'undefined'){
  635. return $('<div>')
  636. .addClass('tab')
  637. .text(tabs[id].name)
  638. .mouseup(function(e){
  639. switch(e.which){
  640. case 1: // RMB
  641. if($(this).data('id')!=selectedTab){
  642. $o.selectTab($(this).data('id'));
  643. return prevent(e);
  644. }
  645. break;
  646. case 2: // MMB
  647. $(this).children('span.close-button').click();
  648. return prevent(e);
  649. break;
  650. case 3: // LMB
  651. return prevent(e);
  652. break;
  653. default:
  654. return prevent(e);
  655. }
  656. })
  657. .append(
  658. $('<span>')
  659. .addClass('close-button')
  660. .click(function(){
  661. $o.removeTab(id);
  662. return false;
  663. })
  664. .css({
  665. 'position': 'absolute',
  666. 'background-color': 'inherit',
  667. 'top': 0,
  668. 'right': 0
  669. })
  670. .html('&times;')
  671. )
  672. .data('id',id);
  673. }
  674. },
  675. refreshTabs: function(){
  676. $tl.html('');
  677. var i,tab;
  678. for(i in tabs){
  679. tab = $o.tabObj(i);
  680. if(i==selectedTab){
  681. tab.addClass('clicked');
  682. $('#title').text(tabs[i].name);
  683. $('#topic').text(tabs[i].topic);
  684. }
  685. $tl.append(tab);
  686. }
  687. if($tl.get(0).scrollHeight-20 != $tl.scrollTop()){
  688. $('#tabs-scroll-right').removeClass('disabled');
  689. }
  690. if($tl.scrollTop() != 0){
  691. $('#tabs-scroll-left').removeClass('disabled');
  692. }
  693. }
  694. });
  695. String.prototype.htmlentities = function(){
  696. return this
  697. .replace(/&/g, '&amp;')
  698. .replace(/</g, '&lt;')
  699. .replace(/>/g, '&gt;')
  700. .replace(/\n/g,'<br/>')
  701. .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;')
  702. .replace(/\s/g, '&nbsp;')
  703. .replace(/"/g, '&quot;');
  704. };
  705. $(document).ready(function(){
  706. $.extend(settings,$.parseJSON($.localStorage('settings')));
  707. $.localStorage('settings',JSON.stringify(settings));
  708. $i = $('#input');
  709. $s = $('#send');
  710. $cl = $('#content-list');
  711. $c = $('#content');
  712. $tl = $('#tabs-list');
  713. $h = $('#head');
  714. $s.click(function(){
  715. if(!$s.hasClass('clicked')){
  716. $s.addClass('clicked');
  717. setTimeout(function(){
  718. $s.removeClass('clicked');
  719. },500);
  720. }
  721. $o.send($i.val());
  722. $i.val('');
  723. });
  724. $i.keypress(function(e){
  725. if(e.keyCode == 13){
  726. if(!$s.hasClass('clicked')){
  727. $s.addClass('clicked');
  728. setTimeout(function(){
  729. $s.removeClass('clicked');
  730. },500);
  731. }
  732. $o.send($i.val());
  733. $i.val('');
  734. }
  735. });
  736. $('#settings, #users').click(function(){
  737. $(this).addClass('open');
  738. $(this).children('.close-button').show();
  739. }).hover(function(){
  740. $(this).addClass('hovered');
  741. },function(){
  742. $(this).removeClass('hovered');
  743. }).children('.close-button').click(function(){
  744. $(this).parent().removeClass('open');
  745. $(this).hide();
  746. return false;
  747. }).hide();
  748. $('#users').hoverIntent({
  749. out: function(){
  750. $(this).removeClass('open');
  751. $(this).children('.close-button').hide();
  752. },
  753. timeout: 1000
  754. });
  755. $('#content').click(function(){
  756. $('#settings, #users, #head').removeClass('hovered').removeClass('open');
  757. $('#settings, #users').children('.close-button').hide()
  758. });
  759. $('.unselectable').attr('unselectable','on');
  760. $.contextMenu({
  761. selector: 'div.tab',
  762. items: {
  763. add: {
  764. name: 'New Tab',
  765. icon: 'add',
  766. callback: function(){
  767. $(this).contextMenu('hide');
  768. $o.addTab(prompt('Channel'));
  769. }
  770. },
  771. s1: '',
  772. close: {
  773. name: 'Close',
  774. icon: 'delete',
  775. callback: function(){
  776. $(this).contextMenu('hide');
  777. $o.removeTab($(this).data('id'));
  778. }
  779. }
  780. },
  781. zIndex: 99999,
  782. trigger: 'right'
  783. });
  784. $.contextMenu({
  785. selector: '#tabs-list',
  786. items: {
  787. add: {
  788. name: 'New Tab',
  789. icon: 'add',
  790. callback: function(){
  791. $(this).contextMenu('hide');
  792. $o.addTab(prompt('channel'));
  793. }
  794. }
  795. },
  796. zIndex: 99999,
  797. trigger: 'right'
  798. });
  799. $('#tabs-scroll-right').click(function(){
  800. event('scroll right');
  801. $tl.scrollTop(($tl.scrollTop()||0)+20);
  802. if($tl.get(0).scrollHeight-20 == $tl.scrollTop()){
  803. $('#tabs-scroll-right').addClass('disabled');
  804. }
  805. $('#tabs-scroll-left').removeClass('disabled');
  806. });
  807. $('#tabs-scroll-left').click(function(){
  808. event('scroll left');
  809. $tl.scrollTop(($tl.scrollTop()||0)-20);
  810. if($tl.scrollTop() == 0){
  811. $('#tabs-scroll-left').addClass('disabled');
  812. }
  813. $('#tabs-scroll-right').removeClass('disabled');
  814. });
  815. (function scrollup(){
  816. $('#tabs-scroll-left').click();
  817. if($tl.scrollTop() != 0){
  818. setTimeout(scrollup,10);
  819. }
  820. })();
  821. //DEBUG
  822. /* for(var i=0;i<20;i++){
  823. tabs.push({
  824. name: '#Tab'+i,
  825. title: 'Tab '+i,
  826. topic: 'Topic for tab '+i
  827. });
  828. } */
  829. //END DEBUG
  830. event('Date '+new Date,'ready');
  831. $h.addClass('hovered');
  832. setTimeout(function(){
  833. $h.removeClass('hovered');
  834. },1000);
  835. $o.renderSettings();
  836. if(settings.autoconnect){
  837. $o.connect();
  838. }
  839. });
  840. delete window.io;
  841. })(window,jQuery,io);
  842. if (!Date.prototype.toISOString) {
  843. Date.prototype.toISOString = function() {
  844. function pad(n) { return n < 10 ? '0' + n : n }
  845. return this.getUTCFullYear() + '-'
  846. + pad(this.getUTCMonth() + 1) + '-'
  847. + pad(this.getUTCDate()) + 'T'
  848. + pad(this.getUTCHours()) + ':'
  849. + pad(this.getUTCMinutes()) + ':'
  850. + pad(this.getUTCSeconds()) + 'Z';
  851. };
  852. }