omnomirc.js 20 KB

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