0){
selectedTab--;
}
break;
}
}
$o.ui.render.tablist();
$cl.html($o.ui.tabs.current().body);
$o.ui.render.users();
},
selected: function(){
return selectedTab;
},
idForName: function(name){
for(var i in tabs){
if(tabs[i].name == name){
return i;
}
}
return false;
},
tab: function(id){
if(typeof id == 'string' && !id.isNumber()){
id = $o.ui.tabs.idForName(id);
if(!id) return false;
}
return typeof tabs[id] == 'undefined'?false:tabs[id];
},
dom: function(id){
if(typeof id == 'string' && !id.isNumber()){
id = $o.ui.tabs.idForName(id);
if(!id) return false;
}
return typeof tabs[id] == 'undefined'?false:tabs[id].body;
},
obj: function(id){
if(typeof id !== 'undefined'){
if(typeof id == 'string' && !id.isNumber()){
id = $o.ui.tabs.idForName(id);
if(!id) return;
}
return $('')
.addClass('tab')
.text($o.ui.tabs.tab(id).name)
.mouseup(function(e){
switch(e.which){
case 1: // RMB
if($(this).data('id')!=selectedTab){
$o.ui.tabs.select($(this).data('id'));
return prevent(e);
}
break;
case 2: // MMB
$(this).children('span.close-button').click();
return prevent(e);
break;
case 3: // LMB
return prevent(e);
break;
default:
return prevent(e);
}
})
.append(
$('')
.addClass('close-button')
.click(function(){
$o.ui.tabs.remove(id);
return false;
})
.css({
'position': 'absolute',
'background-color': 'inherit',
'top': 0,
'right': 0
})
.html('×')
)
.data('id',id);
}
},
select: function(id){
if(typeof id == 'string' && !id.isNumber()){
id = $o.ui.tabs.idForName(id);
if(!id) return false;
}
event(id+' '+$o.ui.tabs.tab(id).name,'tab_select');
if(id=0){
selectedTab=id;
}
$tl.children('.clicked').removeClass('clicked');
$($tl.children().get(id)).addClass('clicked');
$('#title').text($o.ui.tabs.tab(id).name);
$('#topic').text($o.ui.tabs.tab(id).topic);
$cl.html($($o.ui.tabs.tab(id).body).clone());
abbrDate('abbr.date');
$o.ui.render.users();
setTimeout(function scrollContent(){
if($c.scrollTop() < $c[0].scrollHeight){
$c.scrollTop($c.scrollTop()+1);
setTimeout(scrollContent,settings.scrollspeed);
}else{
event('scrolling stopped');
}
},settings.scrollspeed);
},
current: function(){
if(tabs.length > 0 && tabs.length > selectedTab){
return tabs[selectedTab];
}else{
return {
name: '',
body: document.createDocumentFragment(),
date: new Date(),
send: noop,
close: noop,
users: [],
names: noop,
select: noop,
clear: noop
}
}
}
},
},
chat: {
connect: function(server){
if($o.chat.connected()){
$o.disconnect();
}
if(typeof server == 'undefined'){
server = settings.server;
}
socket = window.socket = io.connect(server);
for(var i in handles){
socket.on(handles[i].on,handles[i].fn);
}
$o.chat.auth();
},
disconnect: function(){
if($o.chat.connected()){
socket.disconnect();
}
},
connected: function(){
return typeof socket == 'undefined'?false:properties.connected;
},
send: function(msg,room){
if(typeof room == 'undefined'){
room = $o.ui.tabs.current().name;
}
if(msg !== ''){
if(msg[0] == '/' && msg[1] != '/'){
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');
emit('message',{
message: msg,
room: room,
from: properties.nick
});
}
}
},
auth: function(){
if(settings.nick == ''){
$o.set('nick','User');
return;
}
emit('auth',{
nick: settings.nick
// TODO - send authorization info
});
}
},
get: function(name,formatted){
if(typeof formatted == 'undefined'){
return exists(settings[name])?settings[name]:false;
}else{
var val = $o.get(name),
type,
values = false;
switch(name){
case 'theme':
type = 'select';
values = properties.themes;
break;
case 'autojoin':type = 'array';break;
case 'timestamp':type = 'string';break;
default:
type = typeof val;
}
return {
type: type,
val: val,
values: values,
name: name
};
}
},
set: function(name,value,render){
if(exists(settings[name])){
settings[name] = value;
$.localStorage('settings',JSON.stringify(settings));
switch(name){
case 'timestamp':
abbrDate('abbr.date');
if(settings.timestamp == ''){
$('.date_cell').css('visibility','hidden');
}else{
$('.date_cell').css('visibility','visible');
}
break;
case 'nick':
$o.chat.auth();
break;
}
if(typeof render == 'undefined'){
$o.ui.render.settings();
}
return true;
}else{
return false;
}
},
prop: function(name){
return exists(properties[name])?properties[name]:null;
},
send: function(msg){
$o.chat.send(msg);
},
msg: function(msg,tabName){
var frag;
if(typeof tabName == 'undefined' || tabName == $o.ui.tabs.current().name){
frag = document.createDocumentFragment();
}else{
frag = $o.ui.tabs.tab(tabName).body;
}
switch(typeof msg){
case 'string':
$(frag).append($('').html(msg.htmlentities()));
break;
case 'object':
if(typeof msg.html == 'undefined'){
$(frag).append($('').html('<'+msg.user+'> '+msg.text.htmlentities()));
}else{
$(frag).append(msg.html);
}
break;
}
if(tabs.length > 0){
$($o.ui.tabs.tab(tabName) || $o.ui.tabs.current().body).append(frag);
}
var scroll = [],i,html;
for(i in tabs){
html = '';
$(tabs[i].body).children().each(function(){
html += this.outerHTML;
});
scroll.push({
name: tabs[i].name,
body: html,
date: new Date().toString()
});
}
$.localStorage('tabs',scroll);
if(typeof tabName == 'undefined' || tabName == $o.ui.tabs.current().name){
$o.ui.tabs.select(selectedTab);
}
},
event: function(event_name,message){
event(message,event_name);
}
});
String.prototype.htmlentities = function(){
return this
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/\n/g,'
')
.replace(/\t/g, ' ')
.replace(/\s/g, ' ')
.replace(/"/g, '"');
};
$(document).ready(function(){
$.extend(settings,$.parseJSON($.localStorage('settings')));
$.localStorage('settings',JSON.stringify(settings));
$i = $('#input');
$s = $('#send');
$cl = $('#content-list');
$c = $('#content');
$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');
$('#settings, #users').children('.close-button').hide()
});
$('.unselectable').attr('unselectable','on');
$.contextMenu({
selector: 'div.tab',
items: {
add: {
name: 'New Tab',
icon: 'add',
callback: function(){
$(this).contextMenu('hide');
$o.ui.tabs.add(prompt('Channel'));
}
},
s1: '',
close: {
name: 'Close',
icon: 'delete',
callback: function(){
$(this).contextMenu('hide');
$o.ui.tabs.remove($(this).data('id'));
}
}
},
zIndex: 99999,
trigger: 'right'
});
$.contextMenu({
selector: '#tabs-list',
items: {
add: {
name: 'New Tab',
icon: 'add',
callback: function(){
$(this).contextMenu('hide');
$o.ui.tabs.add(prompt('channel'));
}
}
},
zIndex: 99999,
trigger: 'right'
});
$('#tabs-scroll-right').click(function(){
event('scroll right');
$tl.scrollTop(($tl.scrollTop()||0)+20);
if($tl.get(0).scrollHeight-20 == $tl.scrollTop()){
$('#tabs-scroll-right').addClass('disabled');
}
$('#tabs-scroll-left').removeClass('disabled');
});
$('#tabs-scroll-left').click(function(){
event('scroll left');
$tl.scrollTop(($tl.scrollTop()||0)-20);
if($tl.scrollTop() == 0){
$('#tabs-scroll-left').addClass('disabled');
}
$('#tabs-scroll-right').removeClass('disabled');
});
(function scrollup(){
$('#tabs-scroll-left').click();
if($tl.scrollTop() != 0){
setTimeout(scrollup,10);
}
})();
event('Date '+new Date,'ready');
$h.addClass('hovered');
setTimeout(function(){
$h.removeClass('hovered');
},1000);
$o.ui.render.settings();
if(settings.autoconnect){
$o.chat.connect();
}
});
delete window.io;
})(window,jQuery,io);
if (!Date.prototype.toISOString) {
Date.prototype.toISOString = function() {
function pad(n) { return n < 10 ? '0' + n : n }
return this.getUTCFullYear() + '-'
+ pad(this.getUTCMonth() + 1) + '-'
+ pad(this.getUTCDate()) + 'T'
+ pad(this.getUTCHours()) + ':'
+ pad(this.getUTCMinutes()) + ':'
+ pad(this.getUTCSeconds()) + 'Z';
};
}
if(!String.prototype.isNumber){
String.prototype.isNumber = function(){return /^\d+$/.test(this);}
}