|
@@ -19,27 +19,107 @@
|
|
*/
|
|
*/
|
|
(function(window,$,undefined){
|
|
(function(window,$,undefined){
|
|
var $o = window.OmnomIRC = window.$o = function(){
|
|
var $o = window.OmnomIRC = window.$o = function(){
|
|
- return 'Version: '+$o.version
|
|
|
|
- },$i,$s,$h,$cl,$tl,hht,log=console.log,tabs=[],selectedTab=0;
|
|
|
|
|
|
+ return 'Version: '+$o.version
|
|
|
|
+ },
|
|
|
|
+ event = function(msg,type){
|
|
|
|
+ type=type==undefined?'event':type;
|
|
|
|
+ switch(type){
|
|
|
|
+ case 'ready':type='document_ready';break;
|
|
|
|
+ }
|
|
|
|
+ log('['+type.toUpperCase()+'] '+msg);
|
|
|
|
+ },
|
|
|
|
+ log=console.log,
|
|
|
|
+ tabs=[],
|
|
|
|
+ selectedTab=0,
|
|
|
|
+ commands = [
|
|
|
|
+ {
|
|
|
|
+ cmd: 'help',
|
|
|
|
+ fn: function(args){
|
|
|
|
+ var m = 'Commands:',i;
|
|
|
|
+ for(i in commands){
|
|
|
|
+ m += ' '+commands[i].cmd;
|
|
|
|
+ }
|
|
|
|
+ $o.msg(m);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ cmd: 'open',
|
|
|
|
+ fn: function(args){
|
|
|
|
+ tabs.push({
|
|
|
|
+ name: args[1],
|
|
|
|
+ title: args[2],
|
|
|
|
+ topic: 'Topic for '+args[2]
|
|
|
|
+ });
|
|
|
|
+ $o.refreshTabs();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ cmd: 'clear',
|
|
|
|
+ fn: function(args){
|
|
|
|
+ $cl.html('');
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ cmd: 'close',
|
|
|
|
+ fn: function(args){
|
|
|
|
+ if(args.length > 1){
|
|
|
|
+ $o.removeTab(args[1]);
|
|
|
|
+ }else{
|
|
|
|
+ $o.removeTab(selectedTab);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ cmd: 'tabs',
|
|
|
|
+ fn: function(args){
|
|
|
|
+ $o.msg('Tabs:');
|
|
|
|
+ for(var i in tabs){
|
|
|
|
+ $o.msg(' ['+i+'] '+tabs[i].name);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ $i,$s,$h,$cl,$tl,hht;
|
|
$.extend($o,{
|
|
$.extend($o,{
|
|
- version: '0.1',
|
|
|
|
|
|
+ version: '3.0',
|
|
send: function(msg){
|
|
send: function(msg){
|
|
if(msg !== ''){
|
|
if(msg !== ''){
|
|
- $o.event('send',msg);
|
|
|
|
- $cl.append($('<li>').text(msg));
|
|
|
|
|
|
+ if(msg[0] == '/'){
|
|
|
|
+ var args = msg.split(' '),
|
|
|
|
+ cmd = args[0].substr(1),
|
|
|
|
+ i;
|
|
|
|
+ event(msg,'command');
|
|
|
|
+ for(i in commands){
|
|
|
|
+ if(commands[i].cmd == cmd){
|
|
|
|
+ commands[i].fn(args);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $o.msg(cmd+' is not a valid command.');
|
|
|
|
+ }else{
|
|
|
|
+ event(msg,'send');
|
|
|
|
+ $o.msg({
|
|
|
|
+ text: msg,
|
|
|
|
+ user: 'User'
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- event: function(event_name,message){
|
|
|
|
- switch(event_name){
|
|
|
|
- case 'ready':
|
|
|
|
- log('[DOCUMENT_READY]');
|
|
|
|
|
|
+ msg: function(msg){
|
|
|
|
+ switch(typeof msg){
|
|
|
|
+ case 'string':
|
|
|
|
+ $cl.append($('<li>').html(msg.htmlentities()));
|
|
|
|
+ break;
|
|
|
|
+ case 'object':
|
|
|
|
+ $cl.append($('<li>').html('<'+msg.user+'> '+msg.text.htmlentities()));
|
|
break;
|
|
break;
|
|
- default:
|
|
|
|
- log('['+event_name.toUpperCase()+'] '+message);
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ event: function(event_name,message){
|
|
|
|
+ event(message,event_name);
|
|
|
|
+ },
|
|
selectTab: function(id){
|
|
selectTab: function(id){
|
|
- $o.event('tab_select',id);
|
|
|
|
|
|
+ event(id,'tab_select');
|
|
if(id<tabs.length-1&&id>=0){
|
|
if(id<tabs.length-1&&id>=0){
|
|
selectedTab=id;
|
|
selectedTab=id;
|
|
}
|
|
}
|
|
@@ -52,6 +132,7 @@
|
|
|
|
|
|
},
|
|
},
|
|
addTab: function(name,title){
|
|
addTab: function(name,title){
|
|
|
|
+ event('Tab added: '+name);
|
|
tabs.push({
|
|
tabs.push({
|
|
name: name,
|
|
name: name,
|
|
title: title
|
|
title: title
|
|
@@ -59,6 +140,7 @@
|
|
$tl.append($o.tabObj(tabs.length-1));
|
|
$tl.append($o.tabObj(tabs.length-1));
|
|
},
|
|
},
|
|
removeTab: function(id){
|
|
removeTab: function(id){
|
|
|
|
+ event('Tab removed: '+tabs[id].name);
|
|
tabs.splice(id,1);
|
|
tabs.splice(id,1);
|
|
if(selectedTab==id&&selectedTab>0){
|
|
if(selectedTab==id&&selectedTab>0){
|
|
selectedTab--;
|
|
selectedTab--;
|
|
@@ -69,7 +151,7 @@
|
|
if(typeof id !== 'undefined'){
|
|
if(typeof id !== 'undefined'){
|
|
return $('<span>')
|
|
return $('<span>')
|
|
.addClass('tab')
|
|
.addClass('tab')
|
|
- .text(tabs[id].name)
|
|
|
|
|
|
+ .text(tabs[id].title)
|
|
.click(function(){
|
|
.click(function(){
|
|
if($(this).data('id')!=selectedTab){
|
|
if($(this).data('id')!=selectedTab){
|
|
$o.selectTab($(this).data('id'));
|
|
$o.selectTab($(this).data('id'));
|
|
@@ -102,6 +184,9 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+ String.prototype.htmlentities = function(){
|
|
|
|
+ return this.replace(/&/g, '&').replace(/\s/g, ' ').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
|
|
+ };
|
|
$(document).ready(function(){
|
|
$(document).ready(function(){
|
|
$i = $('#input');
|
|
$i = $('#input');
|
|
$s = $('#send');
|
|
$s = $('#send');
|
|
@@ -161,7 +246,7 @@
|
|
timeout: 1000
|
|
timeout: 1000
|
|
}).hover(function(){
|
|
}).hover(function(){
|
|
hht = setTimeout(function(){
|
|
hht = setTimeout(function(){
|
|
- $o.event('timeout','Head HoverIntent timeout');
|
|
|
|
|
|
+ event('Head HoverIntent timeout','timeout');
|
|
$('#head:hover').addClass('hovered');
|
|
$('#head:hover').addClass('hovered');
|
|
},1000);
|
|
},1000);
|
|
},function(){
|
|
},function(){
|
|
@@ -173,14 +258,14 @@
|
|
//DEBUG
|
|
//DEBUG
|
|
for(var i=0;i<10;i++){
|
|
for(var i=0;i<10;i++){
|
|
tabs.push({
|
|
tabs.push({
|
|
- name: 'Tab '+i,
|
|
|
|
|
|
+ name: '#Tab'+i,
|
|
title: 'Tab '+i,
|
|
title: 'Tab '+i,
|
|
topic: 'Topic for tab '+i
|
|
topic: 'Topic for tab '+i
|
|
});
|
|
});
|
|
}
|
|
}
|
|
//END DEBUG
|
|
//END DEBUG
|
|
$o.refreshTabs();
|
|
$o.refreshTabs();
|
|
- $o.event('ready');
|
|
|
|
|
|
+ event('Date '+new Date,'ready');
|
|
$h.addClass('hovered');
|
|
$h.addClass('hovered');
|
|
setTimeout(function(){
|
|
setTimeout(function(){
|
|
$h.removeClass('hovered');
|
|
$h.removeClass('hovered');
|