').html('-- loaded old scrollback for '+scroll[i].date+' --')
)
.children()
.children('.remove')
.remove();
$(frag)
.children()
.children('.to_remove')
.removeClass('to_remove')
.addClass('remove');
event('loading old tab scrollback for '+name+' last saved +'+scroll[i].date);
}
}
tabs.push({
name: name,
title: title,
body: frag,
names: []
});
$tl.append($o.tabObj(tabs.length-1));
$o.refreshTabs();
$o.renderUsers();
}else{
event('Attempted to add an existing tab');
}
},
removeTab: function(id){
if(typeof tabs[id] != 'undefined'){
event('Tab removed: '+tabs[id].name);
socket.emit('part',{
name: tabs[id].name
});
tabs.splice(id,1);
if(selectedTab==id&&selectedTab>0){
selectedTab--;
}
}
$o.refreshTabs();
$cl.html(tabs[selectedTab].body);
$o.renderUsers();
},
tabObj: function(id){
if(typeof id !== 'undefined'){
return $('')
.addClass('tab')
.text(tabs[id].title)
.mouseup(function(e){
switch(e.which){
case 1: // RMB
if($(this).data('id')!=selectedTab){
$o.selectTab($(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.removeTab(id);
return false;
})
.css({
'position': 'absolute',
'background-color': 'inherit',
'top': 0,
'right': 0
})
.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);
}
if($tl.get(0).scrollHeight-20 != $tl.scrollTop()){
$('#tabs-scroll-right').removeClass('disabled');
}
if($tl.scrollTop() != 0){
$('#tabs-scroll-left').removeClass('disabled');
}
}
});
String.prototype.htmlentities = function(){
return this.replace(/&/g, '&').replace(/\s/g, ' ').replace(//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');
var title = prompt('Title');
tabs.push({
name: prompt('channel'),
title: title,
topic: 'Topic for '+title
});
$o.refreshTabs();
}
},
s1: '',
close: {
name: 'Close',
icon: 'delete',
callback: function(){
$(this).contextMenu('hide');
$o.removeTab($(this).data('id'));
}
}
},
zIndex: 99999,
trigger: 'right'
});
$.contextMenu({
selector: '#tabs-list',
items: {
add: {
name: 'New Tab',
icon: 'add',
callback: function(){
$(this).contextMenu('hide');
var title = prompt('Title');
tabs.push({
name: prompt('channel'),
title: title,
topic: 'Topic for '+title
});
$o.refreshTabs();
}
}
},
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);
}
})();
//DEBUG
/* for(var i=0;i<20;i++){
tabs.push({
name: '#Tab'+i,
title: 'Tab '+i,
topic: 'Topic for tab '+i
});
} */
//END DEBUG
event('Date '+new Date,'ready');
$h.addClass('hovered');
setTimeout(function(){
$h.removeClass('hovered');
},1000);
$o.renderSettings();
if(settings.autoconnect){
$o.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';
};
}