omnomirc.js 3.7 KB

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