omnomirc.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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,$h,$cl,$tl,hht,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)
  68. .click(function(){
  69. if($(this).data('id')!=selectedTab){
  70. $o.selectTab($(this).data('id'));
  71. return false;
  72. }
  73. })
  74. .append(
  75. $('<span>')
  76. .addClass('close-button')
  77. .click(function(){
  78. $o.removeTab(id);
  79. return false;
  80. })
  81. .html('&times;')
  82. )
  83. .data('id',id);
  84. }
  85. },
  86. refreshTabs: function(){
  87. $tl.html('');
  88. var i,tab;
  89. for(i in tabs){
  90. tab = $o.tabObj(i);
  91. if(i==selectedTab){
  92. tab.addClass('clicked');
  93. $('#title').text(tabs[i].title);
  94. $('#topic').text(tabs[i].topic);
  95. }
  96. $tl.append(tab);
  97. }
  98. }
  99. });
  100. $(document).ready(function(){
  101. $i = $('#input');
  102. $s = $('#send');
  103. $cl = $('#content-list');
  104. $tl = $('#tabs-list');
  105. $h = $('#head');
  106. $s.click(function(){
  107. if(!$s.hasClass('clicked')){
  108. $s.addClass('clicked');
  109. setTimeout(function(){
  110. $s.removeClass('clicked');
  111. },500);
  112. }
  113. $o.send($i.val());
  114. $i.val('');
  115. });
  116. $i.keypress(function(e){
  117. if(e.keyCode == 13){
  118. if(!$s.hasClass('clicked')){
  119. $s.addClass('clicked');
  120. setTimeout(function(){
  121. $s.removeClass('clicked');
  122. },500);
  123. }
  124. $o.send($i.val());
  125. $i.val('');
  126. }
  127. });
  128. $('#settings, #users').click(function(){
  129. $(this).addClass('open');
  130. $(this).children('.close-button').show();
  131. }).hover(function(){
  132. $(this).addClass('hovered');
  133. },function(){
  134. $(this).removeClass('hovered');
  135. }).children('.close-button').click(function(){
  136. $(this).parent().removeClass('open');
  137. $(this).hide();
  138. return false;
  139. }).hide();
  140. $('#users').hoverIntent({
  141. out: function(){
  142. $(this).removeClass('open');
  143. $(this).children('.close-button').hide();
  144. },
  145. timeout: 1000
  146. });
  147. $('#content').click(function(){
  148. $('#settings, #users, #head').removeClass('hovered').removeClass('open');
  149. });
  150. $h.hoverIntent({
  151. out: function(){
  152. $h.removeClass('hovered');
  153. },
  154. over: function(){},
  155. timeout: 1000
  156. }).hover(function(){
  157. hht = setTimeout(function(){
  158. $o.event('timeout','Head HoverIntent timeout');
  159. $('#head:hover').addClass('hovered');
  160. },1000);
  161. },function(){
  162. clearInterval(hht);
  163. }).click(function(){
  164. $(this).addClass('hovered');
  165. });
  166. $('.unselectable').attr('unselectable','on');
  167. //DEBUG
  168. for(var i=0;i<10;i++){
  169. tabs.push({
  170. name: 'Tab '+i,
  171. title: 'Tab '+i,
  172. topic: 'Topic for tab '+i
  173. });
  174. }
  175. //END DEBUG
  176. $o.refreshTabs();
  177. $o.event('ready');
  178. $h.addClass('hovered');
  179. setTimeout(function(){
  180. $h.removeClass('hovered');
  181. },1000);
  182. });
  183. })(window,jQuery);