omnomirc.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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,$,undefined){
  17. var $o = window.OmnomIRC = window.$o = function(){
  18. return 'Version: '+$o.version
  19. },$i,$s,$cl,$tl,log=console.log,tabs=[],selectedTab=0;
  20. $.extend($o,{
  21. version: '0.1',
  22. send: function(msg){
  23. if(msg !== ''){
  24. $o.event('send',msg);
  25. $cl.append($('<li>').text(msg));
  26. }
  27. },
  28. event: function(event_name,message){
  29. switch(event_name){
  30. case 'ready':
  31. log('[DOCUMENT_READY]');
  32. break;
  33. default:
  34. log('['+event_name.toUpperCase()+'] '+message);
  35. }
  36. },
  37. selectTab: function(id){
  38. $o.event('tab_select',id);
  39. if(id<tabs.length-1&&id>=0){
  40. selectedTab=id;
  41. }
  42. $tl.children('.clicked').removeClass('clicked');
  43. $($tl.children().get(id)).addClass('clicked');
  44. $('#title').text(tabs[id].title);
  45. $('#topic').text(tabs[id].topic);
  46. },
  47. tabDOM: function(id){
  48. },
  49. addTab: function(name,title){
  50. tabs.push({
  51. name: name,
  52. title: title
  53. });
  54. $tl.append($o.tabObj(tabs.length-1));
  55. },
  56. removeTab: function(id){
  57. tabs.splice(id,1);
  58. if(selectedTab==id&&selectedTab>0){
  59. selectedTab--;
  60. }
  61. $o.refreshTabs();
  62. },
  63. tabObj: function(id){
  64. if(typeof id !== 'undefined'){
  65. return $('<span>')
  66. .addClass('tab')
  67. .text(tabs[id].name).click(function(){
  68. if($(this).data('id')!=selectedTab){
  69. $o.selectTab($(this).data('id'));
  70. }
  71. })
  72. .append(
  73. $('<span>')
  74. .addClass('close-button')
  75. .click(function(){
  76. $o.removeTab(id);
  77. })
  78. .html('&times;')
  79. )
  80. .data('id',id);
  81. }
  82. },
  83. refreshTabs: function(){
  84. $tl.html('');
  85. var i,tab;
  86. for(i in tabs){
  87. tab = $o.tabObj(i);
  88. if(i==selectedTab){
  89. tab.addClass('clicked');
  90. $('#title').text(tabs[i].title);
  91. $('#topic').text(tabs[i].topic);
  92. }
  93. $tl.append(tab);
  94. }
  95. }
  96. });
  97. $(document).ready(function(){
  98. $i = $('#input');
  99. $s = $('#send');
  100. $cl = $('#content-list');
  101. $tl = $('#tabs-list');
  102. $s.click(function(){
  103. if(!$s.hasClass('clicked')){
  104. $s.addClass('clicked');
  105. setTimeout(function(){
  106. $s.removeClass('clicked');
  107. },500);
  108. }
  109. $o.send($i.val());
  110. $i.val('');
  111. });
  112. $i.keypress(function(e){
  113. if(e.keyCode == 13){
  114. if(!$s.hasClass('clicked')){
  115. $s.addClass('clicked');
  116. setTimeout(function(){
  117. $s.removeClass('clicked');
  118. },500);
  119. }
  120. $o.send($i.val());
  121. $i.val('');
  122. }
  123. });
  124. $('#settings, #users').click(function(){
  125. $(this).addClass('open');
  126. }).hoverIntent({
  127. out: function(){
  128. $(this).removeClass('open');
  129. },
  130. timeout: 1000
  131. });
  132. $("#head").hoverIntent({
  133. over: function(){
  134. $(this).addClass('hovered');
  135. },
  136. out: function(){
  137. $(this).removeClass('hovered');
  138. },
  139. timeout: 1000
  140. });
  141. $('.unselectable').attr('unselectable','on');
  142. //DEBUG
  143. for(var i=0;i<10;i++){
  144. tabs.push({
  145. name: 'Tab '+i,
  146. title: 'Tab '+i,
  147. topic: 'Topic for tab '+i
  148. });
  149. }
  150. //END DEBUG
  151. $o.refreshTabs();
  152. $o.event('ready');
  153. });
  154. })(window,jQuery);