omnomirc.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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. //eastegg rickroll start
  482. if (msg.search("goo.gl/QMET")!=-1 || msg.search("youtube.com/watch?v=oHg5SJYRHA0")!=-1 || msg.search("youtube.com/watch?v=dQw4w9WgXcQ")!=-1) {
  483. var rick = document.createElement('div');rick.style.position='absolute';rick.style.zIndex='39px';rick.style.top='0';rick.style.left='35px';rick.innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"><param name="movie" value="http://i-lost-the-ga.me/rickroll.swf"><param name="quality" value="high"><embed src="http://i-lost-the-ga.me/rickroll.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></object>';document.body.appendChild(rick);
  484. }
  485. //easteregg rickroll end
  486. if(msg[0] == '/' && msg[1] != '/'){
  487. var args = msg.split(' '),
  488. cmd = args[0].substr(1),
  489. i;
  490. event(msg,'command');
  491. for(i in commands){
  492. if(commands[i].cmd == cmd){
  493. commands[i].fn(args);
  494. return;
  495. }
  496. }
  497. $o.msg(cmd+' is not a valid command.');
  498. }else{
  499. event(msg,'send');
  500. socket.emit('message',{
  501. message: msg,
  502. room: tabs[selectedTab].name,
  503. from: properties.nick
  504. });
  505. }
  506. }
  507. },
  508. msg: function(msg,tabName){
  509. var frag;
  510. if(typeof tabName == 'undefined' || tabName == tabs[selectedTab].name){
  511. frag = document.createDocumentFragment();
  512. }else{
  513. frag = tabs[$o.tabIdForName(tabName)].body;
  514. }
  515. switch(typeof msg){
  516. case 'string':
  517. $(frag).append($('<li>').html(msg.htmlentities()));
  518. break;
  519. case 'object':
  520. if(typeof msg.html == 'undefined'){
  521. $(frag).append($('<li>').html('&lt;'+msg.user+'&gt;&nbsp;'+msg.text.htmlentities()));
  522. }else{
  523. $(frag).append(msg.html);
  524. }
  525. break;
  526. }
  527. $(tabs[$o.tabIdForName(tabName) || selectedTab].body).append(frag);
  528. var scroll = [],i,html;
  529. for(i in tabs){
  530. html = '';
  531. $(tabs[i].body).children().each(function(){
  532. html += this.outerHTML;
  533. });
  534. scroll.push({
  535. name: tabs[i].name,
  536. body: html,
  537. date: new Date().toString()
  538. });
  539. }
  540. $.localStorage('tabs',scroll);
  541. if(typeof tabName == 'undefined' || tabName == tabs[selectedTab].name){
  542. $o.selectTab(selectedTab);
  543. }
  544. },
  545. event: function(event_name,message){
  546. event(message,event_name);
  547. },
  548. selectTab: function(id){
  549. event(id+' '+tabs[id].name,'tab_select');
  550. if(id<tabs.length&&id>=0){
  551. selectedTab=id;
  552. }
  553. $tl.children('.clicked').removeClass('clicked');
  554. $($tl.children().get(id)).addClass('clicked');
  555. $('#title').text(tabs[id].title);
  556. $('#topic').text(tabs[id].topic);
  557. $cl.html($(tabs[id].body).clone());
  558. abbrDate('abbr.date');
  559. $o.renderUsers();
  560. setTimeout(function scrollContent(){
  561. if($c.scrollTop() < $c[0].scrollHeight){
  562. $c.scrollTop($c.scrollTop()+1);
  563. setTimeout(scrollContent,settings.scrollspeed);
  564. }else{
  565. event('scrolling stopped');
  566. }
  567. },settings.scrollspeed);
  568. },
  569. tabIdForName: function(name){
  570. for(var i in tabs){
  571. if(tabs[i].name == name){
  572. return i;
  573. }
  574. }
  575. return false;
  576. },
  577. tabDOM: function(id){
  578. return tabs[id].body;
  579. },
  580. addTab: function(name,title){
  581. event('Tab added: '+name+' with title '+title);
  582. if(!(function(){
  583. for(var i in tabs){
  584. if(name==tabs[i].name){
  585. return true;
  586. }
  587. }
  588. return false;
  589. })()){
  590. var scroll = $.localStorage('tabs'),
  591. i,
  592. frag = document.createDocumentFragment();
  593. for(i in scroll){
  594. if(scroll[i].name == name){
  595. scroll[i].body = $(scroll[i].body).slice(-10);
  596. $(frag)
  597. .append(scroll[i].body)
  598. .append(
  599. $('<li>').html('<span class="to_remove">-- loaded old scrollback for '+scroll[i].date+' --</span>')
  600. )
  601. .children()
  602. .children('.remove')
  603. .remove();
  604. $(frag)
  605. .children()
  606. .children('.to_remove')
  607. .removeClass('to_remove')
  608. .addClass('remove');
  609. event('loading old tab scrollback for '+name+' last saved +'+scroll[i].date);
  610. }
  611. }
  612. tabs.push({
  613. name: name,
  614. title: title,
  615. body: frag,
  616. names: []
  617. });
  618. $tl.append($o.tabObj(tabs.length-1));
  619. $o.refreshTabs();
  620. $o.renderUsers();
  621. }else{
  622. event('Attempted to add an existing tab');
  623. }
  624. },
  625. removeTab: function(id){
  626. if(typeof tabs[id] != 'undefined'){
  627. event('Tab removed: '+tabs[id].name);
  628. socket.emit('part',{
  629. name: tabs[id].name
  630. });
  631. tabs.splice(id,1);
  632. if(selectedTab==id&&selectedTab>0){
  633. selectedTab--;
  634. }
  635. }
  636. $o.refreshTabs();
  637. $cl.html(tabs[selectedTab].body);
  638. $o.renderUsers();
  639. },
  640. tabObj: function(id){
  641. if(typeof id !== 'undefined'){
  642. return $('<div>')
  643. .addClass('tab')
  644. .text(tabs[id].title)
  645. .mouseup(function(e){
  646. switch(e.which){
  647. case 1: // RMB
  648. if($(this).data('id')!=selectedTab){
  649. $o.selectTab($(this).data('id'));
  650. return prevent(e);
  651. }
  652. break;
  653. case 2: // MMB
  654. $(this).children('span.close-button').click();
  655. return prevent(e);
  656. break;
  657. case 3: // LMB
  658. return prevent(e);
  659. break;
  660. default:
  661. return prevent(e);
  662. }
  663. })
  664. .append(
  665. $('<span>')
  666. .addClass('close-button')
  667. .click(function(){
  668. $o.removeTab(id);
  669. return false;
  670. })
  671. .css({
  672. 'position': 'absolute',
  673. 'background-color': 'inherit',
  674. 'top': 0,
  675. 'right': 0
  676. })
  677. .html('&times;')
  678. )
  679. .data('id',id);
  680. }
  681. },
  682. refreshTabs: function(){
  683. $tl.html('');
  684. var i,tab;
  685. for(i in tabs){
  686. tab = $o.tabObj(i);
  687. if(i==selectedTab){
  688. tab.addClass('clicked');
  689. $('#title').text(tabs[i].title);
  690. $('#topic').text(tabs[i].topic);
  691. }
  692. $tl.append(tab);
  693. }
  694. if($tl.get(0).scrollHeight-20 != $tl.scrollTop()){
  695. $('#tabs-scroll-right').removeClass('disabled');
  696. }
  697. if($tl.scrollTop() != 0){
  698. $('#tabs-scroll-left').removeClass('disabled');
  699. }
  700. }
  701. });
  702. String.prototype.htmlentities = function(){
  703. return this
  704. .replace(/&/g, '&amp;')
  705. .replace(/</g, '&lt;')
  706. .replace(/>/g, '&gt;')
  707. .replace(/\n/g,'<br/>')
  708. .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;')
  709. .replace(/\s/g, '&nbsp;')
  710. .replace(/"/g, '&quot;');
  711. };
  712. $(document).ready(function(){
  713. $.extend(settings,$.parseJSON($.localStorage('settings')));
  714. $.localStorage('settings',JSON.stringify(settings));
  715. $i = $('#input');
  716. $s = $('#send');
  717. $cl = $('#content-list');
  718. $c = $('#content');
  719. $tl = $('#tabs-list');
  720. $h = $('#head');
  721. $s.click(function(){
  722. if(!$s.hasClass('clicked')){
  723. $s.addClass('clicked');
  724. setTimeout(function(){
  725. $s.removeClass('clicked');
  726. },500);
  727. }
  728. $o.send($i.val());
  729. $i.val('');
  730. });
  731. $i.keypress(function(e){
  732. if(e.keyCode == 13){
  733. if(!$s.hasClass('clicked')){
  734. $s.addClass('clicked');
  735. setTimeout(function(){
  736. $s.removeClass('clicked');
  737. },500);
  738. }
  739. $o.send($i.val());
  740. $i.val('');
  741. }
  742. });
  743. $('#settings, #users').click(function(){
  744. $(this).addClass('open');
  745. $(this).children('.close-button').show();
  746. }).hover(function(){
  747. $(this).addClass('hovered');
  748. },function(){
  749. $(this).removeClass('hovered');
  750. }).children('.close-button').click(function(){
  751. $(this).parent().removeClass('open');
  752. $(this).hide();
  753. return false;
  754. }).hide();
  755. $('#users').hoverIntent({
  756. out: function(){
  757. $(this).removeClass('open');
  758. $(this).children('.close-button').hide();
  759. },
  760. timeout: 1000
  761. });
  762. $('#content').click(function(){
  763. $('#settings, #users, #head').removeClass('hovered').removeClass('open');
  764. $('#settings, #users').children('.close-button').hide()
  765. });
  766. $('.unselectable').attr('unselectable','on');
  767. $.contextMenu({
  768. selector: 'div.tab',
  769. items: {
  770. add: {
  771. name: 'New Tab',
  772. icon: 'add',
  773. callback: function(){
  774. $(this).contextMenu('hide');
  775. var title = prompt('Title');
  776. tabs.push({
  777. name: prompt('channel'),
  778. title: title,
  779. topic: 'Topic for '+title
  780. });
  781. $o.refreshTabs();
  782. }
  783. },
  784. s1: '',
  785. close: {
  786. name: 'Close',
  787. icon: 'delete',
  788. callback: function(){
  789. $(this).contextMenu('hide');
  790. $o.removeTab($(this).data('id'));
  791. }
  792. }
  793. },
  794. zIndex: 99999,
  795. trigger: 'right'
  796. });
  797. $.contextMenu({
  798. selector: '#tabs-list',
  799. items: {
  800. add: {
  801. name: 'New Tab',
  802. icon: 'add',
  803. callback: function(){
  804. $(this).contextMenu('hide');
  805. var title = prompt('Title');
  806. tabs.push({
  807. name: prompt('channel'),
  808. title: title,
  809. topic: 'Topic for '+title
  810. });
  811. $o.refreshTabs();
  812. }
  813. }
  814. },
  815. zIndex: 99999,
  816. trigger: 'right'
  817. });
  818. $('#tabs-scroll-right').click(function(){
  819. event('scroll right');
  820. $tl.scrollTop(($tl.scrollTop()||0)+20);
  821. if($tl.get(0).scrollHeight-20 == $tl.scrollTop()){
  822. $('#tabs-scroll-right').addClass('disabled');
  823. }
  824. $('#tabs-scroll-left').removeClass('disabled');
  825. });
  826. $('#tabs-scroll-left').click(function(){
  827. event('scroll left');
  828. $tl.scrollTop(($tl.scrollTop()||0)-20);
  829. if($tl.scrollTop() == 0){
  830. $('#tabs-scroll-left').addClass('disabled');
  831. }
  832. $('#tabs-scroll-right').removeClass('disabled');
  833. });
  834. (function scrollup(){
  835. $('#tabs-scroll-left').click();
  836. if($tl.scrollTop() != 0){
  837. setTimeout(scrollup,10);
  838. }
  839. })();
  840. //DEBUG
  841. /* for(var i=0;i<20;i++){
  842. tabs.push({
  843. name: '#Tab'+i,
  844. title: 'Tab '+i,
  845. topic: 'Topic for tab '+i
  846. });
  847. } */
  848. //END DEBUG
  849. event('Date '+new Date,'ready');
  850. $h.addClass('hovered');
  851. setTimeout(function(){
  852. $h.removeClass('hovered');
  853. },1000);
  854. $o.renderSettings();
  855. if(settings.autoconnect){
  856. $o.connect();
  857. }
  858. });
  859. delete window.io;
  860. })(window,jQuery,io);
  861. if (!Date.prototype.toISOString) {
  862. Date.prototype.toISOString = function() {
  863. function pad(n) { return n < 10 ? '0' + n : n }
  864. return this.getUTCFullYear() + '-'
  865. + pad(this.getUTCMonth() + 1) + '-'
  866. + pad(this.getUTCDate()) + 'T'
  867. + pad(this.getUTCHours()) + ':'
  868. + pad(this.getUTCMinutes()) + ':'
  869. + pad(this.getUTCSeconds()) + 'Z';
  870. };
  871. }