123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- /*
- OmnomIRC COPYRIGHT 2010,2011 Netham45
- OmnomIRC3 rewrite COPYRIGHT 2013 Nathaniel 'Eeems' van Diepen
- This file is part of OmnomIRC.
- OmnomIRC is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- OmnomIRC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with OmnomIRC. If not, see <http://www.gnu.org/licenses/>.
- */
- (function(window,$,undefined){
- var $o = window.OmnomIRC = window.$o = function(){
- return 'Version: '+$o.version
- },$i,$s,$h,$cl,$tl,hht,log=console.log,tabs=[],selectedTab=0;
- $.extend($o,{
- version: '0.1',
- send: function(msg){
- if(msg !== ''){
- $o.event('send',msg);
- $cl.append($('<li>').text(msg));
- }
- },
- event: function(event_name,message){
- switch(event_name){
- case 'ready':
- log('[DOCUMENT_READY]');
- break;
- default:
- log('['+event_name.toUpperCase()+'] '+message);
- }
- },
- selectTab: function(id){
- $o.event('tab_select',id);
- if(id<tabs.length-1&&id>=0){
- selectedTab=id;
- }
- $tl.children('.clicked').removeClass('clicked');
- $($tl.children().get(id)).addClass('clicked');
- $('#title').text(tabs[id].title);
- $('#topic').text(tabs[id].topic);
- },
- tabDOM: function(id){
-
- },
- addTab: function(name,title){
- tabs.push({
- name: name,
- title: title
- });
- $tl.append($o.tabObj(tabs.length-1));
- },
- removeTab: function(id){
- tabs.splice(id,1);
- if(selectedTab==id&&selectedTab>0){
- selectedTab--;
- }
- $o.refreshTabs();
- },
- tabObj: function(id){
- if(typeof id !== 'undefined'){
- return $('<span>')
- .addClass('tab')
- .text(tabs[id].name)
- .click(function(){
- if($(this).data('id')!=selectedTab){
- $o.selectTab($(this).data('id'));
- return false;
- }
- })
- .append(
- $('<span>')
- .addClass('close-button')
- .click(function(){
- $o.removeTab(id);
- return false;
- })
- .html('×')
- )
- .data('id',id);
- }
- },
- refreshTabs: function(){
- $tl.html('');
- var i,tab;
- for(i in tabs){
- tab = $o.tabObj(i);
- if(i==selectedTab){
- tab.addClass('clicked');
- $('#title').text(tabs[i].title);
- $('#topic').text(tabs[i].topic);
- }
- $tl.append(tab);
- }
- }
- });
- $(document).ready(function(){
- $i = $('#input');
- $s = $('#send');
- $cl = $('#content-list');
- $tl = $('#tabs-list');
- $h = $('#head');
- $s.click(function(){
- if(!$s.hasClass('clicked')){
- $s.addClass('clicked');
- setTimeout(function(){
- $s.removeClass('clicked');
- },500);
- }
- $o.send($i.val());
- $i.val('');
- });
- $i.keypress(function(e){
- if(e.keyCode == 13){
- if(!$s.hasClass('clicked')){
- $s.addClass('clicked');
- setTimeout(function(){
- $s.removeClass('clicked');
- },500);
- }
- $o.send($i.val());
- $i.val('');
- }
- });
- $('#settings, #users').click(function(){
- $(this).addClass('open');
- $(this).children('.close-button').show();
- }).hover(function(){
- $(this).addClass('hovered');
- },function(){
- $(this).removeClass('hovered');
- }).children('.close-button').click(function(){
- $(this).parent().removeClass('open');
- $(this).hide();
- return false;
- }).hide();
- $('#users').hoverIntent({
- out: function(){
- $(this).removeClass('open');
- $(this).children('.close-button').hide();
- },
- timeout: 1000
- });
- $('#content').click(function(){
- $('#settings, #users, #head').removeClass('hovered').removeClass('open');
- });
- $h.hoverIntent({
- out: function(){
- $h.removeClass('hovered');
- },
- over: function(){},
- timeout: 1000
- }).hover(function(){
- hht = setTimeout(function(){
- $o.event('timeout','Head HoverIntent timeout');
- $('#head:hover').addClass('hovered');
- },1000);
- },function(){
- clearInterval(hht);
- }).click(function(){
- $(this).addClass('hovered');
- });
- $('.unselectable').attr('unselectable','on');
- //DEBUG
- for(var i=0;i<10;i++){
- tabs.push({
- name: 'Tab '+i,
- title: 'Tab '+i,
- topic: 'Topic for tab '+i
- });
- }
- //END DEBUG
- $o.refreshTabs();
- $o.event('ready');
- $h.addClass('hovered');
- setTimeout(function(){
- $h.removeClass('hovered');
- },1000);
- });
- })(window,jQuery);
|