omnomirc.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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. {
  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. {
  130. cmd: 'open',
  131. fn: function(args){
  132. tabs.push({
  133. name: args[1],
  134. title: args[2],
  135. topic: 'Topic for '+args[2]
  136. });
  137. $o.refreshTabs();
  138. }
  139. },
  140. { // clear
  141. cmd: 'clear',
  142. fn: function(args){
  143. $cl.html('');
  144. tabs[selectedTab].body = document.createDocumentFragment();
  145. socket.emit('echo',{
  146. room: tabs[selectedTab].name,
  147. message: 'messages cleared',
  148. name: 0
  149. });
  150. }
  151. },
  152. { // close
  153. cmd: 'close',
  154. fn: function(args){
  155. if(args.length > 1){
  156. $o.removeTab(args[1]);
  157. }else{
  158. $o.removeTab(selectedTab);
  159. }
  160. }
  161. },
  162. { // tabs
  163. cmd: 'tabs',
  164. fn: function(args){
  165. $o.msg('tabs:');
  166. for(var i in tabs){
  167. $o.msg(' ['+i+'] '+tabs[i].name);
  168. }
  169. }
  170. }
  171. ],
  172. handles = [
  173. {
  174. on: 'names',
  175. fn: function(data){
  176. tabs[$o.tabIdForName(data.room)].names = data.names;
  177. if($o.tabIdForName(data.room) == selectedTab){
  178. $o.renderUsers();
  179. }
  180. }
  181. },
  182. {
  183. on: 'authorized',
  184. fn: function(data){
  185. properties.nick = data.nick;
  186. for(var i in settings.autojoin){
  187. socket.emit('join',{
  188. name: settings.autojoin[i]
  189. });
  190. }
  191. }
  192. },
  193. {
  194. on: 'join',
  195. fn: function(data){
  196. event('joined '+data.name);
  197. var flag = tabs.length == 0;
  198. $o.addTab(data.name,data.title);
  199. if(flag){
  200. $o.selectTab(0);
  201. }
  202. }
  203. },
  204. {
  205. on: 'reconnect',
  206. fn: function(data){
  207. event('reconnected');
  208. $o.auth();
  209. }
  210. },
  211. {
  212. on: 'message',
  213. fn: function(data){
  214. event('recieved message');
  215. var date = new Date(),
  216. string,
  217. time = date.getTime(),
  218. child,
  219. i,
  220. msg = function(msg){
  221. string = '<span class="cell date_cell">[<abbr class="date date_'+time+'" title="'+date.toISOString()+'"></abbr>]</span>';
  222. child = $('<li>').html(string+'<span class="cell">'+msg.htmlentities().replace(
  223. /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/g,
  224. "<a href=\"$1\" title=\"\">$1</a>"
  225. )+'</span>');
  226. $o.msg({html:child},data.room);
  227. };
  228. if(data.from != 0){
  229. msg(' <'+data.from+'> '+data.message);
  230. }else{
  231. msg(' * '+data.message);
  232. }
  233. abbrDate('abbr.date_'+time);
  234. if(settings.timestamp == ''){
  235. $('.date_cell').css('visibility','hidden');
  236. }else{
  237. $('.date_cell').css('visibility','visible');
  238. }
  239. }
  240. }
  241. ],
  242. hooks = [
  243. {
  244. type: 'style',
  245. hook: 'load',
  246. fn: function(){
  247. }
  248. }
  249. ],
  250. abbrDate = function(selector){
  251. if(settings.timestamp == 'fuzzy'){
  252. $(selector).timeago();
  253. }else{
  254. $(selector).each(function(){
  255. var timestamp = settings.timestamp,
  256. i,
  257. text='',
  258. date = new Date($(this).attr('title'));
  259. if(timestamp == 'exact'){
  260. timestamp = 'H:m:s t';
  261. }
  262. for(i=0;i<timestamp.length;i++){
  263. switch(timestamp[i]){
  264. case 'H':text+=((date.getHours()+11)%12)+1;break;
  265. case 'h':text+=date.getHours();break;
  266. case 'm':text+=(date.getMinutes()>9?'':'0')+date.getMinutes();break;
  267. case 's':text+=(date.getSeconds()>9?'':'0')+date.getSeconds();break;
  268. case 't':text+=(date.getHours()>11)?'pm':'am';break;
  269. default:text+=timestamp[i];
  270. }
  271. }
  272. $(this).text(text);
  273. }).timeago('dispose');
  274. }
  275. },
  276. socket,$i,$s,$h,$cl,$tl,hht;
  277. $.extend($o,{
  278. version: '3.0',
  279. register: {
  280. theme: function(name){
  281. if(-1==$.inArray(properties.themes,name)){
  282. properties.themes.push(name);
  283. return true;
  284. }
  285. return false;
  286. },
  287. command: function(name,fn,help){
  288. if(-1==$.inArray(commands,name)){
  289. var o = {
  290. cmd: name,
  291. fn: fn
  292. };
  293. if(typeof help != 'undefined'){
  294. o.help = help;
  295. }
  296. commands.push(o);
  297. return true;
  298. }
  299. return false;
  300. },
  301. plugin: function(){
  302. }
  303. },
  304. connect: function(server){
  305. if($o.connected()){
  306. $o.disconnect();
  307. }
  308. if(typeof server == 'undefined'){
  309. server = settings.server;
  310. }
  311. socket = io.connect(server);
  312. for(var i in handles){
  313. socket.on(handles[i].on,handles[i].fn);
  314. }
  315. $o.auth();
  316. },
  317. disconnect: function(){
  318. if($o.connected()){
  319. socket.disconnect();
  320. socket = undefined;
  321. }
  322. },
  323. auth: function(){
  324. if(settings.nick == ''){
  325. $o.set('nick','User');
  326. return;
  327. }
  328. socket.emit('auth',{
  329. nick: settings.nick
  330. // TODO - send authorization info
  331. });
  332. },
  333. connected: function(){
  334. return typeof socket != 'undefined';
  335. },
  336. get: function(name,formatted){
  337. if(typeof formatted == 'undefined'){
  338. return exists(settings[name])?settings[name]:false;
  339. }else{
  340. var val = $o.get(name),
  341. type,
  342. values = false;
  343. switch(name){
  344. case 'theme':
  345. type = 'select';
  346. values = properties.themes;
  347. break;
  348. case 'autojoin':type = 'array';break;
  349. case 'timestamp':type = 'string';break;
  350. default:
  351. type = typeof val;
  352. }
  353. return {
  354. type: type,
  355. val: val,
  356. values: values,
  357. name: name
  358. };
  359. }
  360. },
  361. set: function(name,value,render){
  362. if(exists(settings[name])){
  363. settings[name] = value;
  364. $.localStorage('settings',JSON.stringify(settings));
  365. switch(name){
  366. case 'timestamp':
  367. abbrDate('abbr.date');
  368. if(settings.timestamp == ''){
  369. $('.date_cell').css('visibility','hidden');
  370. }else{
  371. $('.date_cell').css('visibility','visible');
  372. }
  373. break;
  374. case 'nick':
  375. $o.auth();
  376. break;
  377. }
  378. if(typeof render == 'undefined'){
  379. $o.renderSettings();
  380. }
  381. return true;
  382. }else{
  383. return false;
  384. }
  385. },
  386. renderSettings: function(){
  387. var name,setting,frag = document.createDocumentFragment(),item;
  388. for(name in settings){
  389. setting = $o.get(name,true);
  390. switch(setting.type){
  391. case 'select':
  392. item = $('<select>')
  393. .attr('id','setting_'+name)
  394. .change(function(){
  395. $o.set(this.id.substr(8),$(this).find(':selected').text(),false);
  396. });
  397. for(var i in setting.values){
  398. item.append(
  399. $('<option>')
  400. .text(setting.values[i])
  401. );
  402. }
  403. item.find(':contains('+setting.val+')').attr('selected','selected');
  404. break;
  405. case 'array':
  406. item = $('<input>')
  407. .attr({
  408. type: 'text',
  409. id: 'setting_'+name
  410. })
  411. .val(setting.val)
  412. .change(function(){
  413. $o.set(this.id.substr(8),$(this).val().split(','),false);
  414. });
  415. break;
  416. case 'boolean':
  417. item = $('<input>')
  418. .attr({
  419. type: 'checkbox',
  420. id: 'setting_'+name
  421. })
  422. .change(function(){
  423. $o.set(this.id.substr(8),$(this).is(':checked'),false);
  424. });
  425. if(setting.val){
  426. item.attr('checked','checked');
  427. }
  428. break;
  429. case 'number':
  430. case 'string':default:
  431. item = $('<input>')
  432. .attr({
  433. type: 'text',
  434. id: 'setting_'+name
  435. })
  436. .val(setting.val)
  437. .change(function(){
  438. $o.set(this.id.substr(8),$(this).val(),false);
  439. });
  440. }
  441. $(frag).append(
  442. $('<li>')
  443. .addClass('row')
  444. .append(
  445. $('<span>')
  446. .text(name)
  447. .addClass('cell')
  448. )
  449. .append(
  450. $('<span>')
  451. .append(item)
  452. .addClass('cell')
  453. )
  454. );
  455. }
  456. $('#settings-list').html(frag);
  457. },
  458. renderUsers: function(){
  459. event('Rendering userlist');
  460. var $ul = $('#user-list').html(''),
  461. i,
  462. names = tabs[selectedTab].names;
  463. for(i in names){
  464. $ul.append(
  465. $('<li>').text(names[i])
  466. );
  467. }
  468. },
  469. selectedTab: function(){
  470. return selectedTab;
  471. },
  472. prop: function(name){
  473. return exists(properties[name])?properties[name]:null;
  474. },
  475. send: function(msg){
  476. if(msg !== ''){
  477. if(msg[0] == '/' && msg[1] != '/'){
  478. var args = msg.split(' '),
  479. cmd = args[0].substr(1),
  480. i;
  481. event(msg,'command');
  482. for(i in commands){
  483. if(commands[i].cmd == cmd){
  484. commands[i].fn(args);
  485. return;
  486. }
  487. }
  488. $o.msg(cmd+' is not a valid command.');
  489. }else{
  490. event(msg,'send');
  491. socket.emit('message',{
  492. message: msg,
  493. room: tabs[selectedTab].name,
  494. from: properties.nick
  495. });
  496. }
  497. }
  498. },
  499. msg: function(msg,tabName){
  500. var frag;
  501. if(typeof tabName == 'undefined' || tabName == tabs[selectedTab].name){
  502. frag = document.createDocumentFragment();
  503. }else{
  504. frag = tabs[$o.tabIdForName(tabName)].body;
  505. }
  506. switch(typeof msg){
  507. case 'string':
  508. $(frag).append($('<li>').html(msg.htmlentities()));
  509. break;
  510. case 'object':
  511. if(typeof msg.html == 'undefined'){
  512. $(frag).append($('<li>').html('&lt;'+msg.user+'&gt;&nbsp;'+msg.text.htmlentities()));
  513. }else{
  514. $(frag).append(msg.html);
  515. }
  516. break;
  517. }
  518. $(tabs[$o.tabIdForName(tabName) || selectedTab].body).append(frag);
  519. var scroll = [],i,html;
  520. for(i in tabs){
  521. html = '';
  522. $(tabs[i].body).children().each(function(){
  523. html += this.outerHTML;
  524. });
  525. scroll.push({
  526. name: tabs[i].name,
  527. body: html,
  528. date: new Date().toString()
  529. });
  530. }
  531. $.localStorage('tabs',scroll);
  532. if(typeof tabName == 'undefined' || tabName == tabs[selectedTab].name){
  533. $o.selectTab(selectedTab);
  534. }
  535. },
  536. event: function(event_name,message){
  537. event(message,event_name);
  538. },
  539. selectTab: function(id){
  540. event(id+' '+tabs[id].name,'tab_select');
  541. if(id<tabs.length&&id>=0){
  542. selectedTab=id;
  543. }
  544. $tl.children('.clicked').removeClass('clicked');
  545. $($tl.children().get(id)).addClass('clicked');
  546. $('#title').text(tabs[id].title);
  547. $('#topic').text(tabs[id].topic);
  548. $cl.html($(tabs[id].body).clone());
  549. abbrDate('abbr.date');
  550. $o.renderUsers();
  551. setTimeout(function scrollContent(){
  552. if($c.scrollTop() < $c[0].scrollHeight){
  553. $c.scrollTop($c.scrollTop()+1);
  554. setTimeout(scrollContent,settings.scrollspeed);
  555. }else{
  556. event('scrolling stopped');
  557. }
  558. },settings.scrollspeed);
  559. },
  560. tabIdForName: function(name){
  561. for(var i in tabs){
  562. if(tabs[i].name == name){
  563. return i;
  564. }
  565. }
  566. return false;
  567. },
  568. tabDOM: function(id){
  569. return tabs[id].body;
  570. },
  571. addTab: function(name,title){
  572. event('Tab added: '+name+' with title '+title);
  573. if(!(function(){
  574. for(var i in tabs){
  575. if(name==tabs[i].name){
  576. return true;
  577. }
  578. }
  579. return false;
  580. })()){
  581. var scroll = $.localStorage('tabs'),
  582. i,
  583. frag = document.createDocumentFragment();
  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. title: title,
  606. body: frag,
  607. names: []
  608. });
  609. $tl.append($o.tabObj(tabs.length-1));
  610. $o.refreshTabs();
  611. $o.renderUsers();
  612. }else{
  613. event('Attempted to add an existing tab');
  614. }
  615. },
  616. removeTab: function(id){
  617. if(typeof tabs[id] != 'undefined'){
  618. event('Tab removed: '+tabs[id].name);
  619. socket.emit('part',{
  620. name: tabs[id].name
  621. });
  622. tabs.splice(id,1);
  623. if(selectedTab==id&&selectedTab>0){
  624. selectedTab--;
  625. }
  626. }
  627. $o.refreshTabs();
  628. $cl.html(tabs[selectedTab].body);
  629. $o.renderUsers();
  630. },
  631. tabObj: function(id){
  632. if(typeof id !== 'undefined'){
  633. return $('<div>')
  634. .addClass('tab')
  635. .text(tabs[id].title)
  636. .mouseup(function(e){
  637. switch(e.which){
  638. case 1: // RMB
  639. if($(this).data('id')!=selectedTab){
  640. $o.selectTab($(this).data('id'));
  641. return prevent(e);
  642. }
  643. break;
  644. case 2: // MMB
  645. $(this).children('span.close-button').click();
  646. return prevent(e);
  647. break;
  648. case 3: // LMB
  649. return prevent(e);
  650. break;
  651. default:
  652. return prevent(e);
  653. }
  654. })
  655. .append(
  656. $('<span>')
  657. .addClass('close-button')
  658. .click(function(){
  659. $o.removeTab(id);
  660. return false;
  661. })
  662. .css({
  663. 'position': 'absolute',
  664. 'background-color': 'inherit',
  665. 'top': 0,
  666. 'right': 0
  667. })
  668. .html('&times;')
  669. )
  670. .data('id',id);
  671. }
  672. },
  673. refreshTabs: function(){
  674. $tl.html('');
  675. var i,tab;
  676. for(i in tabs){
  677. tab = $o.tabObj(i);
  678. if(i==selectedTab){
  679. tab.addClass('clicked');
  680. $('#title').text(tabs[i].title);
  681. $('#topic').text(tabs[i].topic);
  682. }
  683. $tl.append(tab);
  684. }
  685. if($tl.get(0).scrollHeight-20 != $tl.scrollTop()){
  686. $('#tabs-scroll-right').removeClass('disabled');
  687. }
  688. if($tl.scrollTop() != 0){
  689. $('#tabs-scroll-left').removeClass('disabled');
  690. }
  691. }
  692. });
  693. String.prototype.htmlentities = function(){
  694. return this.replace(/&/g, '&amp;').replace(/\s/g, '&nbsp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  695. };
  696. $(document).ready(function(){
  697. $.extend(settings,$.parseJSON($.localStorage('settings')));
  698. $.localStorage('settings',JSON.stringify(settings));
  699. $i = $('#input');
  700. $s = $('#send');
  701. $cl = $('#content-list');
  702. $c = $('#content');
  703. $tl = $('#tabs-list');
  704. $h = $('#head');
  705. $s.click(function(){
  706. if(!$s.hasClass('clicked')){
  707. $s.addClass('clicked');
  708. setTimeout(function(){
  709. $s.removeClass('clicked');
  710. },500);
  711. }
  712. $o.send($i.val());
  713. $i.val('');
  714. });
  715. $i.keypress(function(e){
  716. if(e.keyCode == 13){
  717. if(!$s.hasClass('clicked')){
  718. $s.addClass('clicked');
  719. setTimeout(function(){
  720. $s.removeClass('clicked');
  721. },500);
  722. }
  723. $o.send($i.val());
  724. $i.val('');
  725. }
  726. });
  727. $('#settings, #users').click(function(){
  728. $(this).addClass('open');
  729. $(this).children('.close-button').show();
  730. }).hover(function(){
  731. $(this).addClass('hovered');
  732. },function(){
  733. $(this).removeClass('hovered');
  734. }).children('.close-button').click(function(){
  735. $(this).parent().removeClass('open');
  736. $(this).hide();
  737. return false;
  738. }).hide();
  739. $('#users').hoverIntent({
  740. out: function(){
  741. $(this).removeClass('open');
  742. $(this).children('.close-button').hide();
  743. },
  744. timeout: 1000
  745. });
  746. $('#content').click(function(){
  747. $('#settings, #users, #head').removeClass('hovered').removeClass('open');
  748. $('#settings, #users').children('.close-button').hide()
  749. });
  750. $('.unselectable').attr('unselectable','on');
  751. $.contextMenu({
  752. selector: 'div.tab',
  753. items: {
  754. add: {
  755. name: 'New Tab',
  756. icon: 'add',
  757. callback: function(){
  758. $(this).contextMenu('hide');
  759. var title = prompt('Title');
  760. tabs.push({
  761. name: prompt('channel'),
  762. title: title,
  763. topic: 'Topic for '+title
  764. });
  765. $o.refreshTabs();
  766. }
  767. },
  768. s1: '',
  769. close: {
  770. name: 'Close',
  771. icon: 'delete',
  772. callback: function(){
  773. $(this).contextMenu('hide');
  774. $o.removeTab($(this).data('id'));
  775. }
  776. }
  777. },
  778. zIndex: 99999,
  779. trigger: 'right'
  780. });
  781. $.contextMenu({
  782. selector: '#tabs-list',
  783. items: {
  784. add: {
  785. name: 'New Tab',
  786. icon: 'add',
  787. callback: function(){
  788. $(this).contextMenu('hide');
  789. var title = prompt('Title');
  790. tabs.push({
  791. name: prompt('channel'),
  792. title: title,
  793. topic: 'Topic for '+title
  794. });
  795. $o.refreshTabs();
  796. }
  797. }
  798. },
  799. zIndex: 99999,
  800. trigger: 'right'
  801. });
  802. $('#tabs-scroll-right').click(function(){
  803. event('scroll right');
  804. $tl.scrollTop(($tl.scrollTop()||0)+20);
  805. if($tl.get(0).scrollHeight-20 == $tl.scrollTop()){
  806. $('#tabs-scroll-right').addClass('disabled');
  807. }
  808. $('#tabs-scroll-left').removeClass('disabled');
  809. });
  810. $('#tabs-scroll-left').click(function(){
  811. event('scroll left');
  812. $tl.scrollTop(($tl.scrollTop()||0)-20);
  813. if($tl.scrollTop() == 0){
  814. $('#tabs-scroll-left').addClass('disabled');
  815. }
  816. $('#tabs-scroll-right').removeClass('disabled');
  817. });
  818. (function scrollup(){
  819. $('#tabs-scroll-left').click();
  820. if($tl.scrollTop() != 0){
  821. setTimeout(scrollup,10);
  822. }
  823. })();
  824. //DEBUG
  825. /* for(var i=0;i<20;i++){
  826. tabs.push({
  827. name: '#Tab'+i,
  828. title: 'Tab '+i,
  829. topic: 'Topic for tab '+i
  830. });
  831. } */
  832. //END DEBUG
  833. event('Date '+new Date,'ready');
  834. $h.addClass('hovered');
  835. setTimeout(function(){
  836. $h.removeClass('hovered');
  837. },1000);
  838. $o.renderSettings();
  839. if(settings.autoconnect){
  840. $o.connect();
  841. }
  842. });
  843. delete window.io;
  844. })(window,jQuery,io);
  845. if (!Date.prototype.toISOString) {
  846. Date.prototype.toISOString = function() {
  847. function pad(n) { return n < 10 ? '0' + n : n }
  848. return this.getUTCFullYear() + '-'
  849. + pad(this.getUTCMonth() + 1) + '-'
  850. + pad(this.getUTCDate()) + 'T'
  851. + pad(this.getUTCHours()) + ':'
  852. + pad(this.getUTCMinutes()) + ':'
  853. + pad(this.getUTCSeconds()) + 'Z';
  854. };
  855. }