From 697677a4312edb94ec83c29373f72aba720bcd62 Mon Sep 17 00:00:00 2001 From: Henry Rapley Date: Sat, 28 Sep 2013 14:39:33 +0100 Subject: [PATCH] saving progress. bug fix. got UI building separate from the client. need to work out kinks. #87 --- dist/chatterbox.js | 39 +++++++++++++++++- dist/chatterbox.min.js | 28 ++++++------- dist/wsc.dAmn.js | 39 +++++++++++++++++- dist/wsc.dAmn.min.js | 94 +++++++++++++++++++++--------------------- dist/wsc.js | 39 +++++++++++++++++- dist/wsc.min.js | 94 +++++++++++++++++++++--------------------- src/ui/base.js | 31 +++++++++++++- src/ui/protocol.js | 8 +++- 8 files changed, 256 insertions(+), 116 deletions(-) diff --git a/dist/chatterbox.js b/dist/chatterbox.js index 05ad235..6449c82 100644 --- a/dist/chatterbox.js +++ b/dist/chatterbox.js @@ -10,6 +10,35 @@ Chatterbox.STATE = 'beta'; Chatterbox._gum = function( ) {}; + +// jQuery hook. + +( function( $ ) { + $.fn.chatterbox = function( method, client, options ) { + + var ui = $(window).data('chatterbox'); + + if( method == 'init' || ui === undefined ) { + if( ui == undefined ) { + ui = new Chatterbox.UI( $(this), client, options, ($.browser.mozilla || false) ); + $(window).resize(ui.resize); + } + $(window).data('chatterbox', ui); + } + + if( method != 'init' && method != undefined ) { + method = 'jq_' + method; + if( method in ui ) + ui[method]( $(this), options); + } + + return ui; + + }; + +} )( jQuery ); + + /** * This object is the platform for the wsc UI. Everything can be used and * loaded from here. @@ -22,7 +51,7 @@ Chatterbox._gum = function( ) {}; * @param mozilla {Boolean} Is the browser in use made by Mozilla? * @param [events] {Object} EventEmitter object. **/ -Chatterbox.UI = function( client, view, options, mozilla, events ) { +Chatterbox.UI = function( view, client, options, mozilla, events ) { this.client = client; this.events = events || new EventEmitter(); @@ -4046,7 +4075,11 @@ Chatterbox.Popup.ItemPicker.Page.prototype.hide = function( ) { /** - * Parser for dAmn-like protocols. + * Rendering for dAmn-like protocols. + * + * This object is mainly used for constructing LogMessage objects with the + * right data. Seemed to make more sense than having multiple definitions of + * LogMessage and/or if...else/switch...case blocks. * * @class Chatterbox.Protocol * @constructor @@ -4267,6 +4300,8 @@ Chatterbox.Protocol.prototype.log = function( event ) { */ Chatterbox.Protocol.LogMessage = function( event, options ) { + options = options || {}; + this.event = event; this.template = options.template || ''; this.keys = options.keys || []; diff --git a/dist/chatterbox.min.js b/dist/chatterbox.min.js index d8d342c..37e496e 100644 --- a/dist/chatterbox.min.js +++ b/dist/chatterbox.min.js @@ -1,16 +1,16 @@ -var Chatterbox={};Chatterbox.VERSION="0.20.104";Chatterbox.STATE="beta";Chatterbox._gum=function(){};Chatterbox.UI=function(b,a,c,e,d){this.client=b;this.events=d||new EventEmitter();this.mozilla=e;this.umuted=[];this.viewing=true;this.settings={themes:["wsct_dAmn","wsct_dark"],theme:"wsct_dark",monitor:["~Monitor",true],username:"",domain:"website.com",clock:true,tabclose:true,developer:false,media:"/static/"};var f=this;this.sound={bank:{m:null},add:function(g,h){if(f.sound.hasOwnProperty(g)){return false}f.sound.bank[g]=h;h.load();f.sound[g]=function(){f.sound.play(f.sound.bank[g])};return true},play:function(g){g.pause();g.currentTime=0;g.play()},toggle:function(h){for(var g in f.sound.bank){if(!f.sound.bank.hasOwnProperty(g)){continue}f.sound.bank[g].muted=h}},mute:function(){f.sound.toggle(true)},unmute:function(){f.sound.toggle(false)},};this.settings=a.extend(this.settings,c);a.append('
');this.mw=new wsc.Middleware();this.view=a.find(".wsc"); -this.mns=this.format_ns(this.settings.monitor[0]);this.lun=this.settings.username.toLowerCase();this.monitoro=null;this.swidth=(function(){if($.browser.msie){var j=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body"),h=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body");scrollbarWidth=j.width()-h.width();j.add(h).remove()}else{var g=$("
").css({width:100,height:100,overflow:"auto",position:"absolute",top:-1000,left:-1000}).prependTo("body").append("
").find("div").css({width:"100%",height:200});scrollbarWidth=100-g.width();g.parent().remove()}return scrollbarWidth})();if(window.mozRTCPeerConnection){Chatterbox._gum=function(h,j,g){return navigator.mozGetUserMedia(h,j,g)}}if(window.webkitRTCPeerConnection){Chatterbox._gum=function(h,j,g){return navigator.webkitGetUserMedia(h,j,g)}}if(window.RTCPeerConnection&&!window.mozRTCPeerConnection){Chatterbox._gum=function(h,j,g){return navigator.getUserMedia(h,j,g) -}}this.LIB="Chatterbox";this.VERSION=Chatterbox.VERSION;this.STATE=Chatterbox.STATE};wsc.defaults.UI=Chatterbox.UI;Chatterbox.UI.prototype.trigger=function(a,b){this.events.emit(a,b,this)};Chatterbox.UI.prototype.on=function(b,a){this.events.addListener(b,a)};Chatterbox.UI.prototype.middle=function(a,b){return this.mw.add(a,b)};Chatterbox.UI.prototype.cascade=function(a,c,b){this.mw.run(a,c,b)};Chatterbox.UI.prototype.remove_listeners=function(){this.events.removeListeners()};Chatterbox.UI.prototype.deform_ns=function(b){var a=b[0];if(a=="#"||a=="@"||a=="~"||a=="+"){return b}if(b.indexOf("chat:")==0){return"#"+b.slice(5)}if(b.indexOf("server:")==0){return"~"+b.slice(7)}if(b.indexOf("feed:")==0){return"#"+b.slice(5)}if(b.indexOf("login:")==0){return"@"+b.slice(6)}if(b.indexOf("pchat:")==0){var c=b.split(":");c.shift();for(i in c){name=c[i];if(name.toLowerCase()!=this.lun){return"@"+name}}}return"#"+b};Chatterbox.UI.prototype.format_ns=function(a){var c=a.slice(1);switch(a[0]){case"@":var b=[c,this.lun]; -b.sort(caseInsensitiveSort);b.unshift("pchat");a=b.join(":");break;case"~":a="server:"+c;break;case"+":a="feed:"+c;break;case"#":a="chat:"+c;break;default:if(a.indexOf("chat:")==0||a.indexOf("pchat:")==0||a.indexOf("server:")==0||a.indexOf("feed:")==0){break}a="chat:"+a;break}return a};Chatterbox.UI.prototype.set_events=function(a){this.events=a||this.events};Chatterbox.UI.prototype.clock=function(a){if(a===undefined||a==this.settings.clock){return this.settings.clock}this.settings.clock=a;this.chatbook.retime();return this.settings.clock};Chatterbox.UI.prototype.get_user_media=function(b,c,a){Chatterbox._gum(b,c,a)};Chatterbox.UI.prototype.build=function(g,a,b){this.view.append(Chatterbox.render("ui",this.settings));this.control=new (g||Chatterbox.Control)(this);this.nav=new (a||Chatterbox.Navigation)(this);this.chatbook=new (b||Chatterbox.Chatbook)(this);this.pager=new Chatterbox.Pager(this);this.monitoro=this.chatbook.create_channel(this.mns,this.settings.monitor[1],true);this.monitoro.show(); -this.control.focus();this.sound.bank.m=this.view.find("div.soundbank");this.sound.add("click",this.sound.bank.m.find("audio.click")[0]);var f=this.sound;var d=false;var c=this.nav.add_button({label:"",icon:"volume",href:"#mute",title:"Mute the client",handler:function(){if(!d){f.mute();c.removeClass("volume");c.addClass("volume_mute");c.prop("title","Unmute the client");d=true;return false}f.unmute();c.removeClass("volume_mute");c.addClass("volume");c.prop("title","Mute the client");d=false;return false}});var e=this;$(window).focus(function(){e.viewing=true});$(window).blur(function(){e.viewing=false});this.client.bind("pkt",function(j,h){e.packet(j,h)});this.client.middle("ns.remove",function(j,h){e.remove_channel(j.ns);h(j)});this.client.bind("ns.create",function(j,h){e.create_channel(j.chan.raw,j.chan.hidden)});this.client.bind("ns.user.list",function(h){e.channel(h.ns).set_user_list(h.users)});this.client.middle("ns.user.privchg",function(j,h){e.channel(j.ns).privchg(j,h)});this.client.bind("ns.user.remove",function(j,h){e.channel(j.ns).remove_one_user(j.user) -});this.client.bind("ns.user.registered",function(h){e.channel(h.ns).register_user(h.user)})};Chatterbox.UI.prototype.resize=function(){this.control.resize();this.view.height(this.view.parent().height());this.nav.resize();this.chatbook.resize(((this.view.parent().height()-this.nav.height())-this.control.height())-5)};Chatterbox.UI.prototype.loop=function(){this.chatbook.loop()};Chatterbox.UI.prototype.packet=function(b,a){var c=this;var d=a.protocol.log(b);if(d){if(this.settings.developer){console.log(">>>",b.sns,"|",d.text())}if(b.hasOwnProperty("s")&&b.s=="0"){this.chatbook.handle(b,a);return}b.html=d.html();this.cascade("log_message",function(f,e){c.chatbook.log_message(f.message,f.event)},{message:d,event:b})}this.chatbook.handle(b,a)};Chatterbox.UI.prototype.create_channel=function(b,a){this.chatbook.create_channel(b,a)};Chatterbox.UI.prototype.remove_channel=function(a){this.chatbook.remove_channel(a)};Chatterbox.UI.prototype.toggle_channel=function(a){return this.chatbook.toggle_channel(a) -};Chatterbox.UI.prototype.channel=function(a,b){return this.chatbook.channel(a,b)};Chatterbox.UI.prototype.channels=function(){return this.chatbook.channels()};Chatterbox.UI.prototype.channel_left=function(){this.chatbook.channel_left()};Chatterbox.UI.prototype.channel_right=function(){this.chatbook.channel_right()};Chatterbox.UI.prototype.monitor=function(b,a){this.monitoro.server_message(b,a)};Chatterbox.UI.prototype.server_message=function(b,a){this.chatbook.server_message(b,a)};Chatterbox.UI.prototype.log_item=function(a){this.chatbook.log_item(a)};Chatterbox.UI.prototype.log=function(a){this.chatbook.log(a)};Chatterbox.UI.prototype.mute_user=function(a){if(!a){return false}a=a.toLowerCase();if(this.umuted.indexOf(a)!=-1){return false}this.umuted.push(a);this.chatbook.each(function(b,c){c.mute_user(a)});return true};Chatterbox.UI.prototype.unmute_user=function(a){if(!a){return false}a=a.toLowerCase();var b=this.umuted.indexOf(a);if(b==-1){return false}this.umuted.splice(b,1);this.chatbook.each(function(c,d){d.unmute_user(a) -});return true};Chatterbox.UI.prototype.clear_user=function(a){this.chatbook.each(function(b,c){c.clear_user(a)})};Chatterbox.UI.prototype.theme=function(a){if(this.settings.theme==a){return this.settings.theme}if(this.settings.themes.indexOf(a)==-1){a="wsct_"+a;if(this.settings.themes.indexOf(a)==-1){return this.settings.theme}}this.view.removeClass(this.settings.theme).addClass(a);this.settings.theme=a;this.trigger("theme.set",{name:"theme.set",theme:a});return this.settings.theme};Chatterbox.UI.prototype.add_theme=function(a){if(this.settings.themes.indexOf(a)>-1){return}this.settings.themes.push(a)};Chatterbox.UI.prototype.developer=function(a){this.settings.developer=a;this.chatbook.developer()};Chatterbox.BaseTab=function(d,b,c,a){this.manager=d;this.hidden=c;this.monitor=(a==undefined?false:a);this.built=false;this.raw=b;this.selector="t-"+(b||"chan").toLowerCase();this.namespace=b;this.visible=false;this.st=0;this.el={t:{o:null,l:null,c:null,},m:null,l:{p:null,w:null,},u:null,h:{title:null,topic:null}}; -this.mulw=0;this.d={u:[0,0],h:{title:[0,0],topic:[0,0]}};if(!d){return}this.raw=d.format_ns(b);this.selector=(this.raw.substr(0,2)=="pc"?"pc":"c")+"-"+d.deform_ns(b).slice(1).toLowerCase();this.namespace=d.deform_ns(b)};Chatterbox.BaseTab.prototype.build=function(b){if(!this.manager){return}if(this.built){return}var a=this.selector;var d=this.namespace;var c=this.raw;this.el.t.o=this.manager.nav.add_tab(a,d);this.el.t.l=this.el.t.o.find(".tab");this.el.t.c=this.el.t.o.find(".close");this.manager.chatbook.view.append(b||Chatterbox.render("basetab",{selector:a,ns:d}));this.el.m=this.window=this.manager.chatbook.view.find("#"+a+"-window");var e=this;this.el.t.l.click(function(){e.manager.toggle_channel(c);return false});this.el.t.c.click(function(f){e.manager.trigger("tab.close.clicked",{ns:e.raw,chan:e,e:f});return false});if(this.hidden&&!this.manager.settings.developer){this.el.t.o.toggleClass("hidden")}this.built=true};Chatterbox.BaseTab.prototype.hide=function(){this.el.m.css({display:"none"}); -this.el.t.o.removeClass("active");this.visible=false};Chatterbox.BaseTab.prototype.show=function(){this.visible=true;this.el.m.css({display:"block"});this.el.t.o.addClass("active");this.el.t.o.removeClass("noise chatting tabbed fill");var a=this;setTimeout(function(){a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight());a.resize();a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight())},100)};Chatterbox.BaseTab.prototype.developer=function(){if(this.manager.settings.developer){this.el.t.o.removeClass("hidden");return}if(this.hidden){this.el.t.o.addClass("hidden")}};Chatterbox.BaseTab.prototype.remove=function(){this.el.t.o.remove();this.el.m.remove()};Chatterbox.BaseTab.prototype.resize=function(b,a){this.el.m.css({height:a||this.manager.chatbook.height(),width:(b||this.manager.chatbook.width())-10})};Chatterbox.BaseTab.prototype.loop=function(){};Chatterbox.Channel=function(d,b,c,a){Chatterbox.BaseTab.call(this,d,b,c,a);this.resized=function(){};this.ulbuf=0 -};Chatterbox.Channel.prototype=new Chatterbox.BaseTab;Chatterbox.Channel.prototype.constructor=Chatterbox.Channel;Chatterbox.Channel.prototype.build=function(){if(!this.manager){return}if(this.built){return}var a=this.selector;var c=this.namespace;var b=this.raw;Chatterbox.BaseTab.prototype.build.call(this,Chatterbox.render("channel",{selector:a,ns:c}));this.el.l.p=this.el.m.find("#"+a+"-log");this.el.l.w=this.el.l.p.find("ul.logwrap");this.el.u=this.el.m.find("#"+a+"-users");this.mulw=parseInt(this.el.u.css("max-width").slice(0,-2));var d=this;var e=false;this.el.l.w.click(function(){if(!e){return}d.manager.control.focus()});this.el.l.w.mousedown(function(){e=true});this.el.l.w.mousemove(function(){e=false});this.el.t.l.click(function(){d.manager.toggle_channel(b);return false});this.setup_header("title");this.setup_header("topic");if(this.namespace[0]=="@"){this.build_user_list({100:"Room Members"},[100])}this.built=true};Chatterbox.Channel.prototype.setup_header=function(a){var c=this; -var b={};b.m=this.el.m.find("header."+a+" div");b.e=this.el.m.find("header."+a+" a[href=#edit]");b.t=this.el.m.find("header."+a+" textarea");b.s=this.el.m.find("header."+a+" a[href=#save]");b.c=this.el.m.find("header."+a+" a[href=#cancel]");this.el.h[a]=b.m;b.m.parent().mouseover(function(f){if(!b.editing){b.e.css("display","block");return}b.s.css("display","block");b.c.css("display","block")});b.m.parent().mouseout(function(f){if(!b.editing){b.e.css("display","none");return}b.s.css("display","none");b.c.css("display","none")});b.e.click(function(f){b.t.text(c.manager.client.channel(c.namespace).info[a].content);b.t.css({display:"block",width:c.el.h[a].innerWidth()-10,});c.el.h[a].css("display","none");b.e.css("display","none");b.editing=true;c.resize();return false});var d=function(){var e=b.t.val();b.t.text("");b.t.css("display","none");c.el.h[a].css("display","block");b.s.css("display","none");b.c.css("display","none");b.editing=false;c.resize();return e};b.s.click(function(f){var g=d(); -c.manager.trigger(a+".save",{ns:c.raw,value:g});b.t.text("");return false});b.c.click(function(f){d();return false})};Chatterbox.Channel.prototype.scroll=function(){this.pad();var a=this.el.l.w.prop("scrollWidth")-this.el.l.w.innerWidth();var b=this.el.l.w.prop("scrollHeight")-this.el.l.w.innerHeight();if(a>0){b+=a}if(b<0||(b-this.el.l.w.scrollTop())>100){return}this.el.l.w.scrollTop(b)};Chatterbox.Channel.prototype.pad=function(){this.el.l.w.css({"padding-top":0,height:"auto"});var b=this.el.l.w.innerHeight();var a=this.el.l.p.innerHeight()-this.el.h.topic.parent().outerHeight();var c=a-b;if(c>0){this.el.l.w.css({"padding-top":c})}else{this.el.l.w.css({"padding-top":0,height:a})}this.el.l.w.scrollTop(this.st)};Chatterbox.Channel.prototype.resize=function(f,a){Chatterbox.BaseTab.prototype.resize.call(this,f,a);var g={title:{m:this.el.m.find("header div.title"),e:this.el.m.find("header.title a[href=#edit]")},topic:{m:this.el.m.find("header div.topic"),e:this.el.m.find("header.topic a[href=#edit]")}}; +var Chatterbox={};Chatterbox.VERSION="0.20.104";Chatterbox.STATE="beta";Chatterbox._gum=function(){};(function(a){a.fn.chatterbox=function(e,b,c){var d=a(window).data("chatterbox");if(e=="init"||d===undefined){if(d==undefined){d=new Chatterbox.UI(a(this),b,c,(a.browser.mozilla||false));a(window).resize(d.resize)}a(window).data("chatterbox",d)}if(e!="init"&&e!=undefined){e="jq_"+e;if(e in d){d[e](a(this),c)}}return d}})(jQuery);Chatterbox.UI=function(b,a,c,e,d){this.client=a;this.events=d||new EventEmitter();this.mozilla=e;this.umuted=[];this.viewing=true;this.settings={themes:["wsct_dAmn","wsct_dark"],theme:"wsct_dark",monitor:["~Monitor",true],username:"",domain:"website.com",clock:true,tabclose:true,developer:false,media:"/static/"};var f=this;this.sound={bank:{m:null},add:function(g,h){if(f.sound.hasOwnProperty(g)){return false}f.sound.bank[g]=h;h.load();f.sound[g]=function(){f.sound.play(f.sound.bank[g])};return true},play:function(g){g.pause();g.currentTime=0;g.play()},toggle:function(h){for(var g in f.sound.bank){if(!f.sound.bank.hasOwnProperty(g)){continue +}f.sound.bank[g].muted=h}},mute:function(){f.sound.toggle(true)},unmute:function(){f.sound.toggle(false)},};this.settings=b.extend(this.settings,c);b.append('
');this.mw=new wsc.Middleware();this.view=b.find(".wsc");this.mns=this.format_ns(this.settings.monitor[0]);this.lun=this.settings.username.toLowerCase();this.monitoro=null;this.swidth=(function(){if($.browser.msie){var j=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body"),h=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body");scrollbarWidth=j.width()-h.width();j.add(h).remove()}else{var g=$("
").css({width:100,height:100,overflow:"auto",position:"absolute",top:-1000,left:-1000}).prependTo("body").append("
").find("div").css({width:"100%",height:200});scrollbarWidth=100-g.width();g.parent().remove()}return scrollbarWidth})();if(window.mozRTCPeerConnection){Chatterbox._gum=function(h,j,g){return navigator.mozGetUserMedia(h,j,g) +}}if(window.webkitRTCPeerConnection){Chatterbox._gum=function(h,j,g){return navigator.webkitGetUserMedia(h,j,g)}}if(window.RTCPeerConnection&&!window.mozRTCPeerConnection){Chatterbox._gum=function(h,j,g){return navigator.getUserMedia(h,j,g)}}this.LIB="Chatterbox";this.VERSION=Chatterbox.VERSION;this.STATE=Chatterbox.STATE};wsc.defaults.UI=Chatterbox.UI;Chatterbox.UI.prototype.trigger=function(a,b){this.events.emit(a,b,this)};Chatterbox.UI.prototype.on=function(b,a){this.events.addListener(b,a)};Chatterbox.UI.prototype.middle=function(a,b){return this.mw.add(a,b)};Chatterbox.UI.prototype.cascade=function(a,c,b){this.mw.run(a,c,b)};Chatterbox.UI.prototype.remove_listeners=function(){this.events.removeListeners()};Chatterbox.UI.prototype.deform_ns=function(b){var a=b[0];if(a=="#"||a=="@"||a=="~"||a=="+"){return b}if(b.indexOf("chat:")==0){return"#"+b.slice(5)}if(b.indexOf("server:")==0){return"~"+b.slice(7)}if(b.indexOf("feed:")==0){return"#"+b.slice(5)}if(b.indexOf("login:")==0){return"@"+b.slice(6) +}if(b.indexOf("pchat:")==0){var c=b.split(":");c.shift();for(i in c){name=c[i];if(name.toLowerCase()!=this.lun){return"@"+name}}}return"#"+b};Chatterbox.UI.prototype.format_ns=function(a){var c=a.slice(1);switch(a[0]){case"@":var b=[c,this.lun];b.sort(caseInsensitiveSort);b.unshift("pchat");a=b.join(":");break;case"~":a="server:"+c;break;case"+":a="feed:"+c;break;case"#":a="chat:"+c;break;default:if(a.indexOf("chat:")==0||a.indexOf("pchat:")==0||a.indexOf("server:")==0||a.indexOf("feed:")==0){break}a="chat:"+a;break}return a};Chatterbox.UI.prototype.set_events=function(a){this.events=a||this.events};Chatterbox.UI.prototype.clock=function(a){if(a===undefined||a==this.settings.clock){return this.settings.clock}this.settings.clock=a;this.chatbook.retime();return this.settings.clock};Chatterbox.UI.prototype.get_user_media=function(b,c,a){Chatterbox._gum(b,c,a)};Chatterbox.UI.prototype.build=function(g,a,b){this.view.append(Chatterbox.render("ui",this.settings));this.control=new (g||Chatterbox.Control)(this); +this.nav=new (a||Chatterbox.Navigation)(this);this.chatbook=new (b||Chatterbox.Chatbook)(this);this.pager=new Chatterbox.Pager(this);this.monitoro=this.chatbook.create_channel(this.mns,this.settings.monitor[1],true);this.monitoro.show();this.control.focus();this.sound.bank.m=this.view.find("div.soundbank");this.sound.add("click",this.sound.bank.m.find("audio.click")[0]);var f=this.sound;var d=false;var c=this.nav.add_button({label:"",icon:"volume",href:"#mute",title:"Mute the client",handler:function(){if(!d){f.mute();c.removeClass("volume");c.addClass("volume_mute");c.prop("title","Unmute the client");d=true;return false}f.unmute();c.removeClass("volume_mute");c.addClass("volume");c.prop("title","Mute the client");d=false;return false}});var e=this;$(window).focus(function(){e.viewing=true});$(window).blur(function(){e.viewing=false});this.client.bind("pkt",function(j,h){e.packet(j,h)});this.client.middle("ns.remove",function(j,h){e.remove_channel(j.ns);h(j)});this.client.bind("ns.create",function(j,h){e.create_channel(j.chan.raw,j.chan.hidden) +});this.client.bind("ns.user.list",function(h){e.channel(h.ns).set_user_list(h.users)});this.client.middle("ns.user.privchg",function(j,h){e.channel(j.ns).privchg(j,h)});this.client.bind("ns.user.remove",function(j,h){e.channel(j.ns).remove_one_user(j.user)});this.client.bind("ns.user.registered",function(h){e.channel(h.ns).register_user(h.user)})};Chatterbox.UI.prototype.resize=function(){this.control.resize();this.view.height(this.view.parent().height());this.nav.resize();this.chatbook.resize(((this.view.parent().height()-this.nav.height())-this.control.height())-5)};Chatterbox.UI.prototype.loop=function(){this.chatbook.loop()};Chatterbox.UI.prototype.packet=function(b,a){var c=this;var d=a.protocol.log(b);if(d){if(this.settings.developer){console.log(">>>",b.sns,"|",d.text())}if(b.hasOwnProperty("s")&&b.s=="0"){this.chatbook.handle(b,a);return}b.html=d.html();this.cascade("log_message",function(f,e){c.chatbook.log_message(f.message,f.event)},{message:d,event:b})}this.chatbook.handle(b,a) +};Chatterbox.UI.prototype.create_channel=function(b,a){this.chatbook.create_channel(b,a)};Chatterbox.UI.prototype.remove_channel=function(a){this.chatbook.remove_channel(a)};Chatterbox.UI.prototype.toggle_channel=function(a){return this.chatbook.toggle_channel(a)};Chatterbox.UI.prototype.channel=function(a,b){return this.chatbook.channel(a,b)};Chatterbox.UI.prototype.channels=function(){return this.chatbook.channels()};Chatterbox.UI.prototype.channel_left=function(){this.chatbook.channel_left()};Chatterbox.UI.prototype.channel_right=function(){this.chatbook.channel_right()};Chatterbox.UI.prototype.monitor=function(b,a){this.monitoro.server_message(b,a)};Chatterbox.UI.prototype.server_message=function(b,a){this.chatbook.server_message(b,a)};Chatterbox.UI.prototype.log_item=function(a){this.chatbook.log_item(a)};Chatterbox.UI.prototype.log=function(a){this.chatbook.log(a)};Chatterbox.UI.prototype.mute_user=function(a){if(!a){return false}a=a.toLowerCase();if(this.umuted.indexOf(a)!=-1){return false +}this.umuted.push(a);this.chatbook.each(function(b,c){c.mute_user(a)});return true};Chatterbox.UI.prototype.unmute_user=function(a){if(!a){return false}a=a.toLowerCase();var b=this.umuted.indexOf(a);if(b==-1){return false}this.umuted.splice(b,1);this.chatbook.each(function(c,d){d.unmute_user(a)});return true};Chatterbox.UI.prototype.clear_user=function(a){this.chatbook.each(function(b,c){c.clear_user(a)})};Chatterbox.UI.prototype.theme=function(a){if(this.settings.theme==a){return this.settings.theme}if(this.settings.themes.indexOf(a)==-1){a="wsct_"+a;if(this.settings.themes.indexOf(a)==-1){return this.settings.theme}}this.view.removeClass(this.settings.theme).addClass(a);this.settings.theme=a;this.trigger("theme.set",{name:"theme.set",theme:a});return this.settings.theme};Chatterbox.UI.prototype.add_theme=function(a){if(this.settings.themes.indexOf(a)>-1){return}this.settings.themes.push(a)};Chatterbox.UI.prototype.developer=function(a){this.settings.developer=a;this.chatbook.developer() +};Chatterbox.BaseTab=function(d,b,c,a){this.manager=d;this.hidden=c;this.monitor=(a==undefined?false:a);this.built=false;this.raw=b;this.selector="t-"+(b||"chan").toLowerCase();this.namespace=b;this.visible=false;this.st=0;this.el={t:{o:null,l:null,c:null,},m:null,l:{p:null,w:null,},u:null,h:{title:null,topic:null}};this.mulw=0;this.d={u:[0,0],h:{title:[0,0],topic:[0,0]}};if(!d){return}this.raw=d.format_ns(b);this.selector=(this.raw.substr(0,2)=="pc"?"pc":"c")+"-"+d.deform_ns(b).slice(1).toLowerCase();this.namespace=d.deform_ns(b)};Chatterbox.BaseTab.prototype.build=function(b){if(!this.manager){return}if(this.built){return}var a=this.selector;var d=this.namespace;var c=this.raw;this.el.t.o=this.manager.nav.add_tab(a,d);this.el.t.l=this.el.t.o.find(".tab");this.el.t.c=this.el.t.o.find(".close");this.manager.chatbook.view.append(b||Chatterbox.render("basetab",{selector:a,ns:d}));this.el.m=this.window=this.manager.chatbook.view.find("#"+a+"-window");var e=this;this.el.t.l.click(function(){e.manager.toggle_channel(c); +return false});this.el.t.c.click(function(f){e.manager.trigger("tab.close.clicked",{ns:e.raw,chan:e,e:f});return false});if(this.hidden&&!this.manager.settings.developer){this.el.t.o.toggleClass("hidden")}this.built=true};Chatterbox.BaseTab.prototype.hide=function(){this.el.m.css({display:"none"});this.el.t.o.removeClass("active");this.visible=false};Chatterbox.BaseTab.prototype.show=function(){this.visible=true;this.el.m.css({display:"block"});this.el.t.o.addClass("active");this.el.t.o.removeClass("noise chatting tabbed fill");var a=this;setTimeout(function(){a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight());a.resize();a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight())},100)};Chatterbox.BaseTab.prototype.developer=function(){if(this.manager.settings.developer){this.el.t.o.removeClass("hidden");return}if(this.hidden){this.el.t.o.addClass("hidden")}};Chatterbox.BaseTab.prototype.remove=function(){this.el.t.o.remove();this.el.m.remove()};Chatterbox.BaseTab.prototype.resize=function(b,a){this.el.m.css({height:a||this.manager.chatbook.height(),width:(b||this.manager.chatbook.width())-10}) +};Chatterbox.BaseTab.prototype.loop=function(){};Chatterbox.Channel=function(d,b,c,a){Chatterbox.BaseTab.call(this,d,b,c,a);this.resized=function(){};this.ulbuf=0};Chatterbox.Channel.prototype=new Chatterbox.BaseTab;Chatterbox.Channel.prototype.constructor=Chatterbox.Channel;Chatterbox.Channel.prototype.build=function(){if(!this.manager){return}if(this.built){return}var a=this.selector;var c=this.namespace;var b=this.raw;Chatterbox.BaseTab.prototype.build.call(this,Chatterbox.render("channel",{selector:a,ns:c}));this.el.l.p=this.el.m.find("#"+a+"-log");this.el.l.w=this.el.l.p.find("ul.logwrap");this.el.u=this.el.m.find("#"+a+"-users");this.mulw=parseInt(this.el.u.css("max-width").slice(0,-2));var d=this;var e=false;this.el.l.w.click(function(){if(!e){return}d.manager.control.focus()});this.el.l.w.mousedown(function(){e=true});this.el.l.w.mousemove(function(){e=false});this.el.t.l.click(function(){d.manager.toggle_channel(b);return false});this.setup_header("title");this.setup_header("topic"); +if(this.namespace[0]=="@"){this.build_user_list({100:"Room Members"},[100])}this.built=true};Chatterbox.Channel.prototype.setup_header=function(a){var c=this;var b={};b.m=this.el.m.find("header."+a+" div");b.e=this.el.m.find("header."+a+" a[href=#edit]");b.t=this.el.m.find("header."+a+" textarea");b.s=this.el.m.find("header."+a+" a[href=#save]");b.c=this.el.m.find("header."+a+" a[href=#cancel]");this.el.h[a]=b.m;b.m.parent().mouseover(function(f){if(!b.editing){b.e.css("display","block");return}b.s.css("display","block");b.c.css("display","block")});b.m.parent().mouseout(function(f){if(!b.editing){b.e.css("display","none");return}b.s.css("display","none");b.c.css("display","none")});b.e.click(function(f){b.t.text(c.manager.client.channel(c.namespace).info[a].content);b.t.css({display:"block",width:c.el.h[a].innerWidth()-10,});c.el.h[a].css("display","none");b.e.css("display","none");b.editing=true;c.resize();return false});var d=function(){var e=b.t.val();b.t.text("");b.t.css("display","none"); +c.el.h[a].css("display","block");b.s.css("display","none");b.c.css("display","none");b.editing=false;c.resize();return e};b.s.click(function(f){var g=d();c.manager.trigger(a+".save",{ns:c.raw,value:g});b.t.text("");return false});b.c.click(function(f){d();return false})};Chatterbox.Channel.prototype.scroll=function(){this.pad();var a=this.el.l.w.prop("scrollWidth")-this.el.l.w.innerWidth();var b=this.el.l.w.prop("scrollHeight")-this.el.l.w.innerHeight();if(a>0){b+=a}if(b<0||(b-this.el.l.w.scrollTop())>100){return}this.el.l.w.scrollTop(b)};Chatterbox.Channel.prototype.pad=function(){this.el.l.w.css({"padding-top":0,height:"auto"});var b=this.el.l.w.innerHeight();var a=this.el.l.p.innerHeight()-this.el.h.topic.parent().outerHeight();var c=a-b;if(c>0){this.el.l.w.css({"padding-top":c})}else{this.el.l.w.css({"padding-top":0,height:a})}this.el.l.w.scrollTop(this.st)};Chatterbox.Channel.prototype.resize=function(f,a){Chatterbox.BaseTab.prototype.resize.call(this,f,a);var g={title:{m:this.el.m.find("header div.title"),e:this.el.m.find("header.title a[href=#edit]")},topic:{m:this.el.m.find("header div.topic"),e:this.el.m.find("header.topic a[href=#edit]")}}; this.el.l.w.css({"padding-top":0});a=a||this.manager.chatbook.height();f=f||this.manager.chatbook.width();var c=a;var b=this.el.m.width();this.el.u.width(1);this.d.u[0]=this.el.u[0].scrollWidth+this.manager.swidth+5;if(this.d.u[0]>this.mulw){this.d.u[0]=this.mulw}this.el.u.width(this.d.u[0]);b=b-this.d.u[0];c=c-g.title.m.parent().outerHeight();this.el.l.p.css({height:c-3,width:(b-10)-this.ulbuf});this.scroll();this.d.u[1]=this.el.l.p.innerHeight();this.el.u.css({height:this.d.u[1]});for(var e in g){if(!g.hasOwnProperty(e)){continue}if(g[e].m.html().length==0){continue}var d=(g[e].m.outerHeight(true)-5)*(-1);g[e].e.css("top",d)}this.resized()};Chatterbox.Channel.prototype.loop=function(){var a=this.el.l.p.find(".logmsg");if(a.length<200){return}a.slice(0,a.length-200).remove();this.resize()};Chatterbox.Channel.prototype.log=function(b){var a=this;this.manager.cascade("log",function(c){a.log_item({html:Chatterbox.render("logmsg",{message:c.message})})},{ns:this.raw,sns:this.namespace,message:b}) };Chatterbox.Channel.prototype.log_item=function(c){var a=new Date();var b="";if(this.manager.settings.clock){b=formatTime("{HH}:{mm}:{ss}",a)}else{b=formatTime("{hh}:{mm}:{ss} {mr}",a)}var d=this;this.manager.cascade("log_item",function(e){if(d.visible){d.st=d.el.l.w.scrollTop()}d.el.l.w.append(Chatterbox.render("logitem",e));d.manager.trigger("log_item.after",{item:d.el.l.w.find("li").last(),chan:d});if(d.visible){d.st+=d.el.l.w.find("li.logmsg").last().height();d.el.l.w.scrollTop(d.st)}d.scroll();d.noise()},{ns:this.namespace,ts:b,ms:a.getTime(),message:c.html,user:(c.user||"system").toLowerCase()})};Chatterbox.Channel.prototype.retime=function(){var a="";var b=this.el.l.w;if(this.manager.settings.clock){a="{HH}:{mm}:{ss}"}else{a="{hh}:{mm}:{ss} {mr}"}b.find("span.ts").each(function(c,d){el=b.find(d);time=new Date(parseInt(el.prop("id")));el.text(formatTime(a,time))})};Chatterbox.Channel.prototype.server_message=function(c,b){var a=this;this.manager.cascade("server_message",function(d){a.log_item({html:Chatterbox.render("servermsg",{message:d.message,info:d.info})}) },{ns:this.namespace,message:c,info:b})};Chatterbox.Channel.prototype.clear=function(){this.el.l.p.find("li.logmsg").remove();this.el.l.p.find("li.loginfo").remove();this.el.l.w.height(0);this.resize()};Chatterbox.Channel.prototype.log_info=function(e,d){var g={ns:this.namespace,ref:e,content:d};this.manager.trigger("log_info.before",g);delete g.ns;var a=this.el.l.w.append(Chatterbox.render("loginfobox",g));this.scroll();var f=this;var c=this.el.l.w.find("li."+g.ref);c.find("a.close").click(function(b){f.el.l.w.find(this).parent().remove();f.resize();return false});this.scroll();return c};Chatterbox.Channel.prototype.log_whois=function(j){var e={avatar:'avatar',username:""+j.symbol+j.username+"",info:[],conns:[],raw:j,};for(var k in j.connections){var h=j.connections[k];var m=[];if(h.online){var a=(new Date-(h.online*1000));m.push(["online",DateStamp(a/1000)+formatTime(" [{HH}:{mm}:{ss}]",new Date(a))])}if(h.idle){m.push(["idle",timeLengthString(h.idle)]) @@ -44,7 +44,7 @@ Chatterbox.Popup.ItemPicker.prototype.build=function(){this.options.content=Chat };Chatterbox.Popup.ItemPicker.prototype.add_button=function(a){a=Object.extend({href:"#button",title:"Button",label:"Button"},(a||{}));this.buttons.append(Chatterbox.render("ip.button",a));return this.buttons.find("a[href="+a.href+"]")};Chatterbox.Popup.ItemPicker.prototype.select=function(a){this.options.event.select(a)};Chatterbox.Popup.ItemPicker.prototype.select_page=function(a){if(!a){return}if(this.cpage!=null){this.cpage.hide()}this.cpage=a||null;if(this.cpage!=null){this.cpage.show()}};Chatterbox.Popup.ItemPicker.Page=function(b,a){this.picker=b;this.options=Object.extend({ref:"page",href:"#page",label:"Page",title:"page",items:[],content:"No items on this page.",},(a||{}));this.name=this.options.label;this.nrefresh=true};Chatterbox.Popup.ItemPicker.Page.prototype.build=function(){this.picker.pbook.append(Chatterbox.render("ip.page",this.options));this.picker.tabs.append(Chatterbox.render("ip.tab",this.options));this.view=this.picker.pbook.find("div.page#"+this.options.ref); this.items=this.view.find("ul");this.tab=this.picker.tabs.find("#"+this.options.ref);this.refresh();var a=this;this.tab.find("a").click(function(){a.picker.select_page(a);return false})};Chatterbox.Popup.ItemPicker.Page.prototype.refresh=function(){var a=this.build_list();if(a.length==0){this.options.content="No items on this page."}else{this.options.content="
    "+a+"
"}this.view.html(this.options.content);this.items=this.view.find("ul");this.hook_events();this.nrefresh=false};Chatterbox.Popup.ItemPicker.Page.prototype.hook_events=function(){var a=this;this.items.find("li").each(function(b,d){var e=a.view.find(d);var c=e.find(".value").html();e.click(function(){a.picker.select(c)})})};Chatterbox.Popup.ItemPicker.Page.prototype.build_list=function(){var c=[];var d=null;var f,e,b;for(var a in this.options.items){if(!this.options.items.hasOwnProperty(a)){continue}d=this.options.items[a];e=d.value||d;f=d.title||e;b=d.html||false;c.push('
  • '+(b?e:''+e+"")+"
  • ") }return c.join("")};Chatterbox.Popup.ItemPicker.Page.prototype.show=function(){this.tab.addClass("selected");this.view.css("display","block");this.refresh()};Chatterbox.Popup.ItemPicker.Page.prototype.hide=function(){this.tab.removeClass("selected");this.view.css("display","none")};Chatterbox.Protocol=function(){this.messages={chatserver:{keys:["version"],template:'** Connected to llama {version} *',global:true},dAmnServer:{keys:["version"],template:'** Connected to dAmnServer {version} *',global:true},login:{keys:["username","e","data"],template:'** Login as {username}: "{e}" *',global:true},join:{keys:["ns","e"],template:'** Join {ns}: "{e}" *',monitor:true},part:{keys:["ns","e","r"],template:'** Part {ns}: "{e}" * {r}',monitor:true},property:{keys:["ns","p","by","ts","value"],template:'** Got {p} for {ns} *',monitor:true},recv_msg:{keys:["user","message"],template:'<{user}>{message}'},recv_action:{keys:["s","user","message"],template:'* {user}{message}'},recv_join:{keys:["user","s","info"],template:'** {user} has joined *',},recv_part:{keys:["user","r"],template:'** {user} has left * {r}'},recv_privchg:{keys:["user","s","by","pc"],template:'** {user} has been made a member of {pc} by {by} *'},recv_kicked:{keys:["user","s","by","r"],template:'** {user} has been kicked by {by} * {r}'},recv_admin_create:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been created by {user} * {privs}'},recv_admin_update:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been updated by {user} * {privs}'},recv_admin_rename:{keys:["p","user","prev","pc"],template:'** Privilege class {prev} has been renamed to {pc} by {user} *'},recv_admin_move:{keys:["p","user","prev","pc","affected"],template:'** All members of {prev} have been moved to {pc} by {user} * {affected} affected user(s)'},recv_admin_remove:{keys:["p","user","pc","affected"],template:'** Privilege class {pc} has been removed by {user} * {affected} affected user(s)'},recv_admin_show:null,recv_admin_showverbose:null,recv_admin_privclass:{keys:["p","e","command"],template:'** Admin command "{command}" failed * {e}'},kicked:{keys:["ns","user","r"],template:'** You have been kicked by {user} * {r}'},ping:null,disconnect:{keys:["e"],template:'** You have been disconnected * {e}',global:true},send:{keys:["ns","e"],template:'** Send error: {e}'},kick:{keys:["ns","user","e"],template:'** Could not kick {user} * {e}'},get:{keys:["ns","p","e"],template:'** Could not get {p} info for {ns} * {e}'},set:{keys:["ns","p","e"],template:'** Could not set {p} * {e}'},kill:{keys:["ns","e"],template:'** Kill error * {e}'},unknown:{keys:["ns","packet"],template:'** Received unknown packet in {ns} * {packet}',monitor:true}} -};Chatterbox.Protocol.prototype.extend_messages=function(b){for(var a in b){this.messages[a]=b[a]}};Chatterbox.Protocol.prototype.log=function(b){var a=this.messages[b.name];return new Chatterbox.Protocol.LogMessage(b,a)};Chatterbox.Protocol.LogMessage=function(b,a){this.event=b;this.template=a.template||"";this.keys=a.keys||[];this.monitor=a.monitor||false;this.global=a.global||false;this._html=false;this._text=false;this._ansi=false};Chatterbox.Protocol.LogMessage.prototype.text=function(){if(this._text===false){this._text=this.render(0)}return this._text};Chatterbox.Protocol.LogMessage.prototype.html=function(){if(this._html===false){this._html=this.render(1)}return this._html};Chatterbox.Protocol.LogMessage.prototype.ansi=function(){if(this._ansi===false){this._ansi=this.render(2)}return this._ansi};Chatterbox.Protocol.LogMessage.prototype.render=function(c){if(c===undefined){c=0}var b=this.template;var e="";for(var a in this.keys){if(!this.keys.hasOwnProperty(a)){continue}key=this.keys[a]; +};Chatterbox.Protocol.prototype.extend_messages=function(b){for(var a in b){this.messages[a]=b[a]}};Chatterbox.Protocol.prototype.log=function(b){var a=this.messages[b.name];return new Chatterbox.Protocol.LogMessage(b,a)};Chatterbox.Protocol.LogMessage=function(b,a){a=a||{};this.event=b;this.template=a.template||"";this.keys=a.keys||[];this.monitor=a.monitor||false;this.global=a.global||false;this._html=false;this._text=false;this._ansi=false};Chatterbox.Protocol.LogMessage.prototype.text=function(){if(this._text===false){this._text=this.render(0)}return this._text};Chatterbox.Protocol.LogMessage.prototype.html=function(){if(this._html===false){this._html=this.render(1)}return this._html};Chatterbox.Protocol.LogMessage.prototype.ansi=function(){if(this._ansi===false){this._ansi=this.render(2)}return this._ansi};Chatterbox.Protocol.LogMessage.prototype.render=function(c){if(c===undefined){c=0}var b=this.template;var e="";for(var a in this.keys){if(!this.keys.hasOwnProperty(a)){continue}key=this.keys[a]; if(key instanceof Array){key=key[1]}if(!this.event.hasOwnProperty(key)||key=="pkt"){continue}e=this.event[key];if(e==null){continue}if(key=="ns"||key=="sns"){key="ns";e=this.event.sns}if(e.hasOwnProperty("_parser")){switch(c){case 1:e=e.html();break;case 2:e=e.ansi();break;case 0:default:e=e.text();break}}b=replaceAll(b,"{"+key+"}",e)}return b};Chatterbox.Settings=function(b,a){Chatterbox.Popup.call(this,b,{ref:"settings",title:"Settings",close:false,content:""});this.config=a;this.saveb=null;this.scb=null;this.tabs=null;this.book=null;this.changed=false;this.manager=b};Chatterbox.Settings.prototype=new Chatterbox.Popup();Chatterbox.Settings.prototype.constructor=Chatterbox.Settings;Chatterbox.Settings.prototype.build=function(){this.options.content=Chatterbox.template.settings.main;Chatterbox.Popup.prototype.build.call(this);this.saveb=this.window.find("a.button.save");this.closeb=this.window.find("a.close");this.scb=this.window.find("a.button.saveclose");this.tabs=this.window.find("nav.tabs ul.tabs"); this.book=this.window.find("div.book");this.config.build(this.manager,this);this.window.find("ul.tabs li").first().addClass("active");this.window.find("div.book div.page").first().addClass("active");var a=this;this.window.find("form").bind("change",function(){a.changed=true});this.config.each_page(function(b,c){c.each_item(function(d,e){e._onchange=function(f){a.changed=true}})});this.saveb.click(function(b){a.save();return false});this.closeb.click(function(b){if(a.changed){if(!confirm("Are you sure? You will lose any unsaved changes.")){return false}}a.close();return false});this.scb.click(function(b){a.save();a.close();return false});this.resize()};Chatterbox.Settings.prototype.resize=function(){var a=this.window.find(".inner");var c=a.find("h2");var d=a.find(".bookwrap");var b=a.find("footer");d.height(a.height()-b.outerHeight()-c.outerHeight()-15);this.book.height(d.innerHeight()-this.tabs.outerHeight()-25);this.book.width(d.innerWidth()-20);this.config.resize()};Chatterbox.Settings.prototype.switch_page=function(b){var c=this.tabs.find("li.active").first(); var a=c.prop("id").split("-",1)[0];c=this.config.page(a.split("_").join(" "));c.hide();b.show()};Chatterbox.Settings.prototype.save=function(){this.config.save(this);this.changed=false;this.manager.trigger("settings.save",{config:this.config})};Chatterbox.Settings.prototype.close=function(){this.window.remove();this.manager.nav.settings.open=false;this.manager.nav.settings.window=null;this.config.close(this);this.manager.trigger("settings.close",{config:this.config})};Chatterbox.Settings.Config=function(a){this.manager=a||null;this.pages=[]};Chatterbox.Settings.Config.prototype.find_page=function(b){var d=b.toLowerCase();var c;for(var a in this.pages){c=this.pages[a];if(c.lname==d){return c}}return null};Chatterbox.Settings.Config.prototype.build=function(c,b){c=c||this.manager;for(var a in this.pages){this.pages[a].build(c,b)}};Chatterbox.Settings.Config.prototype.resize=function(){for(var a in this.pages){this.pages[a].resize()}};Chatterbox.Settings.Config.prototype.page=function(b,a){var c=this.find_page(b); diff --git a/dist/wsc.dAmn.js b/dist/wsc.dAmn.js index 9e3962d..b66f3db 100644 --- a/dist/wsc.dAmn.js +++ b/dist/wsc.dAmn.js @@ -4196,6 +4196,35 @@ Chatterbox.STATE = 'beta'; Chatterbox._gum = function( ) {}; + +// jQuery hook. + +( function( $ ) { + $.fn.chatterbox = function( method, client, options ) { + + var ui = $(window).data('chatterbox'); + + if( method == 'init' || ui === undefined ) { + if( ui == undefined ) { + ui = new Chatterbox.UI( $(this), client, options, ($.browser.mozilla || false) ); + $(window).resize(ui.resize); + } + $(window).data('chatterbox', ui); + } + + if( method != 'init' && method != undefined ) { + method = 'jq_' + method; + if( method in ui ) + ui[method]( $(this), options); + } + + return ui; + + }; + +} )( jQuery ); + + /** * This object is the platform for the wsc UI. Everything can be used and * loaded from here. @@ -4208,7 +4237,7 @@ Chatterbox._gum = function( ) {}; * @param mozilla {Boolean} Is the browser in use made by Mozilla? * @param [events] {Object} EventEmitter object. **/ -Chatterbox.UI = function( client, view, options, mozilla, events ) { +Chatterbox.UI = function( view, client, options, mozilla, events ) { this.client = client; this.events = events || new EventEmitter(); @@ -8232,7 +8261,11 @@ Chatterbox.Popup.ItemPicker.Page.prototype.hide = function( ) { /** - * Parser for dAmn-like protocols. + * Rendering for dAmn-like protocols. + * + * This object is mainly used for constructing LogMessage objects with the + * right data. Seemed to make more sense than having multiple definitions of + * LogMessage and/or if...else/switch...case blocks. * * @class Chatterbox.Protocol * @constructor @@ -8453,6 +8486,8 @@ Chatterbox.Protocol.prototype.log = function( event ) { */ Chatterbox.Protocol.LogMessage = function( event, options ) { + options = options || {}; + this.event = event; this.template = options.template || ''; this.keys = options.keys || []; diff --git a/dist/wsc.dAmn.min.js b/dist/wsc.dAmn.min.js index affb290..12ddf59 100644 --- a/dist/wsc.dAmn.min.js +++ b/dist/wsc.dAmn.min.js @@ -45,53 +45,53 @@ this.storage.ui.set("clock",this.settings.ui.clock.toString());this.storage.ui.s break;default:if(a.indexOf("chat:")==0||a.indexOf("pchat:")==0||a.indexOf("server:")==0||a.indexOf("feed:")==0){break}a="chat:"+a;break}return a};wsc.Client.prototype.create_ns=function(b,f,a){var g=this.channel(b,new wsc.Channel(this,b,f,a));this.trigger("ns.create",{name:"ns.create",ns:b,chan:g,client:this});g.build()};wsc.Client.prototype.remove_ns=function(a){if(!a){return}this.cascade("ns.remove",function(b){var f=b.client.channel(b.ns);if(!f){return}delete b.client.channelo[f.raw.toLowerCase()]},{ns:a,client:this})};wsc.Client.prototype.select_ns=function(a){this.cchannel=this.channel(a)||this.cchannel};wsc.Client.prototype.log=function(a,b){var f=this.channel(a);if(!f){return}f.log(b)};wsc.Client.prototype.monitor=function(a){console.log(a)};wsc.Client.prototype.mute_user=function(a){return this.ui.mute_user(a)};wsc.Client.prototype.unmute_user=function(a){return this.ui.unmute_user(a)};wsc.Client.prototype.send=function(a){return this.conn.send(a)};wsc.Client.prototype.handshake=function(){this.send(wsc_packetstr(this.settings.client,this.settings.clientver,{agent:this.settings.agent})) };wsc.Client.prototype.login=function(){pkt="login "+this.settings.username+"\npk="+this.settings.pk+"\n";this.send(pkt)};wsc.Client.prototype.pong=function(){this.send(wsc_packetstr("pong"))};wsc.Client.prototype.join=function(a){this.send(wsc_packetstr("join",this.format_ns(a)))};wsc.Client.prototype.part=function(a){this.send(wsc_packetstr("part",this.format_ns(a)))};wsc.Client.prototype.say=function(a,b){var f=this;this.cascade("send.msg",function(g){f.send(wsc_packetstr("send",f.format_ns(g.ns),{},wsc_packetstr("msg","main",{},g.input)))},{input:b,ns:a})};wsc.Client.prototype.npmsg=function(a,b){var f=this;this.cascade("send.npmsg",function(g){f.send(wsc_packetstr("send",f.format_ns(g.ns),{},wsc_packetstr("npmsg","main",{},g.input)))},{input:b,ns:a})};wsc.Client.prototype.action=function(a,b){var f=this;this.cascade("send.action",function(g){f.send(wsc_packetstr("send",f.format_ns(g.ns),{},wsc_packetstr("action","main",{},g.input)))},{input:b,ns:a})};wsc.Client.prototype.promote=function(f,a,b){this.send(wsc_packetstr("send",this.format_ns(f),{},wsc_packetstr("promote",a,{},(!b?"":b)))) };wsc.Client.prototype.demote=function(f,a,b){this.send(wsc_packetstr("send",this.format_ns(f),{},wsc_packetstr("demote",a,{},(!b?"":b))))};wsc.Client.prototype.ban=function(b,a){this.send(wsc_packetstr("send",this.format_ns(b),{},wsc_packetstr("ban",a)))};wsc.Client.prototype.unban=function(b,a){this.send(wsc_packetstr("send",this.format_ns(b),{},wsc_packetstr("unban",a)))};wsc.Client.prototype.kick=function(b,a,f){var g=this;this.cascade("send.kick",function(h){g.send(wsc_packetstr("kick",g.format_ns(h.ns),{u:h.user},h.input||null))},{input:f||"",ns:b,user:a})};wsc.Client.prototype.kill=function(a,b){this.send(wsc_packetstr("kill","login:"+a,{},b||null))};wsc.Client.prototype.admin=function(a,b){this.send(wsc_packetstr("send",this.format_ns(a),{},wsc_packetstr("admin","",{},b)))};wsc.Client.prototype.property=function(a,b){this.send(wsc_packetstr("get",this.format_ns(a),{p:b}))};wsc.Client.prototype.set=function(a,f,b){var g=this;this.cascade("send.set",function(h){g.send(wsc_packetstr("set",g.format_ns(h.ns),{p:h.property},h.input)) -},{input:b,ns:a,property:f})};wsc.Client.prototype.whois=function(a){this.send(wsc_packetstr("get","login:"+a,{p:"info"}))};wsc.Client.prototype.disconnect=function(){this.send(wsc_packetstr("disconnect"))};var Chatterbox={};Chatterbox.VERSION="0.20.104";Chatterbox.STATE="beta";Chatterbox._gum=function(){};Chatterbox.UI=function(b,a,f,h,g){this.client=b;this.events=g||new EventEmitter();this.mozilla=h;this.umuted=[];this.viewing=true;this.settings={themes:["wsct_dAmn","wsct_dark"],theme:"wsct_dark",monitor:["~Monitor",true],username:"",domain:"website.com",clock:true,tabclose:true,developer:false,media:"/static/"};var j=this;this.sound={bank:{m:null},add:function(k,l){if(j.sound.hasOwnProperty(k)){return false}j.sound.bank[k]=l;l.load();j.sound[k]=function(){j.sound.play(j.sound.bank[k])};return true},play:function(k){k.pause();k.currentTime=0;k.play()},toggle:function(l){for(var k in j.sound.bank){if(!j.sound.bank.hasOwnProperty(k)){continue}j.sound.bank[k].muted=l}},mute:function(){j.sound.toggle(true) -},unmute:function(){j.sound.toggle(false)},};this.settings=a.extend(this.settings,f);a.append('
    ');this.mw=new wsc.Middleware();this.view=a.find(".wsc");this.mns=this.format_ns(this.settings.monitor[0]);this.lun=this.settings.username.toLowerCase();this.monitoro=null;this.swidth=(function(){if($.browser.msie){var m=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body"),l=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body");scrollbarWidth=m.width()-l.width();m.add(l).remove()}else{var k=$("
    ").css({width:100,height:100,overflow:"auto",position:"absolute",top:-1000,left:-1000}).prependTo("body").append("
    ").find("div").css({width:"100%",height:200});scrollbarWidth=100-k.width();k.parent().remove()}return scrollbarWidth})();if(window.mozRTCPeerConnection){Chatterbox._gum=function(l,m,k){return navigator.mozGetUserMedia(l,m,k) -}}if(window.webkitRTCPeerConnection){Chatterbox._gum=function(l,m,k){return navigator.webkitGetUserMedia(l,m,k)}}if(window.RTCPeerConnection&&!window.mozRTCPeerConnection){Chatterbox._gum=function(l,m,k){return navigator.getUserMedia(l,m,k)}}this.LIB="Chatterbox";this.VERSION=Chatterbox.VERSION;this.STATE=Chatterbox.STATE};wsc.defaults.UI=Chatterbox.UI;Chatterbox.UI.prototype.trigger=function(a,b){this.events.emit(a,b,this)};Chatterbox.UI.prototype.on=function(b,a){this.events.addListener(b,a)};Chatterbox.UI.prototype.middle=function(a,b){return this.mw.add(a,b)};Chatterbox.UI.prototype.cascade=function(a,f,b){this.mw.run(a,f,b)};Chatterbox.UI.prototype.remove_listeners=function(){this.events.removeListeners()};Chatterbox.UI.prototype.deform_ns=function(b){var a=b[0];if(a=="#"||a=="@"||a=="~"||a=="+"){return b}if(b.indexOf("chat:")==0){return"#"+b.slice(5)}if(b.indexOf("server:")==0){return"~"+b.slice(7)}if(b.indexOf("feed:")==0){return"#"+b.slice(5)}if(b.indexOf("login:")==0){return"@"+b.slice(6) -}if(b.indexOf("pchat:")==0){var f=b.split(":");f.shift();for(i in f){name=f[i];if(name.toLowerCase()!=this.lun){return"@"+name}}}return"#"+b};Chatterbox.UI.prototype.format_ns=function(a){var f=a.slice(1);switch(a[0]){case"@":var b=[f,this.lun];b.sort(caseInsensitiveSort);b.unshift("pchat");a=b.join(":");break;case"~":a="server:"+f;break;case"+":a="feed:"+f;break;case"#":a="chat:"+f;break;default:if(a.indexOf("chat:")==0||a.indexOf("pchat:")==0||a.indexOf("server:")==0||a.indexOf("feed:")==0){break}a="chat:"+a;break}return a};Chatterbox.UI.prototype.set_events=function(a){this.events=a||this.events};Chatterbox.UI.prototype.clock=function(a){if(a===undefined||a==this.settings.clock){return this.settings.clock}this.settings.clock=a;this.chatbook.retime();return this.settings.clock};Chatterbox.UI.prototype.get_user_media=function(b,f,a){Chatterbox._gum(b,f,a)};Chatterbox.UI.prototype.build=function(k,a,b){this.view.append(Chatterbox.render("ui",this.settings));this.control=new (k||Chatterbox.Control)(this); -this.nav=new (a||Chatterbox.Navigation)(this);this.chatbook=new (b||Chatterbox.Chatbook)(this);this.pager=new Chatterbox.Pager(this);this.monitoro=this.chatbook.create_channel(this.mns,this.settings.monitor[1],true);this.monitoro.show();this.control.focus();this.sound.bank.m=this.view.find("div.soundbank");this.sound.add("click",this.sound.bank.m.find("audio.click")[0]);var j=this.sound;var g=false;var f=this.nav.add_button({label:"",icon:"volume",href:"#mute",title:"Mute the client",handler:function(){if(!g){j.mute();f.removeClass("volume");f.addClass("volume_mute");f.prop("title","Unmute the client");g=true;return false}j.unmute();f.removeClass("volume_mute");f.addClass("volume");f.prop("title","Mute the client");g=false;return false}});var h=this;$(window).focus(function(){h.viewing=true});$(window).blur(function(){h.viewing=false});this.client.bind("pkt",function(m,l){h.packet(m,l)});this.client.middle("ns.remove",function(m,l){h.remove_channel(m.ns);l(m)});this.client.bind("ns.create",function(m,l){h.create_channel(m.chan.raw,m.chan.hidden) -});this.client.bind("ns.user.list",function(l){h.channel(l.ns).set_user_list(l.users)});this.client.middle("ns.user.privchg",function(m,l){h.channel(m.ns).privchg(m,l)});this.client.bind("ns.user.remove",function(m,l){h.channel(m.ns).remove_one_user(m.user)});this.client.bind("ns.user.registered",function(l){h.channel(l.ns).register_user(l.user)})};Chatterbox.UI.prototype.resize=function(){this.control.resize();this.view.height(this.view.parent().height());this.nav.resize();this.chatbook.resize(((this.view.parent().height()-this.nav.height())-this.control.height())-5)};Chatterbox.UI.prototype.loop=function(){this.chatbook.loop()};Chatterbox.UI.prototype.packet=function(b,a){var f=this;var g=a.protocol.log(b);if(g){if(this.settings.developer){console.log(">>>",b.sns,"|",g.text())}if(b.hasOwnProperty("s")&&b.s=="0"){this.chatbook.handle(b,a);return}b.html=g.html();this.cascade("log_message",function(j,h){f.chatbook.log_message(j.message,j.event)},{message:g,event:b})}this.chatbook.handle(b,a) -};Chatterbox.UI.prototype.create_channel=function(b,a){this.chatbook.create_channel(b,a)};Chatterbox.UI.prototype.remove_channel=function(a){this.chatbook.remove_channel(a)};Chatterbox.UI.prototype.toggle_channel=function(a){return this.chatbook.toggle_channel(a)};Chatterbox.UI.prototype.channel=function(a,b){return this.chatbook.channel(a,b)};Chatterbox.UI.prototype.channels=function(){return this.chatbook.channels()};Chatterbox.UI.prototype.channel_left=function(){this.chatbook.channel_left()};Chatterbox.UI.prototype.channel_right=function(){this.chatbook.channel_right()};Chatterbox.UI.prototype.monitor=function(b,a){this.monitoro.server_message(b,a)};Chatterbox.UI.prototype.server_message=function(b,a){this.chatbook.server_message(b,a)};Chatterbox.UI.prototype.log_item=function(a){this.chatbook.log_item(a)};Chatterbox.UI.prototype.log=function(a){this.chatbook.log(a)};Chatterbox.UI.prototype.mute_user=function(a){if(!a){return false}a=a.toLowerCase();if(this.umuted.indexOf(a)!=-1){return false -}this.umuted.push(a);this.chatbook.each(function(b,f){f.mute_user(a)});return true};Chatterbox.UI.prototype.unmute_user=function(a){if(!a){return false}a=a.toLowerCase();var b=this.umuted.indexOf(a);if(b==-1){return false}this.umuted.splice(b,1);this.chatbook.each(function(f,g){g.unmute_user(a)});return true};Chatterbox.UI.prototype.clear_user=function(a){this.chatbook.each(function(b,f){f.clear_user(a)})};Chatterbox.UI.prototype.theme=function(a){if(this.settings.theme==a){return this.settings.theme}if(this.settings.themes.indexOf(a)==-1){a="wsct_"+a;if(this.settings.themes.indexOf(a)==-1){return this.settings.theme}}this.view.removeClass(this.settings.theme).addClass(a);this.settings.theme=a;this.trigger("theme.set",{name:"theme.set",theme:a});return this.settings.theme};Chatterbox.UI.prototype.add_theme=function(a){if(this.settings.themes.indexOf(a)>-1){return}this.settings.themes.push(a)};Chatterbox.UI.prototype.developer=function(a){this.settings.developer=a;this.chatbook.developer() -};Chatterbox.BaseTab=function(g,b,f,a){this.manager=g;this.hidden=f;this.monitor=(a==undefined?false:a);this.built=false;this.raw=b;this.selector="t-"+(b||"chan").toLowerCase();this.namespace=b;this.visible=false;this.st=0;this.el={t:{o:null,l:null,c:null,},m:null,l:{p:null,w:null,},u:null,h:{title:null,topic:null}};this.mulw=0;this.d={u:[0,0],h:{title:[0,0],topic:[0,0]}};if(!g){return}this.raw=g.format_ns(b);this.selector=(this.raw.substr(0,2)=="pc"?"pc":"c")+"-"+g.deform_ns(b).slice(1).toLowerCase();this.namespace=g.deform_ns(b)};Chatterbox.BaseTab.prototype.build=function(b){if(!this.manager){return}if(this.built){return}var a=this.selector;var g=this.namespace;var f=this.raw;this.el.t.o=this.manager.nav.add_tab(a,g);this.el.t.l=this.el.t.o.find(".tab");this.el.t.c=this.el.t.o.find(".close");this.manager.chatbook.view.append(b||Chatterbox.render("basetab",{selector:a,ns:g}));this.el.m=this.window=this.manager.chatbook.view.find("#"+a+"-window");var h=this;this.el.t.l.click(function(){h.manager.toggle_channel(f); -return false});this.el.t.c.click(function(j){h.manager.trigger("tab.close.clicked",{ns:h.raw,chan:h,e:j});return false});if(this.hidden&&!this.manager.settings.developer){this.el.t.o.toggleClass("hidden")}this.built=true};Chatterbox.BaseTab.prototype.hide=function(){this.el.m.css({display:"none"});this.el.t.o.removeClass("active");this.visible=false};Chatterbox.BaseTab.prototype.show=function(){this.visible=true;this.el.m.css({display:"block"});this.el.t.o.addClass("active");this.el.t.o.removeClass("noise chatting tabbed fill");var a=this;setTimeout(function(){a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight());a.resize();a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight())},100)};Chatterbox.BaseTab.prototype.developer=function(){if(this.manager.settings.developer){this.el.t.o.removeClass("hidden");return}if(this.hidden){this.el.t.o.addClass("hidden")}};Chatterbox.BaseTab.prototype.remove=function(){this.el.t.o.remove();this.el.m.remove()};Chatterbox.BaseTab.prototype.resize=function(b,a){this.el.m.css({height:a||this.manager.chatbook.height(),width:(b||this.manager.chatbook.width())-10}) -};Chatterbox.BaseTab.prototype.loop=function(){};Chatterbox.Channel=function(g,b,f,a){Chatterbox.BaseTab.call(this,g,b,f,a);this.resized=function(){};this.ulbuf=0};Chatterbox.Channel.prototype=new Chatterbox.BaseTab;Chatterbox.Channel.prototype.constructor=Chatterbox.Channel;Chatterbox.Channel.prototype.build=function(){if(!this.manager){return}if(this.built){return}var a=this.selector;var f=this.namespace;var b=this.raw;Chatterbox.BaseTab.prototype.build.call(this,Chatterbox.render("channel",{selector:a,ns:f}));this.el.l.p=this.el.m.find("#"+a+"-log");this.el.l.w=this.el.l.p.find("ul.logwrap");this.el.u=this.el.m.find("#"+a+"-users");this.mulw=parseInt(this.el.u.css("max-width").slice(0,-2));var g=this;var h=false;this.el.l.w.click(function(){if(!h){return}g.manager.control.focus()});this.el.l.w.mousedown(function(){h=true});this.el.l.w.mousemove(function(){h=false});this.el.t.l.click(function(){g.manager.toggle_channel(b);return false});this.setup_header("title");this.setup_header("topic"); -if(this.namespace[0]=="@"){this.build_user_list({100:"Room Members"},[100])}this.built=true};Chatterbox.Channel.prototype.setup_header=function(a){var f=this;var b={};b.m=this.el.m.find("header."+a+" div");b.e=this.el.m.find("header."+a+" a[href=#edit]");b.t=this.el.m.find("header."+a+" textarea");b.s=this.el.m.find("header."+a+" a[href=#save]");b.c=this.el.m.find("header."+a+" a[href=#cancel]");this.el.h[a]=b.m;b.m.parent().mouseover(function(h){if(!b.editing){b.e.css("display","block");return}b.s.css("display","block");b.c.css("display","block")});b.m.parent().mouseout(function(h){if(!b.editing){b.e.css("display","none");return}b.s.css("display","none");b.c.css("display","none")});b.e.click(function(h){b.t.text(f.manager.client.channel(f.namespace).info[a].content);b.t.css({display:"block",width:f.el.h[a].innerWidth()-10,});f.el.h[a].css("display","none");b.e.css("display","none");b.editing=true;f.resize();return false});var g=function(){var h=b.t.val();b.t.text("");b.t.css("display","none"); -f.el.h[a].css("display","block");b.s.css("display","none");b.c.css("display","none");b.editing=false;f.resize();return h};b.s.click(function(h){var j=g();f.manager.trigger(a+".save",{ns:f.raw,value:j});b.t.text("");return false});b.c.click(function(h){g();return false})};Chatterbox.Channel.prototype.scroll=function(){this.pad();var a=this.el.l.w.prop("scrollWidth")-this.el.l.w.innerWidth();var b=this.el.l.w.prop("scrollHeight")-this.el.l.w.innerHeight();if(a>0){b+=a}if(b<0||(b-this.el.l.w.scrollTop())>100){return}this.el.l.w.scrollTop(b)};Chatterbox.Channel.prototype.pad=function(){this.el.l.w.css({"padding-top":0,height:"auto"});var b=this.el.l.w.innerHeight();var a=this.el.l.p.innerHeight()-this.el.h.topic.parent().outerHeight();var f=a-b;if(f>0){this.el.l.w.css({"padding-top":f})}else{this.el.l.w.css({"padding-top":0,height:a})}this.el.l.w.scrollTop(this.st)};Chatterbox.Channel.prototype.resize=function(j,a){Chatterbox.BaseTab.prototype.resize.call(this,j,a);var k={title:{m:this.el.m.find("header div.title"),e:this.el.m.find("header.title a[href=#edit]")},topic:{m:this.el.m.find("header div.topic"),e:this.el.m.find("header.topic a[href=#edit]")}}; -this.el.l.w.css({"padding-top":0});a=a||this.manager.chatbook.height();j=j||this.manager.chatbook.width();var f=a;var b=this.el.m.width();this.el.u.width(1);this.d.u[0]=this.el.u[0].scrollWidth+this.manager.swidth+5;if(this.d.u[0]>this.mulw){this.d.u[0]=this.mulw}this.el.u.width(this.d.u[0]);b=b-this.d.u[0];f=f-k.title.m.parent().outerHeight();this.el.l.p.css({height:f-3,width:(b-10)-this.ulbuf});this.scroll();this.d.u[1]=this.el.l.p.innerHeight();this.el.u.css({height:this.d.u[1]});for(var h in k){if(!k.hasOwnProperty(h)){continue}if(k[h].m.html().length==0){continue}var g=(k[h].m.outerHeight(true)-5)*(-1);k[h].e.css("top",g)}this.resized()};Chatterbox.Channel.prototype.loop=function(){var a=this.el.l.p.find(".logmsg");if(a.length<200){return}a.slice(0,a.length-200).remove();this.resize()};Chatterbox.Channel.prototype.log=function(b){var a=this;this.manager.cascade("log",function(f){a.log_item({html:Chatterbox.render("logmsg",{message:f.message})})},{ns:this.raw,sns:this.namespace,message:b}) -};Chatterbox.Channel.prototype.log_item=function(f){var a=new Date();var b="";if(this.manager.settings.clock){b=formatTime("{HH}:{mm}:{ss}",a)}else{b=formatTime("{hh}:{mm}:{ss} {mr}",a)}var g=this;this.manager.cascade("log_item",function(h){if(g.visible){g.st=g.el.l.w.scrollTop()}g.el.l.w.append(Chatterbox.render("logitem",h));g.manager.trigger("log_item.after",{item:g.el.l.w.find("li").last(),chan:g});if(g.visible){g.st+=g.el.l.w.find("li.logmsg").last().height();g.el.l.w.scrollTop(g.st)}g.scroll();g.noise()},{ns:this.namespace,ts:b,ms:a.getTime(),message:f.html,user:(f.user||"system").toLowerCase()})};Chatterbox.Channel.prototype.retime=function(){var a="";var b=this.el.l.w;if(this.manager.settings.clock){a="{HH}:{mm}:{ss}"}else{a="{hh}:{mm}:{ss} {mr}"}b.find("span.ts").each(function(f,g){el=b.find(g);time=new Date(parseInt(el.prop("id")));el.text(formatTime(a,time))})};Chatterbox.Channel.prototype.server_message=function(f,b){var a=this;this.manager.cascade("server_message",function(g){a.log_item({html:Chatterbox.render("servermsg",{message:g.message,info:g.info})}) -},{ns:this.namespace,message:f,info:b})};Chatterbox.Channel.prototype.clear=function(){this.el.l.p.find("li.logmsg").remove();this.el.l.p.find("li.loginfo").remove();this.el.l.w.height(0);this.resize()};Chatterbox.Channel.prototype.log_info=function(h,g){var k={ns:this.namespace,ref:h,content:g};this.manager.trigger("log_info.before",k);delete k.ns;var a=this.el.l.w.append(Chatterbox.render("loginfobox",k));this.scroll();var j=this;var f=this.el.l.w.find("li."+k.ref);f.find("a.close").click(function(b){j.el.l.w.find(this).parent().remove();j.resize();return false});this.scroll();return f};Chatterbox.Channel.prototype.log_whois=function(m){var h={avatar:'avatar',username:""+m.symbol+m.username+"",info:[],conns:[],raw:m,};for(var n in m.connections){var l=m.connections[n];var p=[];if(l.online){var a=(new Date-(l.online*1000));p.push(["online",DateStamp(a/1000)+formatTime(" [{HH}:{mm}:{ss}]",new Date(a))])}if(l.idle){p.push(["idle",timeLengthString(l.idle)]) -}if(l.agent){p.push(["agent",l.agent])}if(l.debug){p.push(["debug",l.debug])}p.push(["chatrooms",l.channels.join(" ")]);h.conns.push(p)}this.manager.trigger("log_whois.before",h);var b="";for(var n in h.conns){var k=h.conns[n];var r='

    connection '+((parseInt(n)+1).toString())+":

    ";r+="
      ";for(var q in k){r+="
    • "+k[q][0]+": "+k[q][1]+"
    • "}r+="
    ";b+=r+"
    "}var j="";for(var n in h.info){j+="
  • "+h.info[n]+"
  • "}var o=this.log_info("whois-"+m.username,Chatterbox.render("whoiswrap",{avatar:h.avatar,info:Chatterbox.render("whoisinfo",{username:h.username,info:j,connections:b})}));var g=o.find("div.avatar");var f=o.find("div.info");f.width(o.find(".whoiswrap").width()-100);g.height(o.height()-10);this.scroll()};Chatterbox.Channel.prototype.log_pc=function(g,h){contents="";for(var f in h){if(!h.hasOwnProperty(f)){continue}var b=h[f];var a="";if(b[2].length==0){a=""+(g?"default privileges":"no members")+""}else{a=b[2] -}contents+=String.format("
  • {0} {1}:
    • {2}
  • ",[b[1],b[0],a])}var j={title:"Privilege class "+(g?"permissions":"members"),info:"
      "+contents+"
    "};this.log_info("pc-"+(g?"permissions":"members"),Chatterbox.render("pcinfo",j))};Chatterbox.Channel.prototype.set_header=function(a,g,j,f){a=a.toLowerCase();var b=this.el.m.find("header."+a+" a[href=#edit]");if(this.el.h[a].html()!=""){if(g.html().length!=0){this.server_message(a+" set by "+j)}}this.el.h[a].html(g.html());var h=this;setTimeout(function(){if(g.text().length>0){h.el.h[a].css({display:"block"});var k=(h.el.h[a].outerHeight(true)-5)*(-1);b.css("top",k)}else{h.el.h[a].css({display:"none"})}h.resize()},100)};Chatterbox.Channel.prototype.get_header=function(a){return this.el.h[a.toLowerCase()]};Chatterbox.Channel.prototype.build_user_list=function(g,a){var j=this.el.u;var f="";var h=null;j.html("");for(var b in a){var f=g[a[b]];j.append('

    '+f+"

      "); -h=j.find(".pc#"+f);h.css("display","none")}};Chatterbox.Channel.prototype.reveal_user_list=function(){var h=this.el.u;var f=0;var b=0;var a=null;h.find("div.pc").each(function(j,k){a=h.find(this);b=a.find("ul li").length;f+=b;a.css("display",(b==0?"none":"block"))});h.css("display",(f==0?"none":"block"));var g=this;setTimeout(function(){g.resize()},100)};Chatterbox.Channel.prototype.set_user_list=function(g){if(Object.size(g)==0){return}var f=this.el.u;var a=null;for(var b in g){a=g[b];this.set_user(a,true)}this.reveal_user_list()};Chatterbox.Channel.prototype.set_user=function(h,f){var k=this.el.u.find("div.pc#"+replaceAll(h.pc," ","-"));var a=k.find("ul");var b=h.conn==1?"":"["+h.conn+"]";var j='
    • '+h.symbol+""+h.name+""+b+"
    • ";if(a.find("a#"+h.name).length==1){return}if(a.find("li").length==0){a.append(j)}else{var l=h.name.toLowerCase();var n=null;var g=false;a.find("li a").each(function(){if(g){return -}n=a.find(this);if(l"}j.window.append(Chatterbox.render("userinfo",{username:b.name,avatar:b.avatar,link:b.link,info:k}));g=j.window.find(".userinfo#"+b.name);j.window.find("div.userinfo:not('#"+b.name+"')").remove();var m=h.offset();g.css({top:(m.top-h.height())+10,left:(m.left-(g.width()))-6});g.find(".info").height(g.height());g.hover(function(){g.data("hover",1)},function(n){g.data("hover",0);j.unhover_user(g,n)});g.data("hover",0)};var f=function(k){h.data("hover",0);j.unhover_user(g,k)};h.off("mouseenter",a);h.off("mouseleave",f);h.on("mouseenter",a);h.on("mouseleave",f)};Chatterbox.Channel.prototype.unhover_user=function(g,f){var h=g.offset();var b=g.outerHeight(true)+h.top;var k=g.outerWidth(true)+h.left;var a=f.pageX;var j=f.pageY;if(a>h.left&&ah.top&&jh.left&&j>h.top&&j<(h.top+15)){return -}g.remove()};Chatterbox.Channel.prototype.mute_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).css({display:"none"});this.scroll()};Chatterbox.Channel.prototype.unmute_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).css({display:"list-item"});this.scroll()};Chatterbox.Channel.prototype.clear_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).remove();this.scroll()};Chatterbox.Channel.prototype.pkt_join=function(b,a){if(b.e!="ok"){return}this.set_header("title",(new wsc.MessageString("")),"","");this.set_header("topic",(new wsc.MessageString("")),"","")};Chatterbox.Channel.prototype.pkt_recv_msg=function(b,a){var f=this;this.manager.cascade("chan.recv_msg",function(j,g){var h=f.manager.client.settings.username.toLowerCase();if(h==j.user.toLowerCase()){return}var l=j.message.toLowerCase();var k=l.indexOf(h)!=-1;if(!k&&j.sns[0]!="@"){return}if(k){f.highlight()}else{f.highlight(false)}f.manager.trigger("tabbed",j) -},b)};Chatterbox.Channel.prototype.pkt_recv_action=Chatterbox.Channel.prototype.pkt_recv_msg;Chatterbox.Channel.prototype.pkt_property=function(b,a){var g=b.pkt.arg.p;var f=a.channel(this.namespace);switch(g){case"title":case"topic":this.set_header(g,b.value||(new wsc.MessageString("")),b.by,b.ts);break;case"privclasses":this.build_user_list(f.info.pc,f.info.pc_order.slice(0));break;case"members":break;default:break}};Chatterbox.Chatbook=function(a){this.manager=a;this.view=this.manager.view.find("div.chatbook");this.chan={};this.trail=[];this.current=null;this.manager.on("tab.close.clicked",function(b,f){f.chatbook.remove_channel(b.ns)})};Chatterbox.Chatbook.prototype.height=function(){return this.view.height()};Chatterbox.Chatbook.prototype.width=function(){return this.view.width()};Chatterbox.Chatbook.prototype.resize=function(b){b=b||600;var f=this.view.innerWidth();for(var a in this.chan){if(!this.chan.hasOwnProperty(a)){continue}var g=this.chan[a];g.resize(f,b)}};Chatterbox.Chatbook.prototype.loop=function(){for(select in this.chan){this.chan[select].loop() -}};Chatterbox.Chatbook.prototype.channel=function(a,b){a=this.manager.format_ns(a).toLowerCase();if(!this.chan[a]&&b){this.chan[a]=b}return this.chan[a]};Chatterbox.Chatbook.prototype.channels=function(){chans=-1;for(ns in this.chan){if(this.chan[ns].hidden){continue}chans++}return chans};Chatterbox.Chatbook.prototype.create_channel=function(b,f,a){var g=this.channel(b,this.channel_object(b,f,a));g.build();if(this.trail.indexOf(g.namespace)==-1){this.trail.push(g.namespace)}if(!g.visible){this.toggle_channel(b)}this.manager.resize();return g};Chatterbox.Chatbook.prototype.channel_object=function(a,b){return new Chatterbox.Channel(this.manager,a,b)};Chatterbox.Chatbook.prototype.toggle_channel=function(a){var f=this.channel(a);var b=f;if(!f){return}if(f.hidden){if(this.current&&this.current==f){return}if(!this.manager.settings.developer){f.hide();return}}if(this.current){if(this.current==f){return}this.current.hide();b=this.current}else{if(this.manager.monitoro!==null){this.manager.monitoro.hide() -}}f.show();this.manager.control.focus();this.current=f;this.manager.resize();this.manager.control.cache_input(b,f);this.manager.trigger("channel.selected",{ns:f.raw,chan:f,prev:b});this.manager.client.select_ns(f.raw)};Chatterbox.Chatbook.prototype.remove_channel=function(a){var b=this.channel(a);if(!b){return}if(this.channels()==0&&!b.hidden){return}b.remove();delete this.chan[b.raw.toLowerCase()];if(this.current==b){this.channel_left()}var f=this.trail.indexOf(b.namespace);this.trail.splice(f,1)};Chatterbox.Chatbook.prototype.channel_left=function(){var b=this.current.namespace;var a=this.trail.indexOf(b);if(a<0){return}var g=null;while(true){try{g=this.channel(this.trail[--a])}catch(f){a=this.trail.length-1;g=this.channel(this.trail[a])}if(!g.hidden){break}if(this.manager.settings.developer){break}}this.toggle_channel(g.namespace)};Chatterbox.Chatbook.prototype.channel_right=function(){var b=this.current.namespace;var a=this.trail.indexOf(b);if(a==-1){return}var g=null;while(true){try{g=this.channel(this.trail[++a]) -}catch(f){a=0;g=this.channel(this.trail[0])}if(!g.hidden){break}if(this.manager.settings.developer){break}}this.toggle_channel(g.namespace)};Chatterbox.Chatbook.prototype.each=function(f){var b=null;for(var a in this.chan){if(!this.chan.hasOwnProperty(a)){continue}b=this.chan[a];if(f(b.namespace,b)===false){break}}};Chatterbox.Chatbook.prototype.server_message=function(b,a){for(ns in this.chan){this.chan[ns].server_message(b,a)}};Chatterbox.Chatbook.prototype.log_item=function(a){for(ns in this.chan){this.chan[ns].log_item(a)}};Chatterbox.Chatbook.prototype.log=function(a){for(ns in this.chan){this.chan[ns].log(a)}};Chatterbox.Chatbook.prototype.log_message=function(f,b){try{if(!f.global){if(!f.monitor){this.channel(b.ns).log_item(b)}else{this.manager.monitoro.log_item(b)}}else{this.log_item(b)}}catch(a){try{this.ui.monitoro.server_message("Failed to log for",b.sns,b.html)}catch(a){console.log(">> Failed to log message for",b.sns,"::");console.log(">>",b.html)}}};Chatterbox.Chatbook.prototype.retime=function(){for(ns in this.chan){this.chan[ns].retime() -}};Chatterbox.Chatbook.prototype.developer=function(){this.each(function(a,b){b.developer()})};Chatterbox.Chatbook.prototype.handle=function(g,b){var h=this.manager;var j=this.channel(g.ns);if(!j){return}var a="pkt_"+g.name;try{j[a](g,b)}catch(f){}};Chatterbox.Control=function(b){this.manager=b;this.manager.view.append(Chatterbox.template.control);this.view=this.manager.view.find("div.chatcontrol");this.ml=false;this.history={};this.tab={hit:false,cache:"",matched:[],index:-1,type:0,prefix:["","/",""],};this.el={form:this.view.find("form.msg"),i:{s:this.view.find("form.msg input.msg"),m:this.view.find("form.msg textarea.msg"),c:null,t:this.view.find("ul.buttons a[href~=#multiline].button")},brow:{m:this.view.find("div.brow"),b:this.view.find("div.brow ul.buttons"),s:this.view.find("div.brow ul.states")}};this.el.i.c=this.el.i.s;var a=this;this.el.i.t.click(function(f){a.multiline(!a.multiline());return false});this.el.i.s.keydown(function(f){return a.keypress(f)});this.el.i.m.keydown(function(f){return a.keypress(f) -});this.el.form.submit(function(f){return a.submit(f)});this.add_button({label:"b",icon:false,href:"#bold",title:"Bold text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"i",icon:false,href:"#italic",title:"Italic text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"u",icon:false,href:"#underline",title:"Underline text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"sup",icon:false,href:"#sup",title:"Superscript",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"sub",icon:false,href:"#sub",title:"Subscript",handler:function(){a.surroundtext(a.el.i.c[0],"","")}})};Chatterbox.Control.prototype.surroundtext=function(k,j,b){var h=k.scrollTop;var a=k.value,f=k.selectionStart,g=k.selectionEnd;var l=k.value.substring(f,g);k.value=a.substring(0,f)+j+l+b+a.substring(g);k.selectionStart=f+j.length; -k.selectionEnd=f+j.length+l.length;k.scrollTop=h;k.focus()};Chatterbox.Control.prototype.focus=function(){this.el.i.c.focus()};Chatterbox.Control.prototype.resize=function(){w=this.manager.view.width();this.view.css({width:"100%"});this.el.form.css({width:this.manager.view.width()-20});this.el.i.s.css({width:this.manager.view.width()-100});this.el.i.m.css({width:this.manager.view.width()-90})};Chatterbox.Control.prototype.height=function(){var a=this.view.outerHeight();return a};Chatterbox.Control.prototype.multiline=function(a){if(a==undefined||this.ml==a){return this.ml}this.ml=a;var b=(this.ml?"s":"m");a=(this.ml?"m":"s");this.el.i[b].css("display","none");this.el.i[a].css("display","inline-block");this.el.i.c=this.el.i[a];this.manager.resize();return this.ml};Chatterbox.Control.prototype.add_button=function(a){a=Object.extend({label:"New",icon:false,href:"#button",title:"Button.",handler:function(){}},(a||{}));if(a.icon!==false){a.icon=" iconic "+a.icon}else{a.icon=" text"}this.el.brow.b.append(Chatterbox.render("brow_button",a)); -var b=this.el.brow.b.find("a[href="+a.href+"].button");b.click(function(f){a.handler();return false});return b};Chatterbox.Control.prototype.add_state=function(a){a=Object.extend({ref:"state",label:"some state"},(a||{}));var b=this.el.brow.s.find("li#"+a.ref);if(b.length==0){this.el.brow.s.append(Chatterbox.render("brow_state",a));return this.el.brow.s.find("li#"+a.ref)}b.html(a.label);return b};Chatterbox.Control.prototype.rem_state=function(a){return this.el.brow.s.find("li#"+a).remove()};Chatterbox.Control.prototype.chomp=function(){var f=this.el.i.c.val();var b=f.lastIndexOf(" ");if(b==-1){this.el.i.c.val("");return f}var a=f.slice(b+1);this.el.i.c.val(f.slice(0,b));if(a.length==0){return this.chomp()}return a};Chatterbox.Control.prototype.unchomp=function(a){var b=this.el.i.c.val();if(!b){this.el.i.c.val(a)}else{this.el.i.c.val(b+" "+a)}};Chatterbox.Control.prototype.get_text=function(a){if(a==undefined){return this.el.i.c.val()}this.el.i.c.val(a||"");return this.el.i.c.val()};Chatterbox.Control.prototype.set_text=function(a){this.el.i.c.val(a||"") -};Chatterbox.Control.prototype.cache_input=function(b,f){var a=this.get_history(b.namespace);if(a.index>-1){return}a.tmp=this.get_text();this.set_text(this.get_history(f.namespace).tmp)};Chatterbox.Control.prototype.get_history=function(a){if(!a){if(!this.manager.chatbook.current){a="~monitor"}}a=a||this.manager.chatbook.current.namespace;if(!this.history[a]){this.history[a]={index:-1,list:[],tmp:""}}return this.history[a]};Chatterbox.Control.prototype.append_history=function(b){if(!b){return}var a=this.get_history();a.list.unshift(b);a.index=-1;if(a.list.length>100){a.list.pop()}};Chatterbox.Control.prototype.scroll_history=function(a){var f=this.get_history();var b=this.get_text();if(f.index==-1){if(b){f.tmp=b}else{f.list[f.index]=b}}if(a){if(f.list.length>0&&f.index<(f.list.length-1)){f.index++}}else{if(f.index>-1){f.index--}}this.set_text(f.list[f.index]||f.tmp)};Chatterbox.Control.prototype.tab_item=function(b){if(!this.tab.hit){this.start_tab(b)}this.chomp();this.tab.index++;if(this.tab.index>=this.tab.matched.length){this.tab.index=-1 -}if(this.tab.index==-1){this.unchomp(this.tab.prefix[this.tab.type]+this.tab.cache);return}var a=this.get_text()==""?(this.tab.type==0?": ":" "):"";this.unchomp(this.tab.prefix[this.tab.type]+this.tab.matched[this.tab.index]+a)};Chatterbox.Control.prototype.start_tab=function(f){this.tab.hit=true;this.tab.index=-1;this.tab.matched=[];this.tab.type=0;var j=this.chomp();this.unchomp(j);if(j[0]=="/"||j[0]=="#"||j[0]=="@"){this.tab.type=j[0]=="/"?1:2;if(j[0]=="/"){j=j.slice(1)}}else{this.tab.type=0}this.tab.cache=j;j=j.toLowerCase();this.tab.matched=[];if(this.tab.type==0){var k=this.manager.client.channel(this.manager.chatbook.current.namespace);for(var a in k.info.members){if(a.toLowerCase().indexOf(j)==0){this.tab.matched.push(a)}}}else{if(this.tab.type==1){var h="";for(var b in this.manager.client.cmds){h=this.manager.client.cmds[b];if(h.indexOf(j)==0){this.tab.matched.push(h)}}}else{if(this.tab.type==2){var g=this;this.manager.client.each_channel(function(l,m){if(m.namespace.toLowerCase().indexOf(j)==0){g.tab.matched.push(m.namespace) -}})}}}};Chatterbox.Control.prototype.end_tab=function(a){this.tab.hit=false;this.tab.matched=[];this.tab.cache="";this.tab.index=-1};Chatterbox.Control.prototype.submit=function(a){var b=this.get_text();this.append_history(b);this.set_text("");this.handle(a,b);return false};Chatterbox.Control.prototype.keypress=function(f){var b=f.which||f.keyCode;var g=this.tab.hit;var a=false;switch(b){case 13:if(!this.multiline()){this.submit(f)}else{if(f.shiftKey){this.submit(f)}else{a=true}}break;case 38:if(!this.multiline()){this.scroll_history(true);break}a=true;break;case 40:if(!this.multiline()){this.scroll_history(false);break}a=true;break;case 9:if(f.shiftKey){this.manager.channel_right()}else{this.tab_item(f);g=false}break;case 219:if(f.ctrlKey){this.manager.channel_left()}else{a=true}break;case 221:if(f.ctrlKey){this.manager.channel_right()}else{a=true}break;default:a=true;break}if(g){this.end_tab(f)}return a};Chatterbox.Control.prototype.handle=function(b,h){if(h==""){return}if(!this.manager.chatbook.current){return -}var l=false;if(h[0]!="/"){l=true}h=(b.shiftKey?"/npmsg ":(h[0]=="/"?"":"/say "))+h;h=h.slice(1);var m=h.split(" ");var f=m.shift().toLowerCase();var k=this.manager.chatbook.current.namespace;var j=k;if(!l&&m[0]){var g=m[0][0];if((g=="#"||g=="@")&&m[0].length>1){j=this.manager.format_ns(m.shift())}}var n=m.join(" ");var a=this.manager.client.trigger("cmd."+f,{name:"cmd",cmd:f,args:n,target:j,ns:k});if(a==0){this.manager.pager.notice({ref:"cmd-fail",heading:"Command failed",content:'"'+f+'" is not a command.'},false,5000)}};Chatterbox.Navigation=function(a){this.manager=a;this.showclose=this.manager.settings.tabclose;this.settings={};this.settings.open=false;this.el={n:this.manager.view.find("nav.tabs"),tw:this.manager.view.find("nav.tabs div.tabwrap"),t:this.manager.view.find("nav.tabs #chattabs"),b:this.manager.view.find("nav.tabs #tabnav"),l:this.manager.view.find("nav.tabs #tabnav .arrow_left"),r:this.manager.view.find("nav.tabs #tabnav .arrow_right"),s:this.manager.view.find("nav.tabs #tabnav #settings-button"),}; -if(!this.showclose){if(!this.el.t.hasClass("hc")){this.el.t.addClass("hc")}}var b=this;this.el.s.click(function(h){if(b.settings.open){return false}var f={e:h,settings:new Chatterbox.Settings.Config(b.manager)};b.configure_page(f);b.manager.trigger("settings.open",f);b.manager.trigger("settings.open.ran",f);var g=f.settings.page("About");g.item("text",{ref:"about-chatterbox",wclass:"centered faint",text:'Using Chatterbox version '+Chatterbox.VERSION+" "+Chatterbox.STATE+' by ~photofroggy.'});b.settings.window=new Chatterbox.Settings(b.manager,f.settings);b.settings.window.build();b.settings.open=true;return false});this.el.l.click(function(){b.manager.channel_left();return false});this.el.r.click(function(){b.manager.channel_right();return false})};Chatterbox.Navigation.prototype.configure_page=function(b){var g=this.manager;var f=b.settings.page("Main");var h={};h.theme=replaceAll(g.settings.theme,"wsct_",""); -h.clock=g.clock();h.tc=g.nav.closer();var a=[];for(i in g.settings.themes){name=replaceAll(g.settings.themes[i],"wsct_","");a.push({value:name,title:name,selected:h.theme==name})}f.item("Form",{ref:"ui",title:"UI",hint:"Timestamp
      Choose between a 24 hour clock and a 12 hour clock.\n\nTheme
      Change the look of the client.\n\nClose Buttons
      Turn tab close buttons on/off.",fields:[["Dropdown",{ref:"theme",label:"Theme",items:a}],["Dropdown",{ref:"clock",label:"Timestamp Format",items:[{value:"24",title:"24 hour",selected:h.clock},{value:"12",title:"12 hour",selected:!h.clock}]}],["Checkbox",{ref:"tabclose",label:"Close Buttons",items:[{value:"yes",title:"On",selected:h.tc}]}],],event:{change:function(j){g.clock(j.data.clock=="24");g.theme(j.data.theme);g.nav.closer(j.data.tabclose.indexOf("yes")>-1)},save:function(j){h.clock=g.clock();h.theme=replaceAll(g.theme(),"wsct_","");h.tc=g.nav.closer();g.trigger("settings.save.ui",{clock:h.clock,tabclose:h.tc,theme:"wsct_"+h.theme}) -},close:function(j){g.clock(h.clock);g.theme(h.theme);g.nav.closer(h.tc)}}})};Chatterbox.Navigation.prototype.height=function(){var a=this.el.n.outerHeight();return a};Chatterbox.Navigation.prototype.add_button=function(a){a=Object.extend({label:"New",icon:false,href:"#button",title:"Button.",handler:function(){}},(a||{}));if(a.icon!==false){a.icon=" iconic "+a.icon}else{a.icon=" text"}this.el.b.prepend(Chatterbox.render("nav_button",a));var b=this.el.b.find("a[href="+a.href+"].button");b.click(function(f){a.handler();return false});this.resize();return b};Chatterbox.Navigation.prototype.add_tab=function(a,b){this.el.t.append(Chatterbox.render("tab",{selector:a,ns:b}));return this.el.t.find("#"+a+"-tab")};Chatterbox.Navigation.prototype.resize=function(){this.el.tw.width(this.el.n.width()-this.el.b.outerWidth()-20);if(this.settings.open){this.settings.window.resize()}};Chatterbox.Navigation.prototype.closer=function(a){if(a==undefined||a==this.showclose){return this.showclose}this.showclose=a; -if(this.showclose){if(!this.el.t.hasClass("hc")){return}this.el.t.removeClass("hc");return}if(this.el.t.hasClass("hc")){return}this.el.t.addClass("hc")};Chatterbox.Pager=function(a){this.manager=a;this.lifespan=20000;this.halflife=5000;this.el={m:null,click:null};this.sound={click:function(){},};this.notices=[];this.build()};Chatterbox.Pager.prototype.build=function(){this.el.m=this.manager.view.find("div.pager")};Chatterbox.Pager.prototype.notice=function(g,m,l,f){var j={frame:null,close:null,foot:null,b:{},options:Object.extend({ref:"notice",icon:"",heading:"Some notice",content:"Notice content goes here."},(g||{})),onclose:function(){},ondestroy:function(){}};j.options.ref+="-"+(new Date()).valueOf();j.options.content=j.options.content.split("\n").join("

      ");this.notices.push(j);this.el.m.append(Chatterbox.render("pager.notice",j.options));j.frame=this.el.m.find("#"+j.options.ref).last();j.close=j.frame.find("a.close_notice");j.foot=j.frame.find("footer.buttons");var h={};for(var a in j.options.buttons){if(!j.options.buttons.hasOwnProperty(a)){continue -}h=j.options.buttons[a];j.foot.append(Chatterbox.render("pager.button",h));j.b[a]=j.foot.find("a#"+h.ref);j.b[a].click(h.click)}var k=this;j.close.click(function(){j.onclose();k.remove_notice(j);return false});if(!m){if(!l){l=k.lifespan}setTimeout(function(){k.remove_notice(j,true)},l)}if(f!==true){this.manager.sound.click()}return j};Chatterbox.Pager.prototype.remove_notice=function(a,f){var b=this;if(this.notices.indexOf(a)==-1){return false}a.frame.fadeTo((f?this.halflife:300),0).slideUp(function(){a.frame.remove();b.notices.splice(b.notices.indexOf(a),1);a.ondestroy()});if(f){a.frame.mouseenter(function(){if(b.notices.indexOf(a)==-1){return}a.frame.stop(true);a.frame.slideDown(function(){a.frame.fadeTo(300,1);a.frame.mouseleave(function(){setTimeout(function(){b.remove_notice(a,true)},b.lifespan)})})})}};Chatterbox.Pager.prototype.find_notice=function(a){for(var b in this.notices){if(this.notices[b].options.ref==a){return this.notices[b]}}return null};Chatterbox.Popup=function(b,a){this.manager=b; -this.pview=(this.manager||{view:{find:function(){}}}).view;this.window=null;this.closeb=null;this.options=Object.extend({ref:"popup",title:"Popup",close:true,content:""},(a||{}))};Chatterbox.Popup.prototype.build=function(){var b=this.options;if(this.options.close){b.title+=''}this.pview.append(Chatterbox.render("popup",b));this.window=this.pview.find(".floater."+b.ref);if(this.options.close){this.closeb=this.window.find("a.close");var a=this;this.closeb.click(function(f){a.close();return false})}};Chatterbox.Popup.prototype.close=function(){this.window.remove()};Chatterbox.Popup.Prompt=function(b,a){a=a||{};a=Object.extend({position:[0,0],ref:"prompt",title:"Input",close:false,label:"","default":"","submit-button":"Submit",event:{submit:function(){},cancel:function(){}}},a);Chatterbox.Popup.call(this,b,a);this.data=this.options["default"]};Chatterbox.Popup.Prompt.prototype=new Chatterbox.Popup();Chatterbox.Popup.Prompt.prototype.constructor=Chatterbox.Popup.Prompt; -Chatterbox.Popup.Prompt.prototype.build=function(){this.options.content=Chatterbox.template.prompt.main;Chatterbox.Popup.prototype.build.call(this);this.window.css({left:this.options.position[0],top:this.options.position[1]});var a=this;this.window.find(".button.close").click(function(){a.options.event.cancel(a);a.close();return false});this.window.find(".button.submit").click(function(){a.data=a.window.find("input").val();a.options.event.submit(a);a.close();return false});this.window.find("form").submit(function(){a.data=a.window.find("input").val();a.options.event.submit(a);a.close();return false})};Chatterbox.Popup.ItemPicker=function(b,a){a=a||{};a=Object.extend({position:[100,60],ref:"item-picker",title:"Items",event:{select:function(f){}}},a);Chatterbox.Popup.call(this,b,a);this.pview=this.pview.find(".chatbook");this.data=this.options["default"];this.pages=[];this.cpage=null};Chatterbox.Popup.ItemPicker.prototype=new Chatterbox.Popup();Chatterbox.Popup.ItemPicker.prototype.constructor=Chatterbox.Popup.ItemPicker; -Chatterbox.Popup.ItemPicker.prototype.build=function(){this.options.content=Chatterbox.render("ip.main",{});Chatterbox.Popup.prototype.build.call(this);this.window.css({right:this.options.position[0],bottom:this.options.position[1]});this.closeb.removeClass("medium");this.pbook=this.window.find("section.pages");this.tabs=this.window.find("section.tabs ul");this.buttons=this.window.find("section.buttons");var f=this;var b=null;for(var a in this.pages){if(!this.pages.hasOwnProperty(a)){continue}b=this.pages[a];b.build();if(a==0){this.select_page(b)}}};Chatterbox.Popup.ItemPicker.prototype.refresh=function(){if(this.cpage==null){return}else{this.cpage.refresh()}};Chatterbox.Popup.ItemPicker.prototype.page=function(b,a){b=b.toLowerCase();for(var f in this.pages){if(!this.pages.hasOwnProperty(f)){continue}if(this.pages[f].name.toLowerCase()==b){return this.pages[f]}}return(a||null)};Chatterbox.Popup.ItemPicker.prototype.add_page=function(a,b){this.pages.push(new (b||Chatterbox.Popup.ItemPicker.Page)(this,a)) -};Chatterbox.Popup.ItemPicker.prototype.add_button=function(a){a=Object.extend({href:"#button",title:"Button",label:"Button"},(a||{}));this.buttons.append(Chatterbox.render("ip.button",a));return this.buttons.find("a[href="+a.href+"]")};Chatterbox.Popup.ItemPicker.prototype.select=function(a){this.options.event.select(a)};Chatterbox.Popup.ItemPicker.prototype.select_page=function(a){if(!a){return}if(this.cpage!=null){this.cpage.hide()}this.cpage=a||null;if(this.cpage!=null){this.cpage.show()}};Chatterbox.Popup.ItemPicker.Page=function(b,a){this.picker=b;this.options=Object.extend({ref:"page",href:"#page",label:"Page",title:"page",items:[],content:"No items on this page.",},(a||{}));this.name=this.options.label;this.nrefresh=true};Chatterbox.Popup.ItemPicker.Page.prototype.build=function(){this.picker.pbook.append(Chatterbox.render("ip.page",this.options));this.picker.tabs.append(Chatterbox.render("ip.tab",this.options));this.view=this.picker.pbook.find("div.page#"+this.options.ref); -this.items=this.view.find("ul");this.tab=this.picker.tabs.find("#"+this.options.ref);this.refresh();var a=this;this.tab.find("a").click(function(){a.picker.select_page(a);return false})};Chatterbox.Popup.ItemPicker.Page.prototype.refresh=function(){var a=this.build_list();if(a.length==0){this.options.content="No items on this page."}else{this.options.content="

        "+a+"
      "}this.view.html(this.options.content);this.items=this.view.find("ul");this.hook_events();this.nrefresh=false};Chatterbox.Popup.ItemPicker.Page.prototype.hook_events=function(){var a=this;this.items.find("li").each(function(b,g){var h=a.view.find(g);var f=h.find(".value").html();h.click(function(){a.picker.select(f)})})};Chatterbox.Popup.ItemPicker.Page.prototype.build_list=function(){var f=[];var g=null;var j,h,b;for(var a in this.options.items){if(!this.options.items.hasOwnProperty(a)){continue}g=this.options.items[a];h=g.value||g;j=g.title||h;b=g.html||false;f.push('
    • '+(b?h:''+h+"")+"
    • ") -}return f.join("")};Chatterbox.Popup.ItemPicker.Page.prototype.show=function(){this.tab.addClass("selected");this.view.css("display","block");this.refresh()};Chatterbox.Popup.ItemPicker.Page.prototype.hide=function(){this.tab.removeClass("selected");this.view.css("display","none")};Chatterbox.Protocol=function(){this.messages={chatserver:{keys:["version"],template:'** Connected to llama {version} *',global:true},dAmnServer:{keys:["version"],template:'** Connected to dAmnServer {version} *',global:true},login:{keys:["username","e","data"],template:'** Login as {username}: "{e}" *',global:true},join:{keys:["ns","e"],template:'** Join {ns}: "{e}" *',monitor:true},part:{keys:["ns","e","r"],template:'** Part {ns}: "{e}" * {r}',monitor:true},property:{keys:["ns","p","by","ts","value"],template:'** Got {p} for {ns} *',monitor:true},recv_msg:{keys:["user","message"],template:'<{user}>{message}'},recv_action:{keys:["s","user","message"],template:'* {user}{message}'},recv_join:{keys:["user","s","info"],template:'** {user} has joined *',},recv_part:{keys:["user","r"],template:'** {user} has left * {r}'},recv_privchg:{keys:["user","s","by","pc"],template:'** {user} has been made a member of {pc} by {by} *'},recv_kicked:{keys:["user","s","by","r"],template:'** {user} has been kicked by {by} * {r}'},recv_admin_create:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been created by {user} * {privs}'},recv_admin_update:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been updated by {user} * {privs}'},recv_admin_rename:{keys:["p","user","prev","pc"],template:'** Privilege class {prev} has been renamed to {pc} by {user} *'},recv_admin_move:{keys:["p","user","prev","pc","affected"],template:'** All members of {prev} have been moved to {pc} by {user} * {affected} affected user(s)'},recv_admin_remove:{keys:["p","user","pc","affected"],template:'** Privilege class {pc} has been removed by {user} * {affected} affected user(s)'},recv_admin_show:null,recv_admin_showverbose:null,recv_admin_privclass:{keys:["p","e","command"],template:'** Admin command "{command}" failed * {e}'},kicked:{keys:["ns","user","r"],template:'** You have been kicked by {user} * {r}'},ping:null,disconnect:{keys:["e"],template:'** You have been disconnected * {e}',global:true},send:{keys:["ns","e"],template:'** Send error: {e}'},kick:{keys:["ns","user","e"],template:'** Could not kick {user} * {e}'},get:{keys:["ns","p","e"],template:'** Could not get {p} info for {ns} * {e}'},set:{keys:["ns","p","e"],template:'** Could not set {p} * {e}'},kill:{keys:["ns","e"],template:'** Kill error * {e}'},unknown:{keys:["ns","packet"],template:'** Received unknown packet in {ns} * {packet}',monitor:true}} -};Chatterbox.Protocol.prototype.extend_messages=function(b){for(var a in b){this.messages[a]=b[a]}};Chatterbox.Protocol.prototype.log=function(b){var a=this.messages[b.name];return new Chatterbox.Protocol.LogMessage(b,a)};Chatterbox.Protocol.LogMessage=function(b,a){this.event=b;this.template=a.template||"";this.keys=a.keys||[];this.monitor=a.monitor||false;this.global=a.global||false;this._html=false;this._text=false;this._ansi=false};Chatterbox.Protocol.LogMessage.prototype.text=function(){if(this._text===false){this._text=this.render(0)}return this._text};Chatterbox.Protocol.LogMessage.prototype.html=function(){if(this._html===false){this._html=this.render(1)}return this._html};Chatterbox.Protocol.LogMessage.prototype.ansi=function(){if(this._ansi===false){this._ansi=this.render(2)}return this._ansi};Chatterbox.Protocol.LogMessage.prototype.render=function(f){if(f===undefined){f=0}var b=this.template;var g="";for(var a in this.keys){if(!this.keys.hasOwnProperty(a)){continue}key=this.keys[a]; +},{input:b,ns:a,property:f})};wsc.Client.prototype.whois=function(a){this.send(wsc_packetstr("get","login:"+a,{p:"info"}))};wsc.Client.prototype.disconnect=function(){this.send(wsc_packetstr("disconnect"))};var Chatterbox={};Chatterbox.VERSION="0.20.104";Chatterbox.STATE="beta";Chatterbox._gum=function(){};(function(a){a.fn.chatterbox=function(h,b,f){var g=a(window).data("chatterbox");if(h=="init"||g===undefined){if(g==undefined){g=new Chatterbox.UI(a(this),b,f,(a.browser.mozilla||false));a(window).resize(g.resize)}a(window).data("chatterbox",g)}if(h!="init"&&h!=undefined){h="jq_"+h;if(h in g){g[h](a(this),f)}}return g}})(jQuery);Chatterbox.UI=function(b,a,f,h,g){this.client=a;this.events=g||new EventEmitter();this.mozilla=h;this.umuted=[];this.viewing=true;this.settings={themes:["wsct_dAmn","wsct_dark"],theme:"wsct_dark",monitor:["~Monitor",true],username:"",domain:"website.com",clock:true,tabclose:true,developer:false,media:"/static/"};var j=this;this.sound={bank:{m:null},add:function(k,l){if(j.sound.hasOwnProperty(k)){return false +}j.sound.bank[k]=l;l.load();j.sound[k]=function(){j.sound.play(j.sound.bank[k])};return true},play:function(k){k.pause();k.currentTime=0;k.play()},toggle:function(l){for(var k in j.sound.bank){if(!j.sound.bank.hasOwnProperty(k)){continue}j.sound.bank[k].muted=l}},mute:function(){j.sound.toggle(true)},unmute:function(){j.sound.toggle(false)},};this.settings=b.extend(this.settings,f);b.append('
      ');this.mw=new wsc.Middleware();this.view=b.find(".wsc");this.mns=this.format_ns(this.settings.monitor[0]);this.lun=this.settings.username.toLowerCase();this.monitoro=null;this.swidth=(function(){if($.browser.msie){var m=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body"),l=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body");scrollbarWidth=m.width()-l.width();m.add(l).remove()}else{var k=$("
      ").css({width:100,height:100,overflow:"auto",position:"absolute",top:-1000,left:-1000}).prependTo("body").append("
      ").find("div").css({width:"100%",height:200}); +scrollbarWidth=100-k.width();k.parent().remove()}return scrollbarWidth})();if(window.mozRTCPeerConnection){Chatterbox._gum=function(l,m,k){return navigator.mozGetUserMedia(l,m,k)}}if(window.webkitRTCPeerConnection){Chatterbox._gum=function(l,m,k){return navigator.webkitGetUserMedia(l,m,k)}}if(window.RTCPeerConnection&&!window.mozRTCPeerConnection){Chatterbox._gum=function(l,m,k){return navigator.getUserMedia(l,m,k)}}this.LIB="Chatterbox";this.VERSION=Chatterbox.VERSION;this.STATE=Chatterbox.STATE};wsc.defaults.UI=Chatterbox.UI;Chatterbox.UI.prototype.trigger=function(a,b){this.events.emit(a,b,this)};Chatterbox.UI.prototype.on=function(b,a){this.events.addListener(b,a)};Chatterbox.UI.prototype.middle=function(a,b){return this.mw.add(a,b)};Chatterbox.UI.prototype.cascade=function(a,f,b){this.mw.run(a,f,b)};Chatterbox.UI.prototype.remove_listeners=function(){this.events.removeListeners()};Chatterbox.UI.prototype.deform_ns=function(b){var a=b[0];if(a=="#"||a=="@"||a=="~"||a=="+"){return b}if(b.indexOf("chat:")==0){return"#"+b.slice(5) +}if(b.indexOf("server:")==0){return"~"+b.slice(7)}if(b.indexOf("feed:")==0){return"#"+b.slice(5)}if(b.indexOf("login:")==0){return"@"+b.slice(6)}if(b.indexOf("pchat:")==0){var f=b.split(":");f.shift();for(i in f){name=f[i];if(name.toLowerCase()!=this.lun){return"@"+name}}}return"#"+b};Chatterbox.UI.prototype.format_ns=function(a){var f=a.slice(1);switch(a[0]){case"@":var b=[f,this.lun];b.sort(caseInsensitiveSort);b.unshift("pchat");a=b.join(":");break;case"~":a="server:"+f;break;case"+":a="feed:"+f;break;case"#":a="chat:"+f;break;default:if(a.indexOf("chat:")==0||a.indexOf("pchat:")==0||a.indexOf("server:")==0||a.indexOf("feed:")==0){break}a="chat:"+a;break}return a};Chatterbox.UI.prototype.set_events=function(a){this.events=a||this.events};Chatterbox.UI.prototype.clock=function(a){if(a===undefined||a==this.settings.clock){return this.settings.clock}this.settings.clock=a;this.chatbook.retime();return this.settings.clock};Chatterbox.UI.prototype.get_user_media=function(b,f,a){Chatterbox._gum(b,f,a) +};Chatterbox.UI.prototype.build=function(k,a,b){this.view.append(Chatterbox.render("ui",this.settings));this.control=new (k||Chatterbox.Control)(this);this.nav=new (a||Chatterbox.Navigation)(this);this.chatbook=new (b||Chatterbox.Chatbook)(this);this.pager=new Chatterbox.Pager(this);this.monitoro=this.chatbook.create_channel(this.mns,this.settings.monitor[1],true);this.monitoro.show();this.control.focus();this.sound.bank.m=this.view.find("div.soundbank");this.sound.add("click",this.sound.bank.m.find("audio.click")[0]);var j=this.sound;var g=false;var f=this.nav.add_button({label:"",icon:"volume",href:"#mute",title:"Mute the client",handler:function(){if(!g){j.mute();f.removeClass("volume");f.addClass("volume_mute");f.prop("title","Unmute the client");g=true;return false}j.unmute();f.removeClass("volume_mute");f.addClass("volume");f.prop("title","Mute the client");g=false;return false}});var h=this;$(window).focus(function(){h.viewing=true});$(window).blur(function(){h.viewing=false});this.client.bind("pkt",function(m,l){h.packet(m,l) +});this.client.middle("ns.remove",function(m,l){h.remove_channel(m.ns);l(m)});this.client.bind("ns.create",function(m,l){h.create_channel(m.chan.raw,m.chan.hidden)});this.client.bind("ns.user.list",function(l){h.channel(l.ns).set_user_list(l.users)});this.client.middle("ns.user.privchg",function(m,l){h.channel(m.ns).privchg(m,l)});this.client.bind("ns.user.remove",function(m,l){h.channel(m.ns).remove_one_user(m.user)});this.client.bind("ns.user.registered",function(l){h.channel(l.ns).register_user(l.user)})};Chatterbox.UI.prototype.resize=function(){this.control.resize();this.view.height(this.view.parent().height());this.nav.resize();this.chatbook.resize(((this.view.parent().height()-this.nav.height())-this.control.height())-5)};Chatterbox.UI.prototype.loop=function(){this.chatbook.loop()};Chatterbox.UI.prototype.packet=function(b,a){var f=this;var g=a.protocol.log(b);if(g){if(this.settings.developer){console.log(">>>",b.sns,"|",g.text())}if(b.hasOwnProperty("s")&&b.s=="0"){this.chatbook.handle(b,a); +return}b.html=g.html();this.cascade("log_message",function(j,h){f.chatbook.log_message(j.message,j.event)},{message:g,event:b})}this.chatbook.handle(b,a)};Chatterbox.UI.prototype.create_channel=function(b,a){this.chatbook.create_channel(b,a)};Chatterbox.UI.prototype.remove_channel=function(a){this.chatbook.remove_channel(a)};Chatterbox.UI.prototype.toggle_channel=function(a){return this.chatbook.toggle_channel(a)};Chatterbox.UI.prototype.channel=function(a,b){return this.chatbook.channel(a,b)};Chatterbox.UI.prototype.channels=function(){return this.chatbook.channels()};Chatterbox.UI.prototype.channel_left=function(){this.chatbook.channel_left()};Chatterbox.UI.prototype.channel_right=function(){this.chatbook.channel_right()};Chatterbox.UI.prototype.monitor=function(b,a){this.monitoro.server_message(b,a)};Chatterbox.UI.prototype.server_message=function(b,a){this.chatbook.server_message(b,a)};Chatterbox.UI.prototype.log_item=function(a){this.chatbook.log_item(a)};Chatterbox.UI.prototype.log=function(a){this.chatbook.log(a) +};Chatterbox.UI.prototype.mute_user=function(a){if(!a){return false}a=a.toLowerCase();if(this.umuted.indexOf(a)!=-1){return false}this.umuted.push(a);this.chatbook.each(function(b,f){f.mute_user(a)});return true};Chatterbox.UI.prototype.unmute_user=function(a){if(!a){return false}a=a.toLowerCase();var b=this.umuted.indexOf(a);if(b==-1){return false}this.umuted.splice(b,1);this.chatbook.each(function(f,g){g.unmute_user(a)});return true};Chatterbox.UI.prototype.clear_user=function(a){this.chatbook.each(function(b,f){f.clear_user(a)})};Chatterbox.UI.prototype.theme=function(a){if(this.settings.theme==a){return this.settings.theme}if(this.settings.themes.indexOf(a)==-1){a="wsct_"+a;if(this.settings.themes.indexOf(a)==-1){return this.settings.theme}}this.view.removeClass(this.settings.theme).addClass(a);this.settings.theme=a;this.trigger("theme.set",{name:"theme.set",theme:a});return this.settings.theme};Chatterbox.UI.prototype.add_theme=function(a){if(this.settings.themes.indexOf(a)>-1){return +}this.settings.themes.push(a)};Chatterbox.UI.prototype.developer=function(a){this.settings.developer=a;this.chatbook.developer()};Chatterbox.BaseTab=function(g,b,f,a){this.manager=g;this.hidden=f;this.monitor=(a==undefined?false:a);this.built=false;this.raw=b;this.selector="t-"+(b||"chan").toLowerCase();this.namespace=b;this.visible=false;this.st=0;this.el={t:{o:null,l:null,c:null,},m:null,l:{p:null,w:null,},u:null,h:{title:null,topic:null}};this.mulw=0;this.d={u:[0,0],h:{title:[0,0],topic:[0,0]}};if(!g){return}this.raw=g.format_ns(b);this.selector=(this.raw.substr(0,2)=="pc"?"pc":"c")+"-"+g.deform_ns(b).slice(1).toLowerCase();this.namespace=g.deform_ns(b)};Chatterbox.BaseTab.prototype.build=function(b){if(!this.manager){return}if(this.built){return}var a=this.selector;var g=this.namespace;var f=this.raw;this.el.t.o=this.manager.nav.add_tab(a,g);this.el.t.l=this.el.t.o.find(".tab");this.el.t.c=this.el.t.o.find(".close");this.manager.chatbook.view.append(b||Chatterbox.render("basetab",{selector:a,ns:g})); +this.el.m=this.window=this.manager.chatbook.view.find("#"+a+"-window");var h=this;this.el.t.l.click(function(){h.manager.toggle_channel(f);return false});this.el.t.c.click(function(j){h.manager.trigger("tab.close.clicked",{ns:h.raw,chan:h,e:j});return false});if(this.hidden&&!this.manager.settings.developer){this.el.t.o.toggleClass("hidden")}this.built=true};Chatterbox.BaseTab.prototype.hide=function(){this.el.m.css({display:"none"});this.el.t.o.removeClass("active");this.visible=false};Chatterbox.BaseTab.prototype.show=function(){this.visible=true;this.el.m.css({display:"block"});this.el.t.o.addClass("active");this.el.t.o.removeClass("noise chatting tabbed fill");var a=this;setTimeout(function(){a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight());a.resize();a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight())},100)};Chatterbox.BaseTab.prototype.developer=function(){if(this.manager.settings.developer){this.el.t.o.removeClass("hidden");return}if(this.hidden){this.el.t.o.addClass("hidden") +}};Chatterbox.BaseTab.prototype.remove=function(){this.el.t.o.remove();this.el.m.remove()};Chatterbox.BaseTab.prototype.resize=function(b,a){this.el.m.css({height:a||this.manager.chatbook.height(),width:(b||this.manager.chatbook.width())-10})};Chatterbox.BaseTab.prototype.loop=function(){};Chatterbox.Channel=function(g,b,f,a){Chatterbox.BaseTab.call(this,g,b,f,a);this.resized=function(){};this.ulbuf=0};Chatterbox.Channel.prototype=new Chatterbox.BaseTab;Chatterbox.Channel.prototype.constructor=Chatterbox.Channel;Chatterbox.Channel.prototype.build=function(){if(!this.manager){return}if(this.built){return}var a=this.selector;var f=this.namespace;var b=this.raw;Chatterbox.BaseTab.prototype.build.call(this,Chatterbox.render("channel",{selector:a,ns:f}));this.el.l.p=this.el.m.find("#"+a+"-log");this.el.l.w=this.el.l.p.find("ul.logwrap");this.el.u=this.el.m.find("#"+a+"-users");this.mulw=parseInt(this.el.u.css("max-width").slice(0,-2));var g=this;var h=false;this.el.l.w.click(function(){if(!h){return +}g.manager.control.focus()});this.el.l.w.mousedown(function(){h=true});this.el.l.w.mousemove(function(){h=false});this.el.t.l.click(function(){g.manager.toggle_channel(b);return false});this.setup_header("title");this.setup_header("topic");if(this.namespace[0]=="@"){this.build_user_list({100:"Room Members"},[100])}this.built=true};Chatterbox.Channel.prototype.setup_header=function(a){var f=this;var b={};b.m=this.el.m.find("header."+a+" div");b.e=this.el.m.find("header."+a+" a[href=#edit]");b.t=this.el.m.find("header."+a+" textarea");b.s=this.el.m.find("header."+a+" a[href=#save]");b.c=this.el.m.find("header."+a+" a[href=#cancel]");this.el.h[a]=b.m;b.m.parent().mouseover(function(h){if(!b.editing){b.e.css("display","block");return}b.s.css("display","block");b.c.css("display","block")});b.m.parent().mouseout(function(h){if(!b.editing){b.e.css("display","none");return}b.s.css("display","none");b.c.css("display","none")});b.e.click(function(h){b.t.text(f.manager.client.channel(f.namespace).info[a].content); +b.t.css({display:"block",width:f.el.h[a].innerWidth()-10,});f.el.h[a].css("display","none");b.e.css("display","none");b.editing=true;f.resize();return false});var g=function(){var h=b.t.val();b.t.text("");b.t.css("display","none");f.el.h[a].css("display","block");b.s.css("display","none");b.c.css("display","none");b.editing=false;f.resize();return h};b.s.click(function(h){var j=g();f.manager.trigger(a+".save",{ns:f.raw,value:j});b.t.text("");return false});b.c.click(function(h){g();return false})};Chatterbox.Channel.prototype.scroll=function(){this.pad();var a=this.el.l.w.prop("scrollWidth")-this.el.l.w.innerWidth();var b=this.el.l.w.prop("scrollHeight")-this.el.l.w.innerHeight();if(a>0){b+=a}if(b<0||(b-this.el.l.w.scrollTop())>100){return}this.el.l.w.scrollTop(b)};Chatterbox.Channel.prototype.pad=function(){this.el.l.w.css({"padding-top":0,height:"auto"});var b=this.el.l.w.innerHeight();var a=this.el.l.p.innerHeight()-this.el.h.topic.parent().outerHeight();var f=a-b;if(f>0){this.el.l.w.css({"padding-top":f}) +}else{this.el.l.w.css({"padding-top":0,height:a})}this.el.l.w.scrollTop(this.st)};Chatterbox.Channel.prototype.resize=function(j,a){Chatterbox.BaseTab.prototype.resize.call(this,j,a);var k={title:{m:this.el.m.find("header div.title"),e:this.el.m.find("header.title a[href=#edit]")},topic:{m:this.el.m.find("header div.topic"),e:this.el.m.find("header.topic a[href=#edit]")}};this.el.l.w.css({"padding-top":0});a=a||this.manager.chatbook.height();j=j||this.manager.chatbook.width();var f=a;var b=this.el.m.width();this.el.u.width(1);this.d.u[0]=this.el.u[0].scrollWidth+this.manager.swidth+5;if(this.d.u[0]>this.mulw){this.d.u[0]=this.mulw}this.el.u.width(this.d.u[0]);b=b-this.d.u[0];f=f-k.title.m.parent().outerHeight();this.el.l.p.css({height:f-3,width:(b-10)-this.ulbuf});this.scroll();this.d.u[1]=this.el.l.p.innerHeight();this.el.u.css({height:this.d.u[1]});for(var h in k){if(!k.hasOwnProperty(h)){continue}if(k[h].m.html().length==0){continue}var g=(k[h].m.outerHeight(true)-5)*(-1);k[h].e.css("top",g) +}this.resized()};Chatterbox.Channel.prototype.loop=function(){var a=this.el.l.p.find(".logmsg");if(a.length<200){return}a.slice(0,a.length-200).remove();this.resize()};Chatterbox.Channel.prototype.log=function(b){var a=this;this.manager.cascade("log",function(f){a.log_item({html:Chatterbox.render("logmsg",{message:f.message})})},{ns:this.raw,sns:this.namespace,message:b})};Chatterbox.Channel.prototype.log_item=function(f){var a=new Date();var b="";if(this.manager.settings.clock){b=formatTime("{HH}:{mm}:{ss}",a)}else{b=formatTime("{hh}:{mm}:{ss} {mr}",a)}var g=this;this.manager.cascade("log_item",function(h){if(g.visible){g.st=g.el.l.w.scrollTop()}g.el.l.w.append(Chatterbox.render("logitem",h));g.manager.trigger("log_item.after",{item:g.el.l.w.find("li").last(),chan:g});if(g.visible){g.st+=g.el.l.w.find("li.logmsg").last().height();g.el.l.w.scrollTop(g.st)}g.scroll();g.noise()},{ns:this.namespace,ts:b,ms:a.getTime(),message:f.html,user:(f.user||"system").toLowerCase()})};Chatterbox.Channel.prototype.retime=function(){var a=""; +var b=this.el.l.w;if(this.manager.settings.clock){a="{HH}:{mm}:{ss}"}else{a="{hh}:{mm}:{ss} {mr}"}b.find("span.ts").each(function(f,g){el=b.find(g);time=new Date(parseInt(el.prop("id")));el.text(formatTime(a,time))})};Chatterbox.Channel.prototype.server_message=function(f,b){var a=this;this.manager.cascade("server_message",function(g){a.log_item({html:Chatterbox.render("servermsg",{message:g.message,info:g.info})})},{ns:this.namespace,message:f,info:b})};Chatterbox.Channel.prototype.clear=function(){this.el.l.p.find("li.logmsg").remove();this.el.l.p.find("li.loginfo").remove();this.el.l.w.height(0);this.resize()};Chatterbox.Channel.prototype.log_info=function(h,g){var k={ns:this.namespace,ref:h,content:g};this.manager.trigger("log_info.before",k);delete k.ns;var a=this.el.l.w.append(Chatterbox.render("loginfobox",k));this.scroll();var j=this;var f=this.el.l.w.find("li."+k.ref);f.find("a.close").click(function(b){j.el.l.w.find(this).parent().remove();j.resize();return false});this.scroll(); +return f};Chatterbox.Channel.prototype.log_whois=function(m){var h={avatar:'avatar',username:""+m.symbol+m.username+"",info:[],conns:[],raw:m,};for(var n in m.connections){var l=m.connections[n];var p=[];if(l.online){var a=(new Date-(l.online*1000));p.push(["online",DateStamp(a/1000)+formatTime(" [{HH}:{mm}:{ss}]",new Date(a))])}if(l.idle){p.push(["idle",timeLengthString(l.idle)])}if(l.agent){p.push(["agent",l.agent])}if(l.debug){p.push(["debug",l.debug])}p.push(["chatrooms",l.channels.join(" ")]);h.conns.push(p)}this.manager.trigger("log_whois.before",h);var b="";for(var n in h.conns){var k=h.conns[n];var r='

      connection '+((parseInt(n)+1).toString())+":

      ";r+="
        ";for(var q in k){r+="
      • "+k[q][0]+": "+k[q][1]+"
      • "}r+="
      ";b+=r+"
      "}var j="";for(var n in h.info){j+="
    • "+h.info[n]+"
    • "}var o=this.log_info("whois-"+m.username,Chatterbox.render("whoiswrap",{avatar:h.avatar,info:Chatterbox.render("whoisinfo",{username:h.username,info:j,connections:b})})); +var g=o.find("div.avatar");var f=o.find("div.info");f.width(o.find(".whoiswrap").width()-100);g.height(o.height()-10);this.scroll()};Chatterbox.Channel.prototype.log_pc=function(g,h){contents="";for(var f in h){if(!h.hasOwnProperty(f)){continue}var b=h[f];var a="";if(b[2].length==0){a=""+(g?"default privileges":"no members")+""}else{a=b[2]}contents+=String.format("
    • {0} {1}:
      • {2}
    • ",[b[1],b[0],a])}var j={title:"Privilege class "+(g?"permissions":"members"),info:"
        "+contents+"
      "};this.log_info("pc-"+(g?"permissions":"members"),Chatterbox.render("pcinfo",j))};Chatterbox.Channel.prototype.set_header=function(a,g,j,f){a=a.toLowerCase();var b=this.el.m.find("header."+a+" a[href=#edit]");if(this.el.h[a].html()!=""){if(g.html().length!=0){this.server_message(a+" set by "+j)}}this.el.h[a].html(g.html());var h=this;setTimeout(function(){if(g.text().length>0){h.el.h[a].css({display:"block"});var k=(h.el.h[a].outerHeight(true)-5)*(-1); +b.css("top",k)}else{h.el.h[a].css({display:"none"})}h.resize()},100)};Chatterbox.Channel.prototype.get_header=function(a){return this.el.h[a.toLowerCase()]};Chatterbox.Channel.prototype.build_user_list=function(g,a){var j=this.el.u;var f="";var h=null;j.html("");for(var b in a){var f=g[a[b]];j.append('

      '+f+"

        ");h=j.find(".pc#"+f);h.css("display","none")}};Chatterbox.Channel.prototype.reveal_user_list=function(){var h=this.el.u;var f=0;var b=0;var a=null;h.find("div.pc").each(function(j,k){a=h.find(this);b=a.find("ul li").length;f+=b;a.css("display",(b==0?"none":"block"))});h.css("display",(f==0?"none":"block"));var g=this;setTimeout(function(){g.resize()},100)};Chatterbox.Channel.prototype.set_user_list=function(g){if(Object.size(g)==0){return}var f=this.el.u;var a=null;for(var b in g){a=g[b];this.set_user(a,true)}this.reveal_user_list()};Chatterbox.Channel.prototype.set_user=function(h,f){var k=this.el.u.find("div.pc#"+replaceAll(h.pc," ","-")); +var a=k.find("ul");var b=h.conn==1?"":"["+h.conn+"]";var j='
      • '+h.symbol+""+h.name+""+b+"
      • ";if(a.find("a#"+h.name).length==1){return}if(a.find("li").length==0){a.append(j)}else{var l=h.name.toLowerCase();var n=null;var g=false;a.find("li a").each(function(){if(g){return}n=a.find(this);if(l"}j.window.append(Chatterbox.render("userinfo",{username:b.name,avatar:b.avatar,link:b.link,info:k}));g=j.window.find(".userinfo#"+b.name);j.window.find("div.userinfo:not('#"+b.name+"')").remove();var m=h.offset();g.css({top:(m.top-h.height())+10,left:(m.left-(g.width()))-6});g.find(".info").height(g.height());g.hover(function(){g.data("hover",1)},function(n){g.data("hover",0);j.unhover_user(g,n)});g.data("hover",0)};var f=function(k){h.data("hover",0); +j.unhover_user(g,k)};h.off("mouseenter",a);h.off("mouseleave",f);h.on("mouseenter",a);h.on("mouseleave",f)};Chatterbox.Channel.prototype.unhover_user=function(g,f){var h=g.offset();var b=g.outerHeight(true)+h.top;var k=g.outerWidth(true)+h.left;var a=f.pageX;var j=f.pageY;if(a>h.left&&ah.top&&jh.left&&j>h.top&&j<(h.top+15)){return}g.remove()};Chatterbox.Channel.prototype.mute_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).css({display:"none"});this.scroll()};Chatterbox.Channel.prototype.unmute_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).css({display:"list-item"});this.scroll()};Chatterbox.Channel.prototype.clear_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).remove();this.scroll()};Chatterbox.Channel.prototype.pkt_join=function(b,a){if(b.e!="ok"){return}this.set_header("title",(new wsc.MessageString("")),"","");this.set_header("topic",(new wsc.MessageString("")),"","") +};Chatterbox.Channel.prototype.pkt_recv_msg=function(b,a){var f=this;this.manager.cascade("chan.recv_msg",function(j,g){var h=f.manager.client.settings.username.toLowerCase();if(h==j.user.toLowerCase()){return}var l=j.message.toLowerCase();var k=l.indexOf(h)!=-1;if(!k&&j.sns[0]!="@"){return}if(k){f.highlight()}else{f.highlight(false)}f.manager.trigger("tabbed",j)},b)};Chatterbox.Channel.prototype.pkt_recv_action=Chatterbox.Channel.prototype.pkt_recv_msg;Chatterbox.Channel.prototype.pkt_property=function(b,a){var g=b.pkt.arg.p;var f=a.channel(this.namespace);switch(g){case"title":case"topic":this.set_header(g,b.value||(new wsc.MessageString("")),b.by,b.ts);break;case"privclasses":this.build_user_list(f.info.pc,f.info.pc_order.slice(0));break;case"members":break;default:break}};Chatterbox.Chatbook=function(a){this.manager=a;this.view=this.manager.view.find("div.chatbook");this.chan={};this.trail=[];this.current=null;this.manager.on("tab.close.clicked",function(b,f){f.chatbook.remove_channel(b.ns) +})};Chatterbox.Chatbook.prototype.height=function(){return this.view.height()};Chatterbox.Chatbook.prototype.width=function(){return this.view.width()};Chatterbox.Chatbook.prototype.resize=function(b){b=b||600;var f=this.view.innerWidth();for(var a in this.chan){if(!this.chan.hasOwnProperty(a)){continue}var g=this.chan[a];g.resize(f,b)}};Chatterbox.Chatbook.prototype.loop=function(){for(select in this.chan){this.chan[select].loop()}};Chatterbox.Chatbook.prototype.channel=function(a,b){a=this.manager.format_ns(a).toLowerCase();if(!this.chan[a]&&b){this.chan[a]=b}return this.chan[a]};Chatterbox.Chatbook.prototype.channels=function(){chans=-1;for(ns in this.chan){if(this.chan[ns].hidden){continue}chans++}return chans};Chatterbox.Chatbook.prototype.create_channel=function(b,f,a){var g=this.channel(b,this.channel_object(b,f,a));g.build();if(this.trail.indexOf(g.namespace)==-1){this.trail.push(g.namespace)}if(!g.visible){this.toggle_channel(b)}this.manager.resize();return g};Chatterbox.Chatbook.prototype.channel_object=function(a,b){return new Chatterbox.Channel(this.manager,a,b) +};Chatterbox.Chatbook.prototype.toggle_channel=function(a){var f=this.channel(a);var b=f;if(!f){return}if(f.hidden){if(this.current&&this.current==f){return}if(!this.manager.settings.developer){f.hide();return}}if(this.current){if(this.current==f){return}this.current.hide();b=this.current}else{if(this.manager.monitoro!==null){this.manager.monitoro.hide()}}f.show();this.manager.control.focus();this.current=f;this.manager.resize();this.manager.control.cache_input(b,f);this.manager.trigger("channel.selected",{ns:f.raw,chan:f,prev:b});this.manager.client.select_ns(f.raw)};Chatterbox.Chatbook.prototype.remove_channel=function(a){var b=this.channel(a);if(!b){return}if(this.channels()==0&&!b.hidden){return}b.remove();delete this.chan[b.raw.toLowerCase()];if(this.current==b){this.channel_left()}var f=this.trail.indexOf(b.namespace);this.trail.splice(f,1)};Chatterbox.Chatbook.prototype.channel_left=function(){var b=this.current.namespace;var a=this.trail.indexOf(b);if(a<0){return}var g=null;while(true){try{g=this.channel(this.trail[--a]) +}catch(f){a=this.trail.length-1;g=this.channel(this.trail[a])}if(!g.hidden){break}if(this.manager.settings.developer){break}}this.toggle_channel(g.namespace)};Chatterbox.Chatbook.prototype.channel_right=function(){var b=this.current.namespace;var a=this.trail.indexOf(b);if(a==-1){return}var g=null;while(true){try{g=this.channel(this.trail[++a])}catch(f){a=0;g=this.channel(this.trail[0])}if(!g.hidden){break}if(this.manager.settings.developer){break}}this.toggle_channel(g.namespace)};Chatterbox.Chatbook.prototype.each=function(f){var b=null;for(var a in this.chan){if(!this.chan.hasOwnProperty(a)){continue}b=this.chan[a];if(f(b.namespace,b)===false){break}}};Chatterbox.Chatbook.prototype.server_message=function(b,a){for(ns in this.chan){this.chan[ns].server_message(b,a)}};Chatterbox.Chatbook.prototype.log_item=function(a){for(ns in this.chan){this.chan[ns].log_item(a)}};Chatterbox.Chatbook.prototype.log=function(a){for(ns in this.chan){this.chan[ns].log(a)}};Chatterbox.Chatbook.prototype.log_message=function(f,b){try{if(!f.global){if(!f.monitor){this.channel(b.ns).log_item(b) +}else{this.manager.monitoro.log_item(b)}}else{this.log_item(b)}}catch(a){try{this.ui.monitoro.server_message("Failed to log for",b.sns,b.html)}catch(a){console.log(">> Failed to log message for",b.sns,"::");console.log(">>",b.html)}}};Chatterbox.Chatbook.prototype.retime=function(){for(ns in this.chan){this.chan[ns].retime()}};Chatterbox.Chatbook.prototype.developer=function(){this.each(function(a,b){b.developer()})};Chatterbox.Chatbook.prototype.handle=function(g,b){var h=this.manager;var j=this.channel(g.ns);if(!j){return}var a="pkt_"+g.name;try{j[a](g,b)}catch(f){}};Chatterbox.Control=function(b){this.manager=b;this.manager.view.append(Chatterbox.template.control);this.view=this.manager.view.find("div.chatcontrol");this.ml=false;this.history={};this.tab={hit:false,cache:"",matched:[],index:-1,type:0,prefix:["","/",""],};this.el={form:this.view.find("form.msg"),i:{s:this.view.find("form.msg input.msg"),m:this.view.find("form.msg textarea.msg"),c:null,t:this.view.find("ul.buttons a[href~=#multiline].button")},brow:{m:this.view.find("div.brow"),b:this.view.find("div.brow ul.buttons"),s:this.view.find("div.brow ul.states")}}; +this.el.i.c=this.el.i.s;var a=this;this.el.i.t.click(function(f){a.multiline(!a.multiline());return false});this.el.i.s.keydown(function(f){return a.keypress(f)});this.el.i.m.keydown(function(f){return a.keypress(f)});this.el.form.submit(function(f){return a.submit(f)});this.add_button({label:"b",icon:false,href:"#bold",title:"Bold text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"i",icon:false,href:"#italic",title:"Italic text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"u",icon:false,href:"#underline",title:"Underline text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"sup",icon:false,href:"#sup",title:"Superscript",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"sub",icon:false,href:"#sub",title:"Subscript",handler:function(){a.surroundtext(a.el.i.c[0],"","")}})}; +Chatterbox.Control.prototype.surroundtext=function(k,j,b){var h=k.scrollTop;var a=k.value,f=k.selectionStart,g=k.selectionEnd;var l=k.value.substring(f,g);k.value=a.substring(0,f)+j+l+b+a.substring(g);k.selectionStart=f+j.length;k.selectionEnd=f+j.length+l.length;k.scrollTop=h;k.focus()};Chatterbox.Control.prototype.focus=function(){this.el.i.c.focus()};Chatterbox.Control.prototype.resize=function(){w=this.manager.view.width();this.view.css({width:"100%"});this.el.form.css({width:this.manager.view.width()-20});this.el.i.s.css({width:this.manager.view.width()-100});this.el.i.m.css({width:this.manager.view.width()-90})};Chatterbox.Control.prototype.height=function(){var a=this.view.outerHeight();return a};Chatterbox.Control.prototype.multiline=function(a){if(a==undefined||this.ml==a){return this.ml}this.ml=a;var b=(this.ml?"s":"m");a=(this.ml?"m":"s");this.el.i[b].css("display","none");this.el.i[a].css("display","inline-block");this.el.i.c=this.el.i[a];this.manager.resize();return this.ml +};Chatterbox.Control.prototype.add_button=function(a){a=Object.extend({label:"New",icon:false,href:"#button",title:"Button.",handler:function(){}},(a||{}));if(a.icon!==false){a.icon=" iconic "+a.icon}else{a.icon=" text"}this.el.brow.b.append(Chatterbox.render("brow_button",a));var b=this.el.brow.b.find("a[href="+a.href+"].button");b.click(function(f){a.handler();return false});return b};Chatterbox.Control.prototype.add_state=function(a){a=Object.extend({ref:"state",label:"some state"},(a||{}));var b=this.el.brow.s.find("li#"+a.ref);if(b.length==0){this.el.brow.s.append(Chatterbox.render("brow_state",a));return this.el.brow.s.find("li#"+a.ref)}b.html(a.label);return b};Chatterbox.Control.prototype.rem_state=function(a){return this.el.brow.s.find("li#"+a).remove()};Chatterbox.Control.prototype.chomp=function(){var f=this.el.i.c.val();var b=f.lastIndexOf(" ");if(b==-1){this.el.i.c.val("");return f}var a=f.slice(b+1);this.el.i.c.val(f.slice(0,b));if(a.length==0){return this.chomp()}return a +};Chatterbox.Control.prototype.unchomp=function(a){var b=this.el.i.c.val();if(!b){this.el.i.c.val(a)}else{this.el.i.c.val(b+" "+a)}};Chatterbox.Control.prototype.get_text=function(a){if(a==undefined){return this.el.i.c.val()}this.el.i.c.val(a||"");return this.el.i.c.val()};Chatterbox.Control.prototype.set_text=function(a){this.el.i.c.val(a||"")};Chatterbox.Control.prototype.cache_input=function(b,f){var a=this.get_history(b.namespace);if(a.index>-1){return}a.tmp=this.get_text();this.set_text(this.get_history(f.namespace).tmp)};Chatterbox.Control.prototype.get_history=function(a){if(!a){if(!this.manager.chatbook.current){a="~monitor"}}a=a||this.manager.chatbook.current.namespace;if(!this.history[a]){this.history[a]={index:-1,list:[],tmp:""}}return this.history[a]};Chatterbox.Control.prototype.append_history=function(b){if(!b){return}var a=this.get_history();a.list.unshift(b);a.index=-1;if(a.list.length>100){a.list.pop()}};Chatterbox.Control.prototype.scroll_history=function(a){var f=this.get_history(); +var b=this.get_text();if(f.index==-1){if(b){f.tmp=b}else{f.list[f.index]=b}}if(a){if(f.list.length>0&&f.index<(f.list.length-1)){f.index++}}else{if(f.index>-1){f.index--}}this.set_text(f.list[f.index]||f.tmp)};Chatterbox.Control.prototype.tab_item=function(b){if(!this.tab.hit){this.start_tab(b)}this.chomp();this.tab.index++;if(this.tab.index>=this.tab.matched.length){this.tab.index=-1}if(this.tab.index==-1){this.unchomp(this.tab.prefix[this.tab.type]+this.tab.cache);return}var a=this.get_text()==""?(this.tab.type==0?": ":" "):"";this.unchomp(this.tab.prefix[this.tab.type]+this.tab.matched[this.tab.index]+a)};Chatterbox.Control.prototype.start_tab=function(f){this.tab.hit=true;this.tab.index=-1;this.tab.matched=[];this.tab.type=0;var j=this.chomp();this.unchomp(j);if(j[0]=="/"||j[0]=="#"||j[0]=="@"){this.tab.type=j[0]=="/"?1:2;if(j[0]=="/"){j=j.slice(1)}}else{this.tab.type=0}this.tab.cache=j;j=j.toLowerCase();this.tab.matched=[];if(this.tab.type==0){var k=this.manager.client.channel(this.manager.chatbook.current.namespace); +for(var a in k.info.members){if(a.toLowerCase().indexOf(j)==0){this.tab.matched.push(a)}}}else{if(this.tab.type==1){var h="";for(var b in this.manager.client.cmds){h=this.manager.client.cmds[b];if(h.indexOf(j)==0){this.tab.matched.push(h)}}}else{if(this.tab.type==2){var g=this;this.manager.client.each_channel(function(l,m){if(m.namespace.toLowerCase().indexOf(j)==0){g.tab.matched.push(m.namespace)}})}}}};Chatterbox.Control.prototype.end_tab=function(a){this.tab.hit=false;this.tab.matched=[];this.tab.cache="";this.tab.index=-1};Chatterbox.Control.prototype.submit=function(a){var b=this.get_text();this.append_history(b);this.set_text("");this.handle(a,b);return false};Chatterbox.Control.prototype.keypress=function(f){var b=f.which||f.keyCode;var g=this.tab.hit;var a=false;switch(b){case 13:if(!this.multiline()){this.submit(f)}else{if(f.shiftKey){this.submit(f)}else{a=true}}break;case 38:if(!this.multiline()){this.scroll_history(true);break}a=true;break;case 40:if(!this.multiline()){this.scroll_history(false); +break}a=true;break;case 9:if(f.shiftKey){this.manager.channel_right()}else{this.tab_item(f);g=false}break;case 219:if(f.ctrlKey){this.manager.channel_left()}else{a=true}break;case 221:if(f.ctrlKey){this.manager.channel_right()}else{a=true}break;default:a=true;break}if(g){this.end_tab(f)}return a};Chatterbox.Control.prototype.handle=function(b,h){if(h==""){return}if(!this.manager.chatbook.current){return}var l=false;if(h[0]!="/"){l=true}h=(b.shiftKey?"/npmsg ":(h[0]=="/"?"":"/say "))+h;h=h.slice(1);var m=h.split(" ");var f=m.shift().toLowerCase();var k=this.manager.chatbook.current.namespace;var j=k;if(!l&&m[0]){var g=m[0][0];if((g=="#"||g=="@")&&m[0].length>1){j=this.manager.format_ns(m.shift())}}var n=m.join(" ");var a=this.manager.client.trigger("cmd."+f,{name:"cmd",cmd:f,args:n,target:j,ns:k});if(a==0){this.manager.pager.notice({ref:"cmd-fail",heading:"Command failed",content:'"'+f+'" is not a command.'},false,5000)}};Chatterbox.Navigation=function(a){this.manager=a;this.showclose=this.manager.settings.tabclose; +this.settings={};this.settings.open=false;this.el={n:this.manager.view.find("nav.tabs"),tw:this.manager.view.find("nav.tabs div.tabwrap"),t:this.manager.view.find("nav.tabs #chattabs"),b:this.manager.view.find("nav.tabs #tabnav"),l:this.manager.view.find("nav.tabs #tabnav .arrow_left"),r:this.manager.view.find("nav.tabs #tabnav .arrow_right"),s:this.manager.view.find("nav.tabs #tabnav #settings-button"),};if(!this.showclose){if(!this.el.t.hasClass("hc")){this.el.t.addClass("hc")}}var b=this;this.el.s.click(function(h){if(b.settings.open){return false}var f={e:h,settings:new Chatterbox.Settings.Config(b.manager)};b.configure_page(f);b.manager.trigger("settings.open",f);b.manager.trigger("settings.open.ran",f);var g=f.settings.page("About");g.item("text",{ref:"about-chatterbox",wclass:"centered faint",text:'Using Chatterbox version '+Chatterbox.VERSION+" "+Chatterbox.STATE+' by ~photofroggy.'}); +b.settings.window=new Chatterbox.Settings(b.manager,f.settings);b.settings.window.build();b.settings.open=true;return false});this.el.l.click(function(){b.manager.channel_left();return false});this.el.r.click(function(){b.manager.channel_right();return false})};Chatterbox.Navigation.prototype.configure_page=function(b){var g=this.manager;var f=b.settings.page("Main");var h={};h.theme=replaceAll(g.settings.theme,"wsct_","");h.clock=g.clock();h.tc=g.nav.closer();var a=[];for(i in g.settings.themes){name=replaceAll(g.settings.themes[i],"wsct_","");a.push({value:name,title:name,selected:h.theme==name})}f.item("Form",{ref:"ui",title:"UI",hint:"Timestamp
        Choose between a 24 hour clock and a 12 hour clock.\n\nTheme
        Change the look of the client.\n\nClose Buttons
        Turn tab close buttons on/off.",fields:[["Dropdown",{ref:"theme",label:"Theme",items:a}],["Dropdown",{ref:"clock",label:"Timestamp Format",items:[{value:"24",title:"24 hour",selected:h.clock},{value:"12",title:"12 hour",selected:!h.clock}]}],["Checkbox",{ref:"tabclose",label:"Close Buttons",items:[{value:"yes",title:"On",selected:h.tc}]}],],event:{change:function(j){g.clock(j.data.clock=="24"); +g.theme(j.data.theme);g.nav.closer(j.data.tabclose.indexOf("yes")>-1)},save:function(j){h.clock=g.clock();h.theme=replaceAll(g.theme(),"wsct_","");h.tc=g.nav.closer();g.trigger("settings.save.ui",{clock:h.clock,tabclose:h.tc,theme:"wsct_"+h.theme})},close:function(j){g.clock(h.clock);g.theme(h.theme);g.nav.closer(h.tc)}}})};Chatterbox.Navigation.prototype.height=function(){var a=this.el.n.outerHeight();return a};Chatterbox.Navigation.prototype.add_button=function(a){a=Object.extend({label:"New",icon:false,href:"#button",title:"Button.",handler:function(){}},(a||{}));if(a.icon!==false){a.icon=" iconic "+a.icon}else{a.icon=" text"}this.el.b.prepend(Chatterbox.render("nav_button",a));var b=this.el.b.find("a[href="+a.href+"].button");b.click(function(f){a.handler();return false});this.resize();return b};Chatterbox.Navigation.prototype.add_tab=function(a,b){this.el.t.append(Chatterbox.render("tab",{selector:a,ns:b}));return this.el.t.find("#"+a+"-tab")};Chatterbox.Navigation.prototype.resize=function(){this.el.tw.width(this.el.n.width()-this.el.b.outerWidth()-20); +if(this.settings.open){this.settings.window.resize()}};Chatterbox.Navigation.prototype.closer=function(a){if(a==undefined||a==this.showclose){return this.showclose}this.showclose=a;if(this.showclose){if(!this.el.t.hasClass("hc")){return}this.el.t.removeClass("hc");return}if(this.el.t.hasClass("hc")){return}this.el.t.addClass("hc")};Chatterbox.Pager=function(a){this.manager=a;this.lifespan=20000;this.halflife=5000;this.el={m:null,click:null};this.sound={click:function(){},};this.notices=[];this.build()};Chatterbox.Pager.prototype.build=function(){this.el.m=this.manager.view.find("div.pager")};Chatterbox.Pager.prototype.notice=function(g,m,l,f){var j={frame:null,close:null,foot:null,b:{},options:Object.extend({ref:"notice",icon:"",heading:"Some notice",content:"Notice content goes here."},(g||{})),onclose:function(){},ondestroy:function(){}};j.options.ref+="-"+(new Date()).valueOf();j.options.content=j.options.content.split("\n").join("

        ");this.notices.push(j);this.el.m.append(Chatterbox.render("pager.notice",j.options)); +j.frame=this.el.m.find("#"+j.options.ref).last();j.close=j.frame.find("a.close_notice");j.foot=j.frame.find("footer.buttons");var h={};for(var a in j.options.buttons){if(!j.options.buttons.hasOwnProperty(a)){continue}h=j.options.buttons[a];j.foot.append(Chatterbox.render("pager.button",h));j.b[a]=j.foot.find("a#"+h.ref);j.b[a].click(h.click)}var k=this;j.close.click(function(){j.onclose();k.remove_notice(j);return false});if(!m){if(!l){l=k.lifespan}setTimeout(function(){k.remove_notice(j,true)},l)}if(f!==true){this.manager.sound.click()}return j};Chatterbox.Pager.prototype.remove_notice=function(a,f){var b=this;if(this.notices.indexOf(a)==-1){return false}a.frame.fadeTo((f?this.halflife:300),0).slideUp(function(){a.frame.remove();b.notices.splice(b.notices.indexOf(a),1);a.ondestroy()});if(f){a.frame.mouseenter(function(){if(b.notices.indexOf(a)==-1){return}a.frame.stop(true);a.frame.slideDown(function(){a.frame.fadeTo(300,1);a.frame.mouseleave(function(){setTimeout(function(){b.remove_notice(a,true) +},b.lifespan)})})})}};Chatterbox.Pager.prototype.find_notice=function(a){for(var b in this.notices){if(this.notices[b].options.ref==a){return this.notices[b]}}return null};Chatterbox.Popup=function(b,a){this.manager=b;this.pview=(this.manager||{view:{find:function(){}}}).view;this.window=null;this.closeb=null;this.options=Object.extend({ref:"popup",title:"Popup",close:true,content:""},(a||{}))};Chatterbox.Popup.prototype.build=function(){var b=this.options;if(this.options.close){b.title+=''}this.pview.append(Chatterbox.render("popup",b));this.window=this.pview.find(".floater."+b.ref);if(this.options.close){this.closeb=this.window.find("a.close");var a=this;this.closeb.click(function(f){a.close();return false})}};Chatterbox.Popup.prototype.close=function(){this.window.remove()};Chatterbox.Popup.Prompt=function(b,a){a=a||{};a=Object.extend({position:[0,0],ref:"prompt",title:"Input",close:false,label:"","default":"","submit-button":"Submit",event:{submit:function(){},cancel:function(){}}},a); +Chatterbox.Popup.call(this,b,a);this.data=this.options["default"]};Chatterbox.Popup.Prompt.prototype=new Chatterbox.Popup();Chatterbox.Popup.Prompt.prototype.constructor=Chatterbox.Popup.Prompt;Chatterbox.Popup.Prompt.prototype.build=function(){this.options.content=Chatterbox.template.prompt.main;Chatterbox.Popup.prototype.build.call(this);this.window.css({left:this.options.position[0],top:this.options.position[1]});var a=this;this.window.find(".button.close").click(function(){a.options.event.cancel(a);a.close();return false});this.window.find(".button.submit").click(function(){a.data=a.window.find("input").val();a.options.event.submit(a);a.close();return false});this.window.find("form").submit(function(){a.data=a.window.find("input").val();a.options.event.submit(a);a.close();return false})};Chatterbox.Popup.ItemPicker=function(b,a){a=a||{};a=Object.extend({position:[100,60],ref:"item-picker",title:"Items",event:{select:function(f){}}},a);Chatterbox.Popup.call(this,b,a);this.pview=this.pview.find(".chatbook"); +this.data=this.options["default"];this.pages=[];this.cpage=null};Chatterbox.Popup.ItemPicker.prototype=new Chatterbox.Popup();Chatterbox.Popup.ItemPicker.prototype.constructor=Chatterbox.Popup.ItemPicker;Chatterbox.Popup.ItemPicker.prototype.build=function(){this.options.content=Chatterbox.render("ip.main",{});Chatterbox.Popup.prototype.build.call(this);this.window.css({right:this.options.position[0],bottom:this.options.position[1]});this.closeb.removeClass("medium");this.pbook=this.window.find("section.pages");this.tabs=this.window.find("section.tabs ul");this.buttons=this.window.find("section.buttons");var f=this;var b=null;for(var a in this.pages){if(!this.pages.hasOwnProperty(a)){continue}b=this.pages[a];b.build();if(a==0){this.select_page(b)}}};Chatterbox.Popup.ItemPicker.prototype.refresh=function(){if(this.cpage==null){return}else{this.cpage.refresh()}};Chatterbox.Popup.ItemPicker.prototype.page=function(b,a){b=b.toLowerCase();for(var f in this.pages){if(!this.pages.hasOwnProperty(f)){continue +}if(this.pages[f].name.toLowerCase()==b){return this.pages[f]}}return(a||null)};Chatterbox.Popup.ItemPicker.prototype.add_page=function(a,b){this.pages.push(new (b||Chatterbox.Popup.ItemPicker.Page)(this,a))};Chatterbox.Popup.ItemPicker.prototype.add_button=function(a){a=Object.extend({href:"#button",title:"Button",label:"Button"},(a||{}));this.buttons.append(Chatterbox.render("ip.button",a));return this.buttons.find("a[href="+a.href+"]")};Chatterbox.Popup.ItemPicker.prototype.select=function(a){this.options.event.select(a)};Chatterbox.Popup.ItemPicker.prototype.select_page=function(a){if(!a){return}if(this.cpage!=null){this.cpage.hide()}this.cpage=a||null;if(this.cpage!=null){this.cpage.show()}};Chatterbox.Popup.ItemPicker.Page=function(b,a){this.picker=b;this.options=Object.extend({ref:"page",href:"#page",label:"Page",title:"page",items:[],content:"No items on this page.",},(a||{}));this.name=this.options.label;this.nrefresh=true};Chatterbox.Popup.ItemPicker.Page.prototype.build=function(){this.picker.pbook.append(Chatterbox.render("ip.page",this.options)); +this.picker.tabs.append(Chatterbox.render("ip.tab",this.options));this.view=this.picker.pbook.find("div.page#"+this.options.ref);this.items=this.view.find("ul");this.tab=this.picker.tabs.find("#"+this.options.ref);this.refresh();var a=this;this.tab.find("a").click(function(){a.picker.select_page(a);return false})};Chatterbox.Popup.ItemPicker.Page.prototype.refresh=function(){var a=this.build_list();if(a.length==0){this.options.content="No items on this page."}else{this.options.content="

          "+a+"
        "}this.view.html(this.options.content);this.items=this.view.find("ul");this.hook_events();this.nrefresh=false};Chatterbox.Popup.ItemPicker.Page.prototype.hook_events=function(){var a=this;this.items.find("li").each(function(b,g){var h=a.view.find(g);var f=h.find(".value").html();h.click(function(){a.picker.select(f)})})};Chatterbox.Popup.ItemPicker.Page.prototype.build_list=function(){var f=[];var g=null;var j,h,b;for(var a in this.options.items){if(!this.options.items.hasOwnProperty(a)){continue +}g=this.options.items[a];h=g.value||g;j=g.title||h;b=g.html||false;f.push('
      • '+(b?h:''+h+"")+"
      • ")}return f.join("")};Chatterbox.Popup.ItemPicker.Page.prototype.show=function(){this.tab.addClass("selected");this.view.css("display","block");this.refresh()};Chatterbox.Popup.ItemPicker.Page.prototype.hide=function(){this.tab.removeClass("selected");this.view.css("display","none")};Chatterbox.Protocol=function(){this.messages={chatserver:{keys:["version"],template:'** Connected to llama {version} *',global:true},dAmnServer:{keys:["version"],template:'** Connected to dAmnServer {version} *',global:true},login:{keys:["username","e","data"],template:'** Login as {username}: "{e}" *',global:true},join:{keys:["ns","e"],template:'** Join {ns}: "{e}" *',monitor:true},part:{keys:["ns","e","r"],template:'** Part {ns}: "{e}" * {r}',monitor:true},property:{keys:["ns","p","by","ts","value"],template:'** Got {p} for {ns} *',monitor:true},recv_msg:{keys:["user","message"],template:'<{user}>{message}'},recv_action:{keys:["s","user","message"],template:'* {user}{message}'},recv_join:{keys:["user","s","info"],template:'** {user} has joined *',},recv_part:{keys:["user","r"],template:'** {user} has left * {r}'},recv_privchg:{keys:["user","s","by","pc"],template:'** {user} has been made a member of {pc} by {by} *'},recv_kicked:{keys:["user","s","by","r"],template:'** {user} has been kicked by {by} * {r}'},recv_admin_create:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been created by {user} * {privs}'},recv_admin_update:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been updated by {user} * {privs}'},recv_admin_rename:{keys:["p","user","prev","pc"],template:'** Privilege class {prev} has been renamed to {pc} by {user} *'},recv_admin_move:{keys:["p","user","prev","pc","affected"],template:'** All members of {prev} have been moved to {pc} by {user} * {affected} affected user(s)'},recv_admin_remove:{keys:["p","user","pc","affected"],template:'** Privilege class {pc} has been removed by {user} * {affected} affected user(s)'},recv_admin_show:null,recv_admin_showverbose:null,recv_admin_privclass:{keys:["p","e","command"],template:'** Admin command "{command}" failed * {e}'},kicked:{keys:["ns","user","r"],template:'** You have been kicked by {user} * {r}'},ping:null,disconnect:{keys:["e"],template:'** You have been disconnected * {e}',global:true},send:{keys:["ns","e"],template:'** Send error: {e}'},kick:{keys:["ns","user","e"],template:'** Could not kick {user} * {e}'},get:{keys:["ns","p","e"],template:'** Could not get {p} info for {ns} * {e}'},set:{keys:["ns","p","e"],template:'** Could not set {p} * {e}'},kill:{keys:["ns","e"],template:'** Kill error * {e}'},unknown:{keys:["ns","packet"],template:'** Received unknown packet in {ns} * {packet}',monitor:true}} +};Chatterbox.Protocol.prototype.extend_messages=function(b){for(var a in b){this.messages[a]=b[a]}};Chatterbox.Protocol.prototype.log=function(b){var a=this.messages[b.name];return new Chatterbox.Protocol.LogMessage(b,a)};Chatterbox.Protocol.LogMessage=function(b,a){a=a||{};this.event=b;this.template=a.template||"";this.keys=a.keys||[];this.monitor=a.monitor||false;this.global=a.global||false;this._html=false;this._text=false;this._ansi=false};Chatterbox.Protocol.LogMessage.prototype.text=function(){if(this._text===false){this._text=this.render(0)}return this._text};Chatterbox.Protocol.LogMessage.prototype.html=function(){if(this._html===false){this._html=this.render(1)}return this._html};Chatterbox.Protocol.LogMessage.prototype.ansi=function(){if(this._ansi===false){this._ansi=this.render(2)}return this._ansi};Chatterbox.Protocol.LogMessage.prototype.render=function(f){if(f===undefined){f=0}var b=this.template;var g="";for(var a in this.keys){if(!this.keys.hasOwnProperty(a)){continue}key=this.keys[a]; if(key instanceof Array){key=key[1]}if(!this.event.hasOwnProperty(key)||key=="pkt"){continue}g=this.event[key];if(g==null){continue}if(key=="ns"||key=="sns"){key="ns";g=this.event.sns}if(g.hasOwnProperty("_parser")){switch(f){case 1:g=g.html();break;case 2:g=g.ansi();break;case 0:default:g=g.text();break}}b=replaceAll(b,"{"+key+"}",g)}return b};Chatterbox.Settings=function(b,a){Chatterbox.Popup.call(this,b,{ref:"settings",title:"Settings",close:false,content:""});this.config=a;this.saveb=null;this.scb=null;this.tabs=null;this.book=null;this.changed=false;this.manager=b};Chatterbox.Settings.prototype=new Chatterbox.Popup();Chatterbox.Settings.prototype.constructor=Chatterbox.Settings;Chatterbox.Settings.prototype.build=function(){this.options.content=Chatterbox.template.settings.main;Chatterbox.Popup.prototype.build.call(this);this.saveb=this.window.find("a.button.save");this.closeb=this.window.find("a.close");this.scb=this.window.find("a.button.saveclose");this.tabs=this.window.find("nav.tabs ul.tabs"); this.book=this.window.find("div.book");this.config.build(this.manager,this);this.window.find("ul.tabs li").first().addClass("active");this.window.find("div.book div.page").first().addClass("active");var a=this;this.window.find("form").bind("change",function(){a.changed=true});this.config.each_page(function(b,f){f.each_item(function(g,h){h._onchange=function(j){a.changed=true}})});this.saveb.click(function(b){a.save();return false});this.closeb.click(function(b){if(a.changed){if(!confirm("Are you sure? You will lose any unsaved changes.")){return false}}a.close();return false});this.scb.click(function(b){a.save();a.close();return false});this.resize()};Chatterbox.Settings.prototype.resize=function(){var a=this.window.find(".inner");var f=a.find("h2");var g=a.find(".bookwrap");var b=a.find("footer");g.height(a.height()-b.outerHeight()-f.outerHeight()-15);this.book.height(g.innerHeight()-this.tabs.outerHeight()-25);this.book.width(g.innerWidth()-20);this.config.resize()};Chatterbox.Settings.prototype.switch_page=function(b){var f=this.tabs.find("li.active").first(); var a=f.prop("id").split("-",1)[0];f=this.config.page(a.split("_").join(" "));f.hide();b.show()};Chatterbox.Settings.prototype.save=function(){this.config.save(this);this.changed=false;this.manager.trigger("settings.save",{config:this.config})};Chatterbox.Settings.prototype.close=function(){this.window.remove();this.manager.nav.settings.open=false;this.manager.nav.settings.window=null;this.config.close(this);this.manager.trigger("settings.close",{config:this.config})};Chatterbox.Settings.Config=function(a){this.manager=a||null;this.pages=[]};Chatterbox.Settings.Config.prototype.find_page=function(b){var g=b.toLowerCase();var f;for(var a in this.pages){f=this.pages[a];if(f.lname==g){return f}}return null};Chatterbox.Settings.Config.prototype.build=function(f,b){f=f||this.manager;for(var a in this.pages){this.pages[a].build(f,b)}};Chatterbox.Settings.Config.prototype.resize=function(){for(var a in this.pages){this.pages[a].resize()}};Chatterbox.Settings.Config.prototype.page=function(b,a){var f=this.find_page(b); diff --git a/dist/wsc.js b/dist/wsc.js index 133b5af..65621dc 100644 --- a/dist/wsc.js +++ b/dist/wsc.js @@ -4196,6 +4196,35 @@ Chatterbox.STATE = 'beta'; Chatterbox._gum = function( ) {}; + +// jQuery hook. + +( function( $ ) { + $.fn.chatterbox = function( method, client, options ) { + + var ui = $(window).data('chatterbox'); + + if( method == 'init' || ui === undefined ) { + if( ui == undefined ) { + ui = new Chatterbox.UI( $(this), client, options, ($.browser.mozilla || false) ); + $(window).resize(ui.resize); + } + $(window).data('chatterbox', ui); + } + + if( method != 'init' && method != undefined ) { + method = 'jq_' + method; + if( method in ui ) + ui[method]( $(this), options); + } + + return ui; + + }; + +} )( jQuery ); + + /** * This object is the platform for the wsc UI. Everything can be used and * loaded from here. @@ -4208,7 +4237,7 @@ Chatterbox._gum = function( ) {}; * @param mozilla {Boolean} Is the browser in use made by Mozilla? * @param [events] {Object} EventEmitter object. **/ -Chatterbox.UI = function( client, view, options, mozilla, events ) { +Chatterbox.UI = function( view, client, options, mozilla, events ) { this.client = client; this.events = events || new EventEmitter(); @@ -8232,7 +8261,11 @@ Chatterbox.Popup.ItemPicker.Page.prototype.hide = function( ) { /** - * Parser for dAmn-like protocols. + * Rendering for dAmn-like protocols. + * + * This object is mainly used for constructing LogMessage objects with the + * right data. Seemed to make more sense than having multiple definitions of + * LogMessage and/or if...else/switch...case blocks. * * @class Chatterbox.Protocol * @constructor @@ -8453,6 +8486,8 @@ Chatterbox.Protocol.prototype.log = function( event ) { */ Chatterbox.Protocol.LogMessage = function( event, options ) { + options = options || {}; + this.event = event; this.template = options.template || ''; this.keys = options.keys || []; diff --git a/dist/wsc.min.js b/dist/wsc.min.js index 53e5657..222d27c 100644 --- a/dist/wsc.min.js +++ b/dist/wsc.min.js @@ -45,53 +45,53 @@ this.storage.ui.set("clock",this.settings.ui.clock.toString());this.storage.ui.s break;default:if(a.indexOf("chat:")==0||a.indexOf("pchat:")==0||a.indexOf("server:")==0||a.indexOf("feed:")==0){break}a="chat:"+a;break}return a};wsc.Client.prototype.create_ns=function(b,d,a){var f=this.channel(b,new wsc.Channel(this,b,d,a));this.trigger("ns.create",{name:"ns.create",ns:b,chan:f,client:this});f.build()};wsc.Client.prototype.remove_ns=function(a){if(!a){return}this.cascade("ns.remove",function(b){var d=b.client.channel(b.ns);if(!d){return}delete b.client.channelo[d.raw.toLowerCase()]},{ns:a,client:this})};wsc.Client.prototype.select_ns=function(a){this.cchannel=this.channel(a)||this.cchannel};wsc.Client.prototype.log=function(a,b){var d=this.channel(a);if(!d){return}d.log(b)};wsc.Client.prototype.monitor=function(a){console.log(a)};wsc.Client.prototype.mute_user=function(a){return this.ui.mute_user(a)};wsc.Client.prototype.unmute_user=function(a){return this.ui.unmute_user(a)};wsc.Client.prototype.send=function(a){return this.conn.send(a)};wsc.Client.prototype.handshake=function(){this.send(wsc_packetstr(this.settings.client,this.settings.clientver,{agent:this.settings.agent})) };wsc.Client.prototype.login=function(){pkt="login "+this.settings.username+"\npk="+this.settings.pk+"\n";this.send(pkt)};wsc.Client.prototype.pong=function(){this.send(wsc_packetstr("pong"))};wsc.Client.prototype.join=function(a){this.send(wsc_packetstr("join",this.format_ns(a)))};wsc.Client.prototype.part=function(a){this.send(wsc_packetstr("part",this.format_ns(a)))};wsc.Client.prototype.say=function(a,b){var d=this;this.cascade("send.msg",function(f){d.send(wsc_packetstr("send",d.format_ns(f.ns),{},wsc_packetstr("msg","main",{},f.input)))},{input:b,ns:a})};wsc.Client.prototype.npmsg=function(a,b){var d=this;this.cascade("send.npmsg",function(f){d.send(wsc_packetstr("send",d.format_ns(f.ns),{},wsc_packetstr("npmsg","main",{},f.input)))},{input:b,ns:a})};wsc.Client.prototype.action=function(a,b){var d=this;this.cascade("send.action",function(f){d.send(wsc_packetstr("send",d.format_ns(f.ns),{},wsc_packetstr("action","main",{},f.input)))},{input:b,ns:a})};wsc.Client.prototype.promote=function(d,a,b){this.send(wsc_packetstr("send",this.format_ns(d),{},wsc_packetstr("promote",a,{},(!b?"":b)))) };wsc.Client.prototype.demote=function(d,a,b){this.send(wsc_packetstr("send",this.format_ns(d),{},wsc_packetstr("demote",a,{},(!b?"":b))))};wsc.Client.prototype.ban=function(b,a){this.send(wsc_packetstr("send",this.format_ns(b),{},wsc_packetstr("ban",a)))};wsc.Client.prototype.unban=function(b,a){this.send(wsc_packetstr("send",this.format_ns(b),{},wsc_packetstr("unban",a)))};wsc.Client.prototype.kick=function(b,a,d){var f=this;this.cascade("send.kick",function(g){f.send(wsc_packetstr("kick",f.format_ns(g.ns),{u:g.user},g.input||null))},{input:d||"",ns:b,user:a})};wsc.Client.prototype.kill=function(a,b){this.send(wsc_packetstr("kill","login:"+a,{},b||null))};wsc.Client.prototype.admin=function(a,b){this.send(wsc_packetstr("send",this.format_ns(a),{},wsc_packetstr("admin","",{},b)))};wsc.Client.prototype.property=function(a,b){this.send(wsc_packetstr("get",this.format_ns(a),{p:b}))};wsc.Client.prototype.set=function(a,d,b){var f=this;this.cascade("send.set",function(g){f.send(wsc_packetstr("set",f.format_ns(g.ns),{p:g.property},g.input)) -},{input:b,ns:a,property:d})};wsc.Client.prototype.whois=function(a){this.send(wsc_packetstr("get","login:"+a,{p:"info"}))};wsc.Client.prototype.disconnect=function(){this.send(wsc_packetstr("disconnect"))};var Chatterbox={};Chatterbox.VERSION="0.20.104";Chatterbox.STATE="beta";Chatterbox._gum=function(){};Chatterbox.UI=function(b,a,d,g,f){this.client=b;this.events=f||new EventEmitter();this.mozilla=g;this.umuted=[];this.viewing=true;this.settings={themes:["wsct_dAmn","wsct_dark"],theme:"wsct_dark",monitor:["~Monitor",true],username:"",domain:"website.com",clock:true,tabclose:true,developer:false,media:"/static/"};var h=this;this.sound={bank:{m:null},add:function(j,k){if(h.sound.hasOwnProperty(j)){return false}h.sound.bank[j]=k;k.load();h.sound[j]=function(){h.sound.play(h.sound.bank[j])};return true},play:function(j){j.pause();j.currentTime=0;j.play()},toggle:function(k){for(var j in h.sound.bank){if(!h.sound.bank.hasOwnProperty(j)){continue}h.sound.bank[j].muted=k}},mute:function(){h.sound.toggle(true) -},unmute:function(){h.sound.toggle(false)},};this.settings=a.extend(this.settings,d);a.append('
        ');this.mw=new wsc.Middleware();this.view=a.find(".wsc");this.mns=this.format_ns(this.settings.monitor[0]);this.lun=this.settings.username.toLowerCase();this.monitoro=null;this.swidth=(function(){if($.browser.msie){var l=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body"),k=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body");scrollbarWidth=l.width()-k.width();l.add(k).remove()}else{var j=$("
        ").css({width:100,height:100,overflow:"auto",position:"absolute",top:-1000,left:-1000}).prependTo("body").append("
        ").find("div").css({width:"100%",height:200});scrollbarWidth=100-j.width();j.parent().remove()}return scrollbarWidth})();if(window.mozRTCPeerConnection){Chatterbox._gum=function(k,l,j){return navigator.mozGetUserMedia(k,l,j) -}}if(window.webkitRTCPeerConnection){Chatterbox._gum=function(k,l,j){return navigator.webkitGetUserMedia(k,l,j)}}if(window.RTCPeerConnection&&!window.mozRTCPeerConnection){Chatterbox._gum=function(k,l,j){return navigator.getUserMedia(k,l,j)}}this.LIB="Chatterbox";this.VERSION=Chatterbox.VERSION;this.STATE=Chatterbox.STATE};wsc.defaults.UI=Chatterbox.UI;Chatterbox.UI.prototype.trigger=function(a,b){this.events.emit(a,b,this)};Chatterbox.UI.prototype.on=function(b,a){this.events.addListener(b,a)};Chatterbox.UI.prototype.middle=function(a,b){return this.mw.add(a,b)};Chatterbox.UI.prototype.cascade=function(a,d,b){this.mw.run(a,d,b)};Chatterbox.UI.prototype.remove_listeners=function(){this.events.removeListeners()};Chatterbox.UI.prototype.deform_ns=function(b){var a=b[0];if(a=="#"||a=="@"||a=="~"||a=="+"){return b}if(b.indexOf("chat:")==0){return"#"+b.slice(5)}if(b.indexOf("server:")==0){return"~"+b.slice(7)}if(b.indexOf("feed:")==0){return"#"+b.slice(5)}if(b.indexOf("login:")==0){return"@"+b.slice(6) -}if(b.indexOf("pchat:")==0){var d=b.split(":");d.shift();for(i in d){name=d[i];if(name.toLowerCase()!=this.lun){return"@"+name}}}return"#"+b};Chatterbox.UI.prototype.format_ns=function(a){var d=a.slice(1);switch(a[0]){case"@":var b=[d,this.lun];b.sort(caseInsensitiveSort);b.unshift("pchat");a=b.join(":");break;case"~":a="server:"+d;break;case"+":a="feed:"+d;break;case"#":a="chat:"+d;break;default:if(a.indexOf("chat:")==0||a.indexOf("pchat:")==0||a.indexOf("server:")==0||a.indexOf("feed:")==0){break}a="chat:"+a;break}return a};Chatterbox.UI.prototype.set_events=function(a){this.events=a||this.events};Chatterbox.UI.prototype.clock=function(a){if(a===undefined||a==this.settings.clock){return this.settings.clock}this.settings.clock=a;this.chatbook.retime();return this.settings.clock};Chatterbox.UI.prototype.get_user_media=function(b,d,a){Chatterbox._gum(b,d,a)};Chatterbox.UI.prototype.build=function(j,a,b){this.view.append(Chatterbox.render("ui",this.settings));this.control=new (j||Chatterbox.Control)(this); -this.nav=new (a||Chatterbox.Navigation)(this);this.chatbook=new (b||Chatterbox.Chatbook)(this);this.pager=new Chatterbox.Pager(this);this.monitoro=this.chatbook.create_channel(this.mns,this.settings.monitor[1],true);this.monitoro.show();this.control.focus();this.sound.bank.m=this.view.find("div.soundbank");this.sound.add("click",this.sound.bank.m.find("audio.click")[0]);var h=this.sound;var f=false;var d=this.nav.add_button({label:"",icon:"volume",href:"#mute",title:"Mute the client",handler:function(){if(!f){h.mute();d.removeClass("volume");d.addClass("volume_mute");d.prop("title","Unmute the client");f=true;return false}h.unmute();d.removeClass("volume_mute");d.addClass("volume");d.prop("title","Mute the client");f=false;return false}});var g=this;$(window).focus(function(){g.viewing=true});$(window).blur(function(){g.viewing=false});this.client.bind("pkt",function(l,k){g.packet(l,k)});this.client.middle("ns.remove",function(l,k){g.remove_channel(l.ns);k(l)});this.client.bind("ns.create",function(l,k){g.create_channel(l.chan.raw,l.chan.hidden) -});this.client.bind("ns.user.list",function(k){g.channel(k.ns).set_user_list(k.users)});this.client.middle("ns.user.privchg",function(l,k){g.channel(l.ns).privchg(l,k)});this.client.bind("ns.user.remove",function(l,k){g.channel(l.ns).remove_one_user(l.user)});this.client.bind("ns.user.registered",function(k){g.channel(k.ns).register_user(k.user)})};Chatterbox.UI.prototype.resize=function(){this.control.resize();this.view.height(this.view.parent().height());this.nav.resize();this.chatbook.resize(((this.view.parent().height()-this.nav.height())-this.control.height())-5)};Chatterbox.UI.prototype.loop=function(){this.chatbook.loop()};Chatterbox.UI.prototype.packet=function(b,a){var d=this;var f=a.protocol.log(b);if(f){if(this.settings.developer){console.log(">>>",b.sns,"|",f.text())}if(b.hasOwnProperty("s")&&b.s=="0"){this.chatbook.handle(b,a);return}b.html=f.html();this.cascade("log_message",function(h,g){d.chatbook.log_message(h.message,h.event)},{message:f,event:b})}this.chatbook.handle(b,a) -};Chatterbox.UI.prototype.create_channel=function(b,a){this.chatbook.create_channel(b,a)};Chatterbox.UI.prototype.remove_channel=function(a){this.chatbook.remove_channel(a)};Chatterbox.UI.prototype.toggle_channel=function(a){return this.chatbook.toggle_channel(a)};Chatterbox.UI.prototype.channel=function(a,b){return this.chatbook.channel(a,b)};Chatterbox.UI.prototype.channels=function(){return this.chatbook.channels()};Chatterbox.UI.prototype.channel_left=function(){this.chatbook.channel_left()};Chatterbox.UI.prototype.channel_right=function(){this.chatbook.channel_right()};Chatterbox.UI.prototype.monitor=function(b,a){this.monitoro.server_message(b,a)};Chatterbox.UI.prototype.server_message=function(b,a){this.chatbook.server_message(b,a)};Chatterbox.UI.prototype.log_item=function(a){this.chatbook.log_item(a)};Chatterbox.UI.prototype.log=function(a){this.chatbook.log(a)};Chatterbox.UI.prototype.mute_user=function(a){if(!a){return false}a=a.toLowerCase();if(this.umuted.indexOf(a)!=-1){return false -}this.umuted.push(a);this.chatbook.each(function(b,d){d.mute_user(a)});return true};Chatterbox.UI.prototype.unmute_user=function(a){if(!a){return false}a=a.toLowerCase();var b=this.umuted.indexOf(a);if(b==-1){return false}this.umuted.splice(b,1);this.chatbook.each(function(d,f){f.unmute_user(a)});return true};Chatterbox.UI.prototype.clear_user=function(a){this.chatbook.each(function(b,d){d.clear_user(a)})};Chatterbox.UI.prototype.theme=function(a){if(this.settings.theme==a){return this.settings.theme}if(this.settings.themes.indexOf(a)==-1){a="wsct_"+a;if(this.settings.themes.indexOf(a)==-1){return this.settings.theme}}this.view.removeClass(this.settings.theme).addClass(a);this.settings.theme=a;this.trigger("theme.set",{name:"theme.set",theme:a});return this.settings.theme};Chatterbox.UI.prototype.add_theme=function(a){if(this.settings.themes.indexOf(a)>-1){return}this.settings.themes.push(a)};Chatterbox.UI.prototype.developer=function(a){this.settings.developer=a;this.chatbook.developer() -};Chatterbox.BaseTab=function(f,b,d,a){this.manager=f;this.hidden=d;this.monitor=(a==undefined?false:a);this.built=false;this.raw=b;this.selector="t-"+(b||"chan").toLowerCase();this.namespace=b;this.visible=false;this.st=0;this.el={t:{o:null,l:null,c:null,},m:null,l:{p:null,w:null,},u:null,h:{title:null,topic:null}};this.mulw=0;this.d={u:[0,0],h:{title:[0,0],topic:[0,0]}};if(!f){return}this.raw=f.format_ns(b);this.selector=(this.raw.substr(0,2)=="pc"?"pc":"c")+"-"+f.deform_ns(b).slice(1).toLowerCase();this.namespace=f.deform_ns(b)};Chatterbox.BaseTab.prototype.build=function(b){if(!this.manager){return}if(this.built){return}var a=this.selector;var f=this.namespace;var d=this.raw;this.el.t.o=this.manager.nav.add_tab(a,f);this.el.t.l=this.el.t.o.find(".tab");this.el.t.c=this.el.t.o.find(".close");this.manager.chatbook.view.append(b||Chatterbox.render("basetab",{selector:a,ns:f}));this.el.m=this.window=this.manager.chatbook.view.find("#"+a+"-window");var g=this;this.el.t.l.click(function(){g.manager.toggle_channel(d); -return false});this.el.t.c.click(function(h){g.manager.trigger("tab.close.clicked",{ns:g.raw,chan:g,e:h});return false});if(this.hidden&&!this.manager.settings.developer){this.el.t.o.toggleClass("hidden")}this.built=true};Chatterbox.BaseTab.prototype.hide=function(){this.el.m.css({display:"none"});this.el.t.o.removeClass("active");this.visible=false};Chatterbox.BaseTab.prototype.show=function(){this.visible=true;this.el.m.css({display:"block"});this.el.t.o.addClass("active");this.el.t.o.removeClass("noise chatting tabbed fill");var a=this;setTimeout(function(){a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight());a.resize();a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight())},100)};Chatterbox.BaseTab.prototype.developer=function(){if(this.manager.settings.developer){this.el.t.o.removeClass("hidden");return}if(this.hidden){this.el.t.o.addClass("hidden")}};Chatterbox.BaseTab.prototype.remove=function(){this.el.t.o.remove();this.el.m.remove()};Chatterbox.BaseTab.prototype.resize=function(b,a){this.el.m.css({height:a||this.manager.chatbook.height(),width:(b||this.manager.chatbook.width())-10}) -};Chatterbox.BaseTab.prototype.loop=function(){};Chatterbox.Channel=function(f,b,d,a){Chatterbox.BaseTab.call(this,f,b,d,a);this.resized=function(){};this.ulbuf=0};Chatterbox.Channel.prototype=new Chatterbox.BaseTab;Chatterbox.Channel.prototype.constructor=Chatterbox.Channel;Chatterbox.Channel.prototype.build=function(){if(!this.manager){return}if(this.built){return}var a=this.selector;var d=this.namespace;var b=this.raw;Chatterbox.BaseTab.prototype.build.call(this,Chatterbox.render("channel",{selector:a,ns:d}));this.el.l.p=this.el.m.find("#"+a+"-log");this.el.l.w=this.el.l.p.find("ul.logwrap");this.el.u=this.el.m.find("#"+a+"-users");this.mulw=parseInt(this.el.u.css("max-width").slice(0,-2));var f=this;var g=false;this.el.l.w.click(function(){if(!g){return}f.manager.control.focus()});this.el.l.w.mousedown(function(){g=true});this.el.l.w.mousemove(function(){g=false});this.el.t.l.click(function(){f.manager.toggle_channel(b);return false});this.setup_header("title");this.setup_header("topic"); -if(this.namespace[0]=="@"){this.build_user_list({100:"Room Members"},[100])}this.built=true};Chatterbox.Channel.prototype.setup_header=function(a){var d=this;var b={};b.m=this.el.m.find("header."+a+" div");b.e=this.el.m.find("header."+a+" a[href=#edit]");b.t=this.el.m.find("header."+a+" textarea");b.s=this.el.m.find("header."+a+" a[href=#save]");b.c=this.el.m.find("header."+a+" a[href=#cancel]");this.el.h[a]=b.m;b.m.parent().mouseover(function(g){if(!b.editing){b.e.css("display","block");return}b.s.css("display","block");b.c.css("display","block")});b.m.parent().mouseout(function(g){if(!b.editing){b.e.css("display","none");return}b.s.css("display","none");b.c.css("display","none")});b.e.click(function(g){b.t.text(d.manager.client.channel(d.namespace).info[a].content);b.t.css({display:"block",width:d.el.h[a].innerWidth()-10,});d.el.h[a].css("display","none");b.e.css("display","none");b.editing=true;d.resize();return false});var f=function(){var g=b.t.val();b.t.text("");b.t.css("display","none"); -d.el.h[a].css("display","block");b.s.css("display","none");b.c.css("display","none");b.editing=false;d.resize();return g};b.s.click(function(g){var h=f();d.manager.trigger(a+".save",{ns:d.raw,value:h});b.t.text("");return false});b.c.click(function(g){f();return false})};Chatterbox.Channel.prototype.scroll=function(){this.pad();var a=this.el.l.w.prop("scrollWidth")-this.el.l.w.innerWidth();var b=this.el.l.w.prop("scrollHeight")-this.el.l.w.innerHeight();if(a>0){b+=a}if(b<0||(b-this.el.l.w.scrollTop())>100){return}this.el.l.w.scrollTop(b)};Chatterbox.Channel.prototype.pad=function(){this.el.l.w.css({"padding-top":0,height:"auto"});var b=this.el.l.w.innerHeight();var a=this.el.l.p.innerHeight()-this.el.h.topic.parent().outerHeight();var d=a-b;if(d>0){this.el.l.w.css({"padding-top":d})}else{this.el.l.w.css({"padding-top":0,height:a})}this.el.l.w.scrollTop(this.st)};Chatterbox.Channel.prototype.resize=function(h,a){Chatterbox.BaseTab.prototype.resize.call(this,h,a);var j={title:{m:this.el.m.find("header div.title"),e:this.el.m.find("header.title a[href=#edit]")},topic:{m:this.el.m.find("header div.topic"),e:this.el.m.find("header.topic a[href=#edit]")}}; -this.el.l.w.css({"padding-top":0});a=a||this.manager.chatbook.height();h=h||this.manager.chatbook.width();var d=a;var b=this.el.m.width();this.el.u.width(1);this.d.u[0]=this.el.u[0].scrollWidth+this.manager.swidth+5;if(this.d.u[0]>this.mulw){this.d.u[0]=this.mulw}this.el.u.width(this.d.u[0]);b=b-this.d.u[0];d=d-j.title.m.parent().outerHeight();this.el.l.p.css({height:d-3,width:(b-10)-this.ulbuf});this.scroll();this.d.u[1]=this.el.l.p.innerHeight();this.el.u.css({height:this.d.u[1]});for(var g in j){if(!j.hasOwnProperty(g)){continue}if(j[g].m.html().length==0){continue}var f=(j[g].m.outerHeight(true)-5)*(-1);j[g].e.css("top",f)}this.resized()};Chatterbox.Channel.prototype.loop=function(){var a=this.el.l.p.find(".logmsg");if(a.length<200){return}a.slice(0,a.length-200).remove();this.resize()};Chatterbox.Channel.prototype.log=function(b){var a=this;this.manager.cascade("log",function(d){a.log_item({html:Chatterbox.render("logmsg",{message:d.message})})},{ns:this.raw,sns:this.namespace,message:b}) -};Chatterbox.Channel.prototype.log_item=function(d){var a=new Date();var b="";if(this.manager.settings.clock){b=formatTime("{HH}:{mm}:{ss}",a)}else{b=formatTime("{hh}:{mm}:{ss} {mr}",a)}var f=this;this.manager.cascade("log_item",function(g){if(f.visible){f.st=f.el.l.w.scrollTop()}f.el.l.w.append(Chatterbox.render("logitem",g));f.manager.trigger("log_item.after",{item:f.el.l.w.find("li").last(),chan:f});if(f.visible){f.st+=f.el.l.w.find("li.logmsg").last().height();f.el.l.w.scrollTop(f.st)}f.scroll();f.noise()},{ns:this.namespace,ts:b,ms:a.getTime(),message:d.html,user:(d.user||"system").toLowerCase()})};Chatterbox.Channel.prototype.retime=function(){var a="";var b=this.el.l.w;if(this.manager.settings.clock){a="{HH}:{mm}:{ss}"}else{a="{hh}:{mm}:{ss} {mr}"}b.find("span.ts").each(function(d,f){el=b.find(f);time=new Date(parseInt(el.prop("id")));el.text(formatTime(a,time))})};Chatterbox.Channel.prototype.server_message=function(d,b){var a=this;this.manager.cascade("server_message",function(f){a.log_item({html:Chatterbox.render("servermsg",{message:f.message,info:f.info})}) -},{ns:this.namespace,message:d,info:b})};Chatterbox.Channel.prototype.clear=function(){this.el.l.p.find("li.logmsg").remove();this.el.l.p.find("li.loginfo").remove();this.el.l.w.height(0);this.resize()};Chatterbox.Channel.prototype.log_info=function(g,f){var j={ns:this.namespace,ref:g,content:f};this.manager.trigger("log_info.before",j);delete j.ns;var a=this.el.l.w.append(Chatterbox.render("loginfobox",j));this.scroll();var h=this;var d=this.el.l.w.find("li."+j.ref);d.find("a.close").click(function(b){h.el.l.w.find(this).parent().remove();h.resize();return false});this.scroll();return d};Chatterbox.Channel.prototype.log_whois=function(l){var g={avatar:'avatar',username:""+l.symbol+l.username+"",info:[],conns:[],raw:l,};for(var m in l.connections){var k=l.connections[m];var o=[];if(k.online){var a=(new Date-(k.online*1000));o.push(["online",DateStamp(a/1000)+formatTime(" [{HH}:{mm}:{ss}]",new Date(a))])}if(k.idle){o.push(["idle",timeLengthString(k.idle)]) -}if(k.agent){o.push(["agent",k.agent])}if(k.debug){o.push(["debug",k.debug])}o.push(["chatrooms",k.channels.join(" ")]);g.conns.push(o)}this.manager.trigger("log_whois.before",g);var b="";for(var m in g.conns){var j=g.conns[m];var q='

        connection '+((parseInt(m)+1).toString())+":

        ";q+="
          ";for(var p in j){q+="
        • "+j[p][0]+": "+j[p][1]+"
        • "}q+="
        ";b+=q+"
        "}var h="";for(var m in g.info){h+="
      • "+g.info[m]+"
      • "}var n=this.log_info("whois-"+l.username,Chatterbox.render("whoiswrap",{avatar:g.avatar,info:Chatterbox.render("whoisinfo",{username:g.username,info:h,connections:b})}));var f=n.find("div.avatar");var d=n.find("div.info");d.width(n.find(".whoiswrap").width()-100);f.height(n.height()-10);this.scroll()};Chatterbox.Channel.prototype.log_pc=function(f,g){contents="";for(var d in g){if(!g.hasOwnProperty(d)){continue}var b=g[d];var a="";if(b[2].length==0){a=""+(f?"default privileges":"no members")+""}else{a=b[2] -}contents+=String.format("
      • {0} {1}:
        • {2}
      • ",[b[1],b[0],a])}var h={title:"Privilege class "+(f?"permissions":"members"),info:"
          "+contents+"
        "};this.log_info("pc-"+(f?"permissions":"members"),Chatterbox.render("pcinfo",h))};Chatterbox.Channel.prototype.set_header=function(a,f,h,d){a=a.toLowerCase();var b=this.el.m.find("header."+a+" a[href=#edit]");if(this.el.h[a].html()!=""){if(f.html().length!=0){this.server_message(a+" set by "+h)}}this.el.h[a].html(f.html());var g=this;setTimeout(function(){if(f.text().length>0){g.el.h[a].css({display:"block"});var j=(g.el.h[a].outerHeight(true)-5)*(-1);b.css("top",j)}else{g.el.h[a].css({display:"none"})}g.resize()},100)};Chatterbox.Channel.prototype.get_header=function(a){return this.el.h[a.toLowerCase()]};Chatterbox.Channel.prototype.build_user_list=function(f,a){var h=this.el.u;var d="";var g=null;h.html("");for(var b in a){var d=f[a[b]];h.append('

        '+d+"

          "); -g=h.find(".pc#"+d);g.css("display","none")}};Chatterbox.Channel.prototype.reveal_user_list=function(){var g=this.el.u;var d=0;var b=0;var a=null;g.find("div.pc").each(function(h,j){a=g.find(this);b=a.find("ul li").length;d+=b;a.css("display",(b==0?"none":"block"))});g.css("display",(d==0?"none":"block"));var f=this;setTimeout(function(){f.resize()},100)};Chatterbox.Channel.prototype.set_user_list=function(f){if(Object.size(f)==0){return}var d=this.el.u;var a=null;for(var b in f){a=f[b];this.set_user(a,true)}this.reveal_user_list()};Chatterbox.Channel.prototype.set_user=function(g,d){var j=this.el.u.find("div.pc#"+replaceAll(g.pc," ","-"));var a=j.find("ul");var b=g.conn==1?"":"["+g.conn+"]";var h='
        • '+g.symbol+""+g.name+""+b+"
        • ";if(a.find("a#"+g.name).length==1){return}if(a.find("li").length==0){a.append(h)}else{var k=g.name.toLowerCase();var m=null;var f=false;a.find("li a").each(function(){if(f){return -}m=a.find(this);if(k"}h.window.append(Chatterbox.render("userinfo",{username:b.name,avatar:b.avatar,link:b.link,info:j}));f=h.window.find(".userinfo#"+b.name);h.window.find("div.userinfo:not('#"+b.name+"')").remove();var l=g.offset();f.css({top:(l.top-g.height())+10,left:(l.left-(f.width()))-6});f.find(".info").height(f.height());f.hover(function(){f.data("hover",1)},function(m){f.data("hover",0);h.unhover_user(f,m)});f.data("hover",0)};var d=function(j){g.data("hover",0);h.unhover_user(f,j)};g.off("mouseenter",a);g.off("mouseleave",d);g.on("mouseenter",a);g.on("mouseleave",d)};Chatterbox.Channel.prototype.unhover_user=function(f,d){var g=f.offset();var b=f.outerHeight(true)+g.top;var j=f.outerWidth(true)+g.left;var a=d.pageX;var h=d.pageY;if(a>g.left&&ag.top&&hg.left&&h>g.top&&h<(g.top+15)){return -}f.remove()};Chatterbox.Channel.prototype.mute_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).css({display:"none"});this.scroll()};Chatterbox.Channel.prototype.unmute_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).css({display:"list-item"});this.scroll()};Chatterbox.Channel.prototype.clear_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).remove();this.scroll()};Chatterbox.Channel.prototype.pkt_join=function(b,a){if(b.e!="ok"){return}this.set_header("title",(new wsc.MessageString("")),"","");this.set_header("topic",(new wsc.MessageString("")),"","")};Chatterbox.Channel.prototype.pkt_recv_msg=function(b,a){var d=this;this.manager.cascade("chan.recv_msg",function(h,f){var g=d.manager.client.settings.username.toLowerCase();if(g==h.user.toLowerCase()){return}var k=h.message.toLowerCase();var j=k.indexOf(g)!=-1;if(!j&&h.sns[0]!="@"){return}if(j){d.highlight()}else{d.highlight(false)}d.manager.trigger("tabbed",h) -},b)};Chatterbox.Channel.prototype.pkt_recv_action=Chatterbox.Channel.prototype.pkt_recv_msg;Chatterbox.Channel.prototype.pkt_property=function(b,a){var f=b.pkt.arg.p;var d=a.channel(this.namespace);switch(f){case"title":case"topic":this.set_header(f,b.value||(new wsc.MessageString("")),b.by,b.ts);break;case"privclasses":this.build_user_list(d.info.pc,d.info.pc_order.slice(0));break;case"members":break;default:break}};Chatterbox.Chatbook=function(a){this.manager=a;this.view=this.manager.view.find("div.chatbook");this.chan={};this.trail=[];this.current=null;this.manager.on("tab.close.clicked",function(b,d){d.chatbook.remove_channel(b.ns)})};Chatterbox.Chatbook.prototype.height=function(){return this.view.height()};Chatterbox.Chatbook.prototype.width=function(){return this.view.width()};Chatterbox.Chatbook.prototype.resize=function(b){b=b||600;var d=this.view.innerWidth();for(var a in this.chan){if(!this.chan.hasOwnProperty(a)){continue}var f=this.chan[a];f.resize(d,b)}};Chatterbox.Chatbook.prototype.loop=function(){for(select in this.chan){this.chan[select].loop() -}};Chatterbox.Chatbook.prototype.channel=function(a,b){a=this.manager.format_ns(a).toLowerCase();if(!this.chan[a]&&b){this.chan[a]=b}return this.chan[a]};Chatterbox.Chatbook.prototype.channels=function(){chans=-1;for(ns in this.chan){if(this.chan[ns].hidden){continue}chans++}return chans};Chatterbox.Chatbook.prototype.create_channel=function(b,d,a){var f=this.channel(b,this.channel_object(b,d,a));f.build();if(this.trail.indexOf(f.namespace)==-1){this.trail.push(f.namespace)}if(!f.visible){this.toggle_channel(b)}this.manager.resize();return f};Chatterbox.Chatbook.prototype.channel_object=function(a,b){return new Chatterbox.Channel(this.manager,a,b)};Chatterbox.Chatbook.prototype.toggle_channel=function(a){var d=this.channel(a);var b=d;if(!d){return}if(d.hidden){if(this.current&&this.current==d){return}if(!this.manager.settings.developer){d.hide();return}}if(this.current){if(this.current==d){return}this.current.hide();b=this.current}else{if(this.manager.monitoro!==null){this.manager.monitoro.hide() -}}d.show();this.manager.control.focus();this.current=d;this.manager.resize();this.manager.control.cache_input(b,d);this.manager.trigger("channel.selected",{ns:d.raw,chan:d,prev:b});this.manager.client.select_ns(d.raw)};Chatterbox.Chatbook.prototype.remove_channel=function(a){var b=this.channel(a);if(!b){return}if(this.channels()==0&&!b.hidden){return}b.remove();delete this.chan[b.raw.toLowerCase()];if(this.current==b){this.channel_left()}var d=this.trail.indexOf(b.namespace);this.trail.splice(d,1)};Chatterbox.Chatbook.prototype.channel_left=function(){var b=this.current.namespace;var a=this.trail.indexOf(b);if(a<0){return}var f=null;while(true){try{f=this.channel(this.trail[--a])}catch(d){a=this.trail.length-1;f=this.channel(this.trail[a])}if(!f.hidden){break}if(this.manager.settings.developer){break}}this.toggle_channel(f.namespace)};Chatterbox.Chatbook.prototype.channel_right=function(){var b=this.current.namespace;var a=this.trail.indexOf(b);if(a==-1){return}var f=null;while(true){try{f=this.channel(this.trail[++a]) -}catch(d){a=0;f=this.channel(this.trail[0])}if(!f.hidden){break}if(this.manager.settings.developer){break}}this.toggle_channel(f.namespace)};Chatterbox.Chatbook.prototype.each=function(d){var b=null;for(var a in this.chan){if(!this.chan.hasOwnProperty(a)){continue}b=this.chan[a];if(d(b.namespace,b)===false){break}}};Chatterbox.Chatbook.prototype.server_message=function(b,a){for(ns in this.chan){this.chan[ns].server_message(b,a)}};Chatterbox.Chatbook.prototype.log_item=function(a){for(ns in this.chan){this.chan[ns].log_item(a)}};Chatterbox.Chatbook.prototype.log=function(a){for(ns in this.chan){this.chan[ns].log(a)}};Chatterbox.Chatbook.prototype.log_message=function(d,b){try{if(!d.global){if(!d.monitor){this.channel(b.ns).log_item(b)}else{this.manager.monitoro.log_item(b)}}else{this.log_item(b)}}catch(a){try{this.ui.monitoro.server_message("Failed to log for",b.sns,b.html)}catch(a){console.log(">> Failed to log message for",b.sns,"::");console.log(">>",b.html)}}};Chatterbox.Chatbook.prototype.retime=function(){for(ns in this.chan){this.chan[ns].retime() -}};Chatterbox.Chatbook.prototype.developer=function(){this.each(function(a,b){b.developer()})};Chatterbox.Chatbook.prototype.handle=function(f,b){var g=this.manager;var h=this.channel(f.ns);if(!h){return}var a="pkt_"+f.name;try{h[a](f,b)}catch(d){}};Chatterbox.Control=function(b){this.manager=b;this.manager.view.append(Chatterbox.template.control);this.view=this.manager.view.find("div.chatcontrol");this.ml=false;this.history={};this.tab={hit:false,cache:"",matched:[],index:-1,type:0,prefix:["","/",""],};this.el={form:this.view.find("form.msg"),i:{s:this.view.find("form.msg input.msg"),m:this.view.find("form.msg textarea.msg"),c:null,t:this.view.find("ul.buttons a[href~=#multiline].button")},brow:{m:this.view.find("div.brow"),b:this.view.find("div.brow ul.buttons"),s:this.view.find("div.brow ul.states")}};this.el.i.c=this.el.i.s;var a=this;this.el.i.t.click(function(d){a.multiline(!a.multiline());return false});this.el.i.s.keydown(function(d){return a.keypress(d)});this.el.i.m.keydown(function(d){return a.keypress(d) -});this.el.form.submit(function(d){return a.submit(d)});this.add_button({label:"b",icon:false,href:"#bold",title:"Bold text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"i",icon:false,href:"#italic",title:"Italic text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"u",icon:false,href:"#underline",title:"Underline text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"sup",icon:false,href:"#sup",title:"Superscript",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"sub",icon:false,href:"#sub",title:"Subscript",handler:function(){a.surroundtext(a.el.i.c[0],"","")}})};Chatterbox.Control.prototype.surroundtext=function(j,h,b){var g=j.scrollTop;var a=j.value,d=j.selectionStart,f=j.selectionEnd;var k=j.value.substring(d,f);j.value=a.substring(0,d)+h+k+b+a.substring(f);j.selectionStart=d+h.length; -j.selectionEnd=d+h.length+k.length;j.scrollTop=g;j.focus()};Chatterbox.Control.prototype.focus=function(){this.el.i.c.focus()};Chatterbox.Control.prototype.resize=function(){w=this.manager.view.width();this.view.css({width:"100%"});this.el.form.css({width:this.manager.view.width()-20});this.el.i.s.css({width:this.manager.view.width()-100});this.el.i.m.css({width:this.manager.view.width()-90})};Chatterbox.Control.prototype.height=function(){var a=this.view.outerHeight();return a};Chatterbox.Control.prototype.multiline=function(a){if(a==undefined||this.ml==a){return this.ml}this.ml=a;var b=(this.ml?"s":"m");a=(this.ml?"m":"s");this.el.i[b].css("display","none");this.el.i[a].css("display","inline-block");this.el.i.c=this.el.i[a];this.manager.resize();return this.ml};Chatterbox.Control.prototype.add_button=function(a){a=Object.extend({label:"New",icon:false,href:"#button",title:"Button.",handler:function(){}},(a||{}));if(a.icon!==false){a.icon=" iconic "+a.icon}else{a.icon=" text"}this.el.brow.b.append(Chatterbox.render("brow_button",a)); -var b=this.el.brow.b.find("a[href="+a.href+"].button");b.click(function(d){a.handler();return false});return b};Chatterbox.Control.prototype.add_state=function(a){a=Object.extend({ref:"state",label:"some state"},(a||{}));var b=this.el.brow.s.find("li#"+a.ref);if(b.length==0){this.el.brow.s.append(Chatterbox.render("brow_state",a));return this.el.brow.s.find("li#"+a.ref)}b.html(a.label);return b};Chatterbox.Control.prototype.rem_state=function(a){return this.el.brow.s.find("li#"+a).remove()};Chatterbox.Control.prototype.chomp=function(){var f=this.el.i.c.val();var b=f.lastIndexOf(" ");if(b==-1){this.el.i.c.val("");return f}var a=f.slice(b+1);this.el.i.c.val(f.slice(0,b));if(a.length==0){return this.chomp()}return a};Chatterbox.Control.prototype.unchomp=function(a){var b=this.el.i.c.val();if(!b){this.el.i.c.val(a)}else{this.el.i.c.val(b+" "+a)}};Chatterbox.Control.prototype.get_text=function(a){if(a==undefined){return this.el.i.c.val()}this.el.i.c.val(a||"");return this.el.i.c.val()};Chatterbox.Control.prototype.set_text=function(a){this.el.i.c.val(a||"") -};Chatterbox.Control.prototype.cache_input=function(b,d){var a=this.get_history(b.namespace);if(a.index>-1){return}a.tmp=this.get_text();this.set_text(this.get_history(d.namespace).tmp)};Chatterbox.Control.prototype.get_history=function(a){if(!a){if(!this.manager.chatbook.current){a="~monitor"}}a=a||this.manager.chatbook.current.namespace;if(!this.history[a]){this.history[a]={index:-1,list:[],tmp:""}}return this.history[a]};Chatterbox.Control.prototype.append_history=function(b){if(!b){return}var a=this.get_history();a.list.unshift(b);a.index=-1;if(a.list.length>100){a.list.pop()}};Chatterbox.Control.prototype.scroll_history=function(a){var d=this.get_history();var b=this.get_text();if(d.index==-1){if(b){d.tmp=b}else{d.list[d.index]=b}}if(a){if(d.list.length>0&&d.index<(d.list.length-1)){d.index++}}else{if(d.index>-1){d.index--}}this.set_text(d.list[d.index]||d.tmp)};Chatterbox.Control.prototype.tab_item=function(b){if(!this.tab.hit){this.start_tab(b)}this.chomp();this.tab.index++;if(this.tab.index>=this.tab.matched.length){this.tab.index=-1 -}if(this.tab.index==-1){this.unchomp(this.tab.prefix[this.tab.type]+this.tab.cache);return}var a=this.get_text()==""?(this.tab.type==0?": ":" "):"";this.unchomp(this.tab.prefix[this.tab.type]+this.tab.matched[this.tab.index]+a)};Chatterbox.Control.prototype.start_tab=function(d){this.tab.hit=true;this.tab.index=-1;this.tab.matched=[];this.tab.type=0;var h=this.chomp();this.unchomp(h);if(h[0]=="/"||h[0]=="#"||h[0]=="@"){this.tab.type=h[0]=="/"?1:2;if(h[0]=="/"){h=h.slice(1)}}else{this.tab.type=0}this.tab.cache=h;h=h.toLowerCase();this.tab.matched=[];if(this.tab.type==0){var j=this.manager.client.channel(this.manager.chatbook.current.namespace);for(var a in j.info.members){if(a.toLowerCase().indexOf(h)==0){this.tab.matched.push(a)}}}else{if(this.tab.type==1){var g="";for(var b in this.manager.client.cmds){g=this.manager.client.cmds[b];if(g.indexOf(h)==0){this.tab.matched.push(g)}}}else{if(this.tab.type==2){var f=this;this.manager.client.each_channel(function(k,l){if(l.namespace.toLowerCase().indexOf(h)==0){f.tab.matched.push(l.namespace) -}})}}}};Chatterbox.Control.prototype.end_tab=function(a){this.tab.hit=false;this.tab.matched=[];this.tab.cache="";this.tab.index=-1};Chatterbox.Control.prototype.submit=function(a){var b=this.get_text();this.append_history(b);this.set_text("");this.handle(a,b);return false};Chatterbox.Control.prototype.keypress=function(d){var b=d.which||d.keyCode;var f=this.tab.hit;var a=false;switch(b){case 13:if(!this.multiline()){this.submit(d)}else{if(d.shiftKey){this.submit(d)}else{a=true}}break;case 38:if(!this.multiline()){this.scroll_history(true);break}a=true;break;case 40:if(!this.multiline()){this.scroll_history(false);break}a=true;break;case 9:if(d.shiftKey){this.manager.channel_right()}else{this.tab_item(d);f=false}break;case 219:if(d.ctrlKey){this.manager.channel_left()}else{a=true}break;case 221:if(d.ctrlKey){this.manager.channel_right()}else{a=true}break;default:a=true;break}if(f){this.end_tab(d)}return a};Chatterbox.Control.prototype.handle=function(b,g){if(g==""){return}if(!this.manager.chatbook.current){return -}var k=false;if(g[0]!="/"){k=true}g=(b.shiftKey?"/npmsg ":(g[0]=="/"?"":"/say "))+g;g=g.slice(1);var l=g.split(" ");var d=l.shift().toLowerCase();var j=this.manager.chatbook.current.namespace;var h=j;if(!k&&l[0]){var f=l[0][0];if((f=="#"||f=="@")&&l[0].length>1){h=this.manager.format_ns(l.shift())}}var m=l.join(" ");var a=this.manager.client.trigger("cmd."+d,{name:"cmd",cmd:d,args:m,target:h,ns:j});if(a==0){this.manager.pager.notice({ref:"cmd-fail",heading:"Command failed",content:'"'+d+'" is not a command.'},false,5000)}};Chatterbox.Navigation=function(a){this.manager=a;this.showclose=this.manager.settings.tabclose;this.settings={};this.settings.open=false;this.el={n:this.manager.view.find("nav.tabs"),tw:this.manager.view.find("nav.tabs div.tabwrap"),t:this.manager.view.find("nav.tabs #chattabs"),b:this.manager.view.find("nav.tabs #tabnav"),l:this.manager.view.find("nav.tabs #tabnav .arrow_left"),r:this.manager.view.find("nav.tabs #tabnav .arrow_right"),s:this.manager.view.find("nav.tabs #tabnav #settings-button"),}; -if(!this.showclose){if(!this.el.t.hasClass("hc")){this.el.t.addClass("hc")}}var b=this;this.el.s.click(function(g){if(b.settings.open){return false}var d={e:g,settings:new Chatterbox.Settings.Config(b.manager)};b.configure_page(d);b.manager.trigger("settings.open",d);b.manager.trigger("settings.open.ran",d);var f=d.settings.page("About");f.item("text",{ref:"about-chatterbox",wclass:"centered faint",text:'Using Chatterbox version '+Chatterbox.VERSION+" "+Chatterbox.STATE+' by ~photofroggy.'});b.settings.window=new Chatterbox.Settings(b.manager,d.settings);b.settings.window.build();b.settings.open=true;return false});this.el.l.click(function(){b.manager.channel_left();return false});this.el.r.click(function(){b.manager.channel_right();return false})};Chatterbox.Navigation.prototype.configure_page=function(b){var f=this.manager;var d=b.settings.page("Main");var g={};g.theme=replaceAll(f.settings.theme,"wsct_",""); -g.clock=f.clock();g.tc=f.nav.closer();var a=[];for(i in f.settings.themes){name=replaceAll(f.settings.themes[i],"wsct_","");a.push({value:name,title:name,selected:g.theme==name})}d.item("Form",{ref:"ui",title:"UI",hint:"Timestamp
          Choose between a 24 hour clock and a 12 hour clock.\n\nTheme
          Change the look of the client.\n\nClose Buttons
          Turn tab close buttons on/off.",fields:[["Dropdown",{ref:"theme",label:"Theme",items:a}],["Dropdown",{ref:"clock",label:"Timestamp Format",items:[{value:"24",title:"24 hour",selected:g.clock},{value:"12",title:"12 hour",selected:!g.clock}]}],["Checkbox",{ref:"tabclose",label:"Close Buttons",items:[{value:"yes",title:"On",selected:g.tc}]}],],event:{change:function(h){f.clock(h.data.clock=="24");f.theme(h.data.theme);f.nav.closer(h.data.tabclose.indexOf("yes")>-1)},save:function(h){g.clock=f.clock();g.theme=replaceAll(f.theme(),"wsct_","");g.tc=f.nav.closer();f.trigger("settings.save.ui",{clock:g.clock,tabclose:g.tc,theme:"wsct_"+g.theme}) -},close:function(h){f.clock(g.clock);f.theme(g.theme);f.nav.closer(g.tc)}}})};Chatterbox.Navigation.prototype.height=function(){var a=this.el.n.outerHeight();return a};Chatterbox.Navigation.prototype.add_button=function(a){a=Object.extend({label:"New",icon:false,href:"#button",title:"Button.",handler:function(){}},(a||{}));if(a.icon!==false){a.icon=" iconic "+a.icon}else{a.icon=" text"}this.el.b.prepend(Chatterbox.render("nav_button",a));var b=this.el.b.find("a[href="+a.href+"].button");b.click(function(d){a.handler();return false});this.resize();return b};Chatterbox.Navigation.prototype.add_tab=function(a,b){this.el.t.append(Chatterbox.render("tab",{selector:a,ns:b}));return this.el.t.find("#"+a+"-tab")};Chatterbox.Navigation.prototype.resize=function(){this.el.tw.width(this.el.n.width()-this.el.b.outerWidth()-20);if(this.settings.open){this.settings.window.resize()}};Chatterbox.Navigation.prototype.closer=function(a){if(a==undefined||a==this.showclose){return this.showclose}this.showclose=a; -if(this.showclose){if(!this.el.t.hasClass("hc")){return}this.el.t.removeClass("hc");return}if(this.el.t.hasClass("hc")){return}this.el.t.addClass("hc")};Chatterbox.Pager=function(a){this.manager=a;this.lifespan=20000;this.halflife=5000;this.el={m:null,click:null};this.sound={click:function(){},};this.notices=[];this.build()};Chatterbox.Pager.prototype.build=function(){this.el.m=this.manager.view.find("div.pager")};Chatterbox.Pager.prototype.notice=function(f,l,k,d){var h={frame:null,close:null,foot:null,b:{},options:Object.extend({ref:"notice",icon:"",heading:"Some notice",content:"Notice content goes here."},(f||{})),onclose:function(){},ondestroy:function(){}};h.options.ref+="-"+(new Date()).valueOf();h.options.content=h.options.content.split("\n").join("

          ");this.notices.push(h);this.el.m.append(Chatterbox.render("pager.notice",h.options));h.frame=this.el.m.find("#"+h.options.ref).last();h.close=h.frame.find("a.close_notice");h.foot=h.frame.find("footer.buttons");var g={};for(var a in h.options.buttons){if(!h.options.buttons.hasOwnProperty(a)){continue -}g=h.options.buttons[a];h.foot.append(Chatterbox.render("pager.button",g));h.b[a]=h.foot.find("a#"+g.ref);h.b[a].click(g.click)}var j=this;h.close.click(function(){h.onclose();j.remove_notice(h);return false});if(!l){if(!k){k=j.lifespan}setTimeout(function(){j.remove_notice(h,true)},k)}if(d!==true){this.manager.sound.click()}return h};Chatterbox.Pager.prototype.remove_notice=function(a,d){var b=this;if(this.notices.indexOf(a)==-1){return false}a.frame.fadeTo((d?this.halflife:300),0).slideUp(function(){a.frame.remove();b.notices.splice(b.notices.indexOf(a),1);a.ondestroy()});if(d){a.frame.mouseenter(function(){if(b.notices.indexOf(a)==-1){return}a.frame.stop(true);a.frame.slideDown(function(){a.frame.fadeTo(300,1);a.frame.mouseleave(function(){setTimeout(function(){b.remove_notice(a,true)},b.lifespan)})})})}};Chatterbox.Pager.prototype.find_notice=function(a){for(var b in this.notices){if(this.notices[b].options.ref==a){return this.notices[b]}}return null};Chatterbox.Popup=function(b,a){this.manager=b; -this.pview=(this.manager||{view:{find:function(){}}}).view;this.window=null;this.closeb=null;this.options=Object.extend({ref:"popup",title:"Popup",close:true,content:""},(a||{}))};Chatterbox.Popup.prototype.build=function(){var b=this.options;if(this.options.close){b.title+=''}this.pview.append(Chatterbox.render("popup",b));this.window=this.pview.find(".floater."+b.ref);if(this.options.close){this.closeb=this.window.find("a.close");var a=this;this.closeb.click(function(d){a.close();return false})}};Chatterbox.Popup.prototype.close=function(){this.window.remove()};Chatterbox.Popup.Prompt=function(b,a){a=a||{};a=Object.extend({position:[0,0],ref:"prompt",title:"Input",close:false,label:"","default":"","submit-button":"Submit",event:{submit:function(){},cancel:function(){}}},a);Chatterbox.Popup.call(this,b,a);this.data=this.options["default"]};Chatterbox.Popup.Prompt.prototype=new Chatterbox.Popup();Chatterbox.Popup.Prompt.prototype.constructor=Chatterbox.Popup.Prompt; -Chatterbox.Popup.Prompt.prototype.build=function(){this.options.content=Chatterbox.template.prompt.main;Chatterbox.Popup.prototype.build.call(this);this.window.css({left:this.options.position[0],top:this.options.position[1]});var a=this;this.window.find(".button.close").click(function(){a.options.event.cancel(a);a.close();return false});this.window.find(".button.submit").click(function(){a.data=a.window.find("input").val();a.options.event.submit(a);a.close();return false});this.window.find("form").submit(function(){a.data=a.window.find("input").val();a.options.event.submit(a);a.close();return false})};Chatterbox.Popup.ItemPicker=function(b,a){a=a||{};a=Object.extend({position:[100,60],ref:"item-picker",title:"Items",event:{select:function(d){}}},a);Chatterbox.Popup.call(this,b,a);this.pview=this.pview.find(".chatbook");this.data=this.options["default"];this.pages=[];this.cpage=null};Chatterbox.Popup.ItemPicker.prototype=new Chatterbox.Popup();Chatterbox.Popup.ItemPicker.prototype.constructor=Chatterbox.Popup.ItemPicker; -Chatterbox.Popup.ItemPicker.prototype.build=function(){this.options.content=Chatterbox.render("ip.main",{});Chatterbox.Popup.prototype.build.call(this);this.window.css({right:this.options.position[0],bottom:this.options.position[1]});this.closeb.removeClass("medium");this.pbook=this.window.find("section.pages");this.tabs=this.window.find("section.tabs ul");this.buttons=this.window.find("section.buttons");var d=this;var b=null;for(var a in this.pages){if(!this.pages.hasOwnProperty(a)){continue}b=this.pages[a];b.build();if(a==0){this.select_page(b)}}};Chatterbox.Popup.ItemPicker.prototype.refresh=function(){if(this.cpage==null){return}else{this.cpage.refresh()}};Chatterbox.Popup.ItemPicker.prototype.page=function(b,a){b=b.toLowerCase();for(var d in this.pages){if(!this.pages.hasOwnProperty(d)){continue}if(this.pages[d].name.toLowerCase()==b){return this.pages[d]}}return(a||null)};Chatterbox.Popup.ItemPicker.prototype.add_page=function(a,b){this.pages.push(new (b||Chatterbox.Popup.ItemPicker.Page)(this,a)) -};Chatterbox.Popup.ItemPicker.prototype.add_button=function(a){a=Object.extend({href:"#button",title:"Button",label:"Button"},(a||{}));this.buttons.append(Chatterbox.render("ip.button",a));return this.buttons.find("a[href="+a.href+"]")};Chatterbox.Popup.ItemPicker.prototype.select=function(a){this.options.event.select(a)};Chatterbox.Popup.ItemPicker.prototype.select_page=function(a){if(!a){return}if(this.cpage!=null){this.cpage.hide()}this.cpage=a||null;if(this.cpage!=null){this.cpage.show()}};Chatterbox.Popup.ItemPicker.Page=function(b,a){this.picker=b;this.options=Object.extend({ref:"page",href:"#page",label:"Page",title:"page",items:[],content:"No items on this page.",},(a||{}));this.name=this.options.label;this.nrefresh=true};Chatterbox.Popup.ItemPicker.Page.prototype.build=function(){this.picker.pbook.append(Chatterbox.render("ip.page",this.options));this.picker.tabs.append(Chatterbox.render("ip.tab",this.options));this.view=this.picker.pbook.find("div.page#"+this.options.ref); -this.items=this.view.find("ul");this.tab=this.picker.tabs.find("#"+this.options.ref);this.refresh();var a=this;this.tab.find("a").click(function(){a.picker.select_page(a);return false})};Chatterbox.Popup.ItemPicker.Page.prototype.refresh=function(){var a=this.build_list();if(a.length==0){this.options.content="No items on this page."}else{this.options.content="

            "+a+"
          "}this.view.html(this.options.content);this.items=this.view.find("ul");this.hook_events();this.nrefresh=false};Chatterbox.Popup.ItemPicker.Page.prototype.hook_events=function(){var a=this;this.items.find("li").each(function(b,f){var g=a.view.find(f);var d=g.find(".value").html();g.click(function(){a.picker.select(d)})})};Chatterbox.Popup.ItemPicker.Page.prototype.build_list=function(){var d=[];var f=null;var h,g,b;for(var a in this.options.items){if(!this.options.items.hasOwnProperty(a)){continue}f=this.options.items[a];g=f.value||f;h=f.title||g;b=f.html||false;d.push('
        • '+(b?g:''+g+"")+"
        • ") -}return d.join("")};Chatterbox.Popup.ItemPicker.Page.prototype.show=function(){this.tab.addClass("selected");this.view.css("display","block");this.refresh()};Chatterbox.Popup.ItemPicker.Page.prototype.hide=function(){this.tab.removeClass("selected");this.view.css("display","none")};Chatterbox.Protocol=function(){this.messages={chatserver:{keys:["version"],template:'** Connected to llama {version} *',global:true},dAmnServer:{keys:["version"],template:'** Connected to dAmnServer {version} *',global:true},login:{keys:["username","e","data"],template:'** Login as {username}: "{e}" *',global:true},join:{keys:["ns","e"],template:'** Join {ns}: "{e}" *',monitor:true},part:{keys:["ns","e","r"],template:'** Part {ns}: "{e}" * {r}',monitor:true},property:{keys:["ns","p","by","ts","value"],template:'** Got {p} for {ns} *',monitor:true},recv_msg:{keys:["user","message"],template:'<{user}>{message}'},recv_action:{keys:["s","user","message"],template:'* {user}{message}'},recv_join:{keys:["user","s","info"],template:'** {user} has joined *',},recv_part:{keys:["user","r"],template:'** {user} has left * {r}'},recv_privchg:{keys:["user","s","by","pc"],template:'** {user} has been made a member of {pc} by {by} *'},recv_kicked:{keys:["user","s","by","r"],template:'** {user} has been kicked by {by} * {r}'},recv_admin_create:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been created by {user} * {privs}'},recv_admin_update:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been updated by {user} * {privs}'},recv_admin_rename:{keys:["p","user","prev","pc"],template:'** Privilege class {prev} has been renamed to {pc} by {user} *'},recv_admin_move:{keys:["p","user","prev","pc","affected"],template:'** All members of {prev} have been moved to {pc} by {user} * {affected} affected user(s)'},recv_admin_remove:{keys:["p","user","pc","affected"],template:'** Privilege class {pc} has been removed by {user} * {affected} affected user(s)'},recv_admin_show:null,recv_admin_showverbose:null,recv_admin_privclass:{keys:["p","e","command"],template:'** Admin command "{command}" failed * {e}'},kicked:{keys:["ns","user","r"],template:'** You have been kicked by {user} * {r}'},ping:null,disconnect:{keys:["e"],template:'** You have been disconnected * {e}',global:true},send:{keys:["ns","e"],template:'** Send error: {e}'},kick:{keys:["ns","user","e"],template:'** Could not kick {user} * {e}'},get:{keys:["ns","p","e"],template:'** Could not get {p} info for {ns} * {e}'},set:{keys:["ns","p","e"],template:'** Could not set {p} * {e}'},kill:{keys:["ns","e"],template:'** Kill error * {e}'},unknown:{keys:["ns","packet"],template:'** Received unknown packet in {ns} * {packet}',monitor:true}} -};Chatterbox.Protocol.prototype.extend_messages=function(b){for(var a in b){this.messages[a]=b[a]}};Chatterbox.Protocol.prototype.log=function(b){var a=this.messages[b.name];return new Chatterbox.Protocol.LogMessage(b,a)};Chatterbox.Protocol.LogMessage=function(b,a){this.event=b;this.template=a.template||"";this.keys=a.keys||[];this.monitor=a.monitor||false;this.global=a.global||false;this._html=false;this._text=false;this._ansi=false};Chatterbox.Protocol.LogMessage.prototype.text=function(){if(this._text===false){this._text=this.render(0)}return this._text};Chatterbox.Protocol.LogMessage.prototype.html=function(){if(this._html===false){this._html=this.render(1)}return this._html};Chatterbox.Protocol.LogMessage.prototype.ansi=function(){if(this._ansi===false){this._ansi=this.render(2)}return this._ansi};Chatterbox.Protocol.LogMessage.prototype.render=function(f){if(f===undefined){f=0}var b=this.template;var g="";for(var a in this.keys){if(!this.keys.hasOwnProperty(a)){continue}key=this.keys[a]; +},{input:b,ns:a,property:d})};wsc.Client.prototype.whois=function(a){this.send(wsc_packetstr("get","login:"+a,{p:"info"}))};wsc.Client.prototype.disconnect=function(){this.send(wsc_packetstr("disconnect"))};var Chatterbox={};Chatterbox.VERSION="0.20.104";Chatterbox.STATE="beta";Chatterbox._gum=function(){};(function(a){a.fn.chatterbox=function(g,b,d){var f=a(window).data("chatterbox");if(g=="init"||f===undefined){if(f==undefined){f=new Chatterbox.UI(a(this),b,d,(a.browser.mozilla||false));a(window).resize(f.resize)}a(window).data("chatterbox",f)}if(g!="init"&&g!=undefined){g="jq_"+g;if(g in f){f[g](a(this),d)}}return f}})(jQuery);Chatterbox.UI=function(b,a,d,g,f){this.client=a;this.events=f||new EventEmitter();this.mozilla=g;this.umuted=[];this.viewing=true;this.settings={themes:["wsct_dAmn","wsct_dark"],theme:"wsct_dark",monitor:["~Monitor",true],username:"",domain:"website.com",clock:true,tabclose:true,developer:false,media:"/static/"};var h=this;this.sound={bank:{m:null},add:function(j,k){if(h.sound.hasOwnProperty(j)){return false +}h.sound.bank[j]=k;k.load();h.sound[j]=function(){h.sound.play(h.sound.bank[j])};return true},play:function(j){j.pause();j.currentTime=0;j.play()},toggle:function(k){for(var j in h.sound.bank){if(!h.sound.bank.hasOwnProperty(j)){continue}h.sound.bank[j].muted=k}},mute:function(){h.sound.toggle(true)},unmute:function(){h.sound.toggle(false)},};this.settings=b.extend(this.settings,d);b.append('
          ');this.mw=new wsc.Middleware();this.view=b.find(".wsc");this.mns=this.format_ns(this.settings.monitor[0]);this.lun=this.settings.username.toLowerCase();this.monitoro=null;this.swidth=(function(){if($.browser.msie){var l=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body"),k=$('').css({position:"absolute",top:-1000,left:-1000}).appendTo("body");scrollbarWidth=l.width()-k.width();l.add(k).remove()}else{var j=$("
          ").css({width:100,height:100,overflow:"auto",position:"absolute",top:-1000,left:-1000}).prependTo("body").append("
          ").find("div").css({width:"100%",height:200}); +scrollbarWidth=100-j.width();j.parent().remove()}return scrollbarWidth})();if(window.mozRTCPeerConnection){Chatterbox._gum=function(k,l,j){return navigator.mozGetUserMedia(k,l,j)}}if(window.webkitRTCPeerConnection){Chatterbox._gum=function(k,l,j){return navigator.webkitGetUserMedia(k,l,j)}}if(window.RTCPeerConnection&&!window.mozRTCPeerConnection){Chatterbox._gum=function(k,l,j){return navigator.getUserMedia(k,l,j)}}this.LIB="Chatterbox";this.VERSION=Chatterbox.VERSION;this.STATE=Chatterbox.STATE};wsc.defaults.UI=Chatterbox.UI;Chatterbox.UI.prototype.trigger=function(a,b){this.events.emit(a,b,this)};Chatterbox.UI.prototype.on=function(b,a){this.events.addListener(b,a)};Chatterbox.UI.prototype.middle=function(a,b){return this.mw.add(a,b)};Chatterbox.UI.prototype.cascade=function(a,d,b){this.mw.run(a,d,b)};Chatterbox.UI.prototype.remove_listeners=function(){this.events.removeListeners()};Chatterbox.UI.prototype.deform_ns=function(b){var a=b[0];if(a=="#"||a=="@"||a=="~"||a=="+"){return b}if(b.indexOf("chat:")==0){return"#"+b.slice(5) +}if(b.indexOf("server:")==0){return"~"+b.slice(7)}if(b.indexOf("feed:")==0){return"#"+b.slice(5)}if(b.indexOf("login:")==0){return"@"+b.slice(6)}if(b.indexOf("pchat:")==0){var d=b.split(":");d.shift();for(i in d){name=d[i];if(name.toLowerCase()!=this.lun){return"@"+name}}}return"#"+b};Chatterbox.UI.prototype.format_ns=function(a){var d=a.slice(1);switch(a[0]){case"@":var b=[d,this.lun];b.sort(caseInsensitiveSort);b.unshift("pchat");a=b.join(":");break;case"~":a="server:"+d;break;case"+":a="feed:"+d;break;case"#":a="chat:"+d;break;default:if(a.indexOf("chat:")==0||a.indexOf("pchat:")==0||a.indexOf("server:")==0||a.indexOf("feed:")==0){break}a="chat:"+a;break}return a};Chatterbox.UI.prototype.set_events=function(a){this.events=a||this.events};Chatterbox.UI.prototype.clock=function(a){if(a===undefined||a==this.settings.clock){return this.settings.clock}this.settings.clock=a;this.chatbook.retime();return this.settings.clock};Chatterbox.UI.prototype.get_user_media=function(b,d,a){Chatterbox._gum(b,d,a) +};Chatterbox.UI.prototype.build=function(j,a,b){this.view.append(Chatterbox.render("ui",this.settings));this.control=new (j||Chatterbox.Control)(this);this.nav=new (a||Chatterbox.Navigation)(this);this.chatbook=new (b||Chatterbox.Chatbook)(this);this.pager=new Chatterbox.Pager(this);this.monitoro=this.chatbook.create_channel(this.mns,this.settings.monitor[1],true);this.monitoro.show();this.control.focus();this.sound.bank.m=this.view.find("div.soundbank");this.sound.add("click",this.sound.bank.m.find("audio.click")[0]);var h=this.sound;var f=false;var d=this.nav.add_button({label:"",icon:"volume",href:"#mute",title:"Mute the client",handler:function(){if(!f){h.mute();d.removeClass("volume");d.addClass("volume_mute");d.prop("title","Unmute the client");f=true;return false}h.unmute();d.removeClass("volume_mute");d.addClass("volume");d.prop("title","Mute the client");f=false;return false}});var g=this;$(window).focus(function(){g.viewing=true});$(window).blur(function(){g.viewing=false});this.client.bind("pkt",function(l,k){g.packet(l,k) +});this.client.middle("ns.remove",function(l,k){g.remove_channel(l.ns);k(l)});this.client.bind("ns.create",function(l,k){g.create_channel(l.chan.raw,l.chan.hidden)});this.client.bind("ns.user.list",function(k){g.channel(k.ns).set_user_list(k.users)});this.client.middle("ns.user.privchg",function(l,k){g.channel(l.ns).privchg(l,k)});this.client.bind("ns.user.remove",function(l,k){g.channel(l.ns).remove_one_user(l.user)});this.client.bind("ns.user.registered",function(k){g.channel(k.ns).register_user(k.user)})};Chatterbox.UI.prototype.resize=function(){this.control.resize();this.view.height(this.view.parent().height());this.nav.resize();this.chatbook.resize(((this.view.parent().height()-this.nav.height())-this.control.height())-5)};Chatterbox.UI.prototype.loop=function(){this.chatbook.loop()};Chatterbox.UI.prototype.packet=function(b,a){var d=this;var f=a.protocol.log(b);if(f){if(this.settings.developer){console.log(">>>",b.sns,"|",f.text())}if(b.hasOwnProperty("s")&&b.s=="0"){this.chatbook.handle(b,a); +return}b.html=f.html();this.cascade("log_message",function(h,g){d.chatbook.log_message(h.message,h.event)},{message:f,event:b})}this.chatbook.handle(b,a)};Chatterbox.UI.prototype.create_channel=function(b,a){this.chatbook.create_channel(b,a)};Chatterbox.UI.prototype.remove_channel=function(a){this.chatbook.remove_channel(a)};Chatterbox.UI.prototype.toggle_channel=function(a){return this.chatbook.toggle_channel(a)};Chatterbox.UI.prototype.channel=function(a,b){return this.chatbook.channel(a,b)};Chatterbox.UI.prototype.channels=function(){return this.chatbook.channels()};Chatterbox.UI.prototype.channel_left=function(){this.chatbook.channel_left()};Chatterbox.UI.prototype.channel_right=function(){this.chatbook.channel_right()};Chatterbox.UI.prototype.monitor=function(b,a){this.monitoro.server_message(b,a)};Chatterbox.UI.prototype.server_message=function(b,a){this.chatbook.server_message(b,a)};Chatterbox.UI.prototype.log_item=function(a){this.chatbook.log_item(a)};Chatterbox.UI.prototype.log=function(a){this.chatbook.log(a) +};Chatterbox.UI.prototype.mute_user=function(a){if(!a){return false}a=a.toLowerCase();if(this.umuted.indexOf(a)!=-1){return false}this.umuted.push(a);this.chatbook.each(function(b,d){d.mute_user(a)});return true};Chatterbox.UI.prototype.unmute_user=function(a){if(!a){return false}a=a.toLowerCase();var b=this.umuted.indexOf(a);if(b==-1){return false}this.umuted.splice(b,1);this.chatbook.each(function(d,f){f.unmute_user(a)});return true};Chatterbox.UI.prototype.clear_user=function(a){this.chatbook.each(function(b,d){d.clear_user(a)})};Chatterbox.UI.prototype.theme=function(a){if(this.settings.theme==a){return this.settings.theme}if(this.settings.themes.indexOf(a)==-1){a="wsct_"+a;if(this.settings.themes.indexOf(a)==-1){return this.settings.theme}}this.view.removeClass(this.settings.theme).addClass(a);this.settings.theme=a;this.trigger("theme.set",{name:"theme.set",theme:a});return this.settings.theme};Chatterbox.UI.prototype.add_theme=function(a){if(this.settings.themes.indexOf(a)>-1){return +}this.settings.themes.push(a)};Chatterbox.UI.prototype.developer=function(a){this.settings.developer=a;this.chatbook.developer()};Chatterbox.BaseTab=function(f,b,d,a){this.manager=f;this.hidden=d;this.monitor=(a==undefined?false:a);this.built=false;this.raw=b;this.selector="t-"+(b||"chan").toLowerCase();this.namespace=b;this.visible=false;this.st=0;this.el={t:{o:null,l:null,c:null,},m:null,l:{p:null,w:null,},u:null,h:{title:null,topic:null}};this.mulw=0;this.d={u:[0,0],h:{title:[0,0],topic:[0,0]}};if(!f){return}this.raw=f.format_ns(b);this.selector=(this.raw.substr(0,2)=="pc"?"pc":"c")+"-"+f.deform_ns(b).slice(1).toLowerCase();this.namespace=f.deform_ns(b)};Chatterbox.BaseTab.prototype.build=function(b){if(!this.manager){return}if(this.built){return}var a=this.selector;var f=this.namespace;var d=this.raw;this.el.t.o=this.manager.nav.add_tab(a,f);this.el.t.l=this.el.t.o.find(".tab");this.el.t.c=this.el.t.o.find(".close");this.manager.chatbook.view.append(b||Chatterbox.render("basetab",{selector:a,ns:f})); +this.el.m=this.window=this.manager.chatbook.view.find("#"+a+"-window");var g=this;this.el.t.l.click(function(){g.manager.toggle_channel(d);return false});this.el.t.c.click(function(h){g.manager.trigger("tab.close.clicked",{ns:g.raw,chan:g,e:h});return false});if(this.hidden&&!this.manager.settings.developer){this.el.t.o.toggleClass("hidden")}this.built=true};Chatterbox.BaseTab.prototype.hide=function(){this.el.m.css({display:"none"});this.el.t.o.removeClass("active");this.visible=false};Chatterbox.BaseTab.prototype.show=function(){this.visible=true;this.el.m.css({display:"block"});this.el.t.o.addClass("active");this.el.t.o.removeClass("noise chatting tabbed fill");var a=this;setTimeout(function(){a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight());a.resize();a.el.l.w.scrollTop(a.el.l.w.prop("scrollHeight")-a.el.l.w.innerHeight())},100)};Chatterbox.BaseTab.prototype.developer=function(){if(this.manager.settings.developer){this.el.t.o.removeClass("hidden");return}if(this.hidden){this.el.t.o.addClass("hidden") +}};Chatterbox.BaseTab.prototype.remove=function(){this.el.t.o.remove();this.el.m.remove()};Chatterbox.BaseTab.prototype.resize=function(b,a){this.el.m.css({height:a||this.manager.chatbook.height(),width:(b||this.manager.chatbook.width())-10})};Chatterbox.BaseTab.prototype.loop=function(){};Chatterbox.Channel=function(f,b,d,a){Chatterbox.BaseTab.call(this,f,b,d,a);this.resized=function(){};this.ulbuf=0};Chatterbox.Channel.prototype=new Chatterbox.BaseTab;Chatterbox.Channel.prototype.constructor=Chatterbox.Channel;Chatterbox.Channel.prototype.build=function(){if(!this.manager){return}if(this.built){return}var a=this.selector;var d=this.namespace;var b=this.raw;Chatterbox.BaseTab.prototype.build.call(this,Chatterbox.render("channel",{selector:a,ns:d}));this.el.l.p=this.el.m.find("#"+a+"-log");this.el.l.w=this.el.l.p.find("ul.logwrap");this.el.u=this.el.m.find("#"+a+"-users");this.mulw=parseInt(this.el.u.css("max-width").slice(0,-2));var f=this;var g=false;this.el.l.w.click(function(){if(!g){return +}f.manager.control.focus()});this.el.l.w.mousedown(function(){g=true});this.el.l.w.mousemove(function(){g=false});this.el.t.l.click(function(){f.manager.toggle_channel(b);return false});this.setup_header("title");this.setup_header("topic");if(this.namespace[0]=="@"){this.build_user_list({100:"Room Members"},[100])}this.built=true};Chatterbox.Channel.prototype.setup_header=function(a){var d=this;var b={};b.m=this.el.m.find("header."+a+" div");b.e=this.el.m.find("header."+a+" a[href=#edit]");b.t=this.el.m.find("header."+a+" textarea");b.s=this.el.m.find("header."+a+" a[href=#save]");b.c=this.el.m.find("header."+a+" a[href=#cancel]");this.el.h[a]=b.m;b.m.parent().mouseover(function(g){if(!b.editing){b.e.css("display","block");return}b.s.css("display","block");b.c.css("display","block")});b.m.parent().mouseout(function(g){if(!b.editing){b.e.css("display","none");return}b.s.css("display","none");b.c.css("display","none")});b.e.click(function(g){b.t.text(d.manager.client.channel(d.namespace).info[a].content); +b.t.css({display:"block",width:d.el.h[a].innerWidth()-10,});d.el.h[a].css("display","none");b.e.css("display","none");b.editing=true;d.resize();return false});var f=function(){var g=b.t.val();b.t.text("");b.t.css("display","none");d.el.h[a].css("display","block");b.s.css("display","none");b.c.css("display","none");b.editing=false;d.resize();return g};b.s.click(function(g){var h=f();d.manager.trigger(a+".save",{ns:d.raw,value:h});b.t.text("");return false});b.c.click(function(g){f();return false})};Chatterbox.Channel.prototype.scroll=function(){this.pad();var a=this.el.l.w.prop("scrollWidth")-this.el.l.w.innerWidth();var b=this.el.l.w.prop("scrollHeight")-this.el.l.w.innerHeight();if(a>0){b+=a}if(b<0||(b-this.el.l.w.scrollTop())>100){return}this.el.l.w.scrollTop(b)};Chatterbox.Channel.prototype.pad=function(){this.el.l.w.css({"padding-top":0,height:"auto"});var b=this.el.l.w.innerHeight();var a=this.el.l.p.innerHeight()-this.el.h.topic.parent().outerHeight();var d=a-b;if(d>0){this.el.l.w.css({"padding-top":d}) +}else{this.el.l.w.css({"padding-top":0,height:a})}this.el.l.w.scrollTop(this.st)};Chatterbox.Channel.prototype.resize=function(h,a){Chatterbox.BaseTab.prototype.resize.call(this,h,a);var j={title:{m:this.el.m.find("header div.title"),e:this.el.m.find("header.title a[href=#edit]")},topic:{m:this.el.m.find("header div.topic"),e:this.el.m.find("header.topic a[href=#edit]")}};this.el.l.w.css({"padding-top":0});a=a||this.manager.chatbook.height();h=h||this.manager.chatbook.width();var d=a;var b=this.el.m.width();this.el.u.width(1);this.d.u[0]=this.el.u[0].scrollWidth+this.manager.swidth+5;if(this.d.u[0]>this.mulw){this.d.u[0]=this.mulw}this.el.u.width(this.d.u[0]);b=b-this.d.u[0];d=d-j.title.m.parent().outerHeight();this.el.l.p.css({height:d-3,width:(b-10)-this.ulbuf});this.scroll();this.d.u[1]=this.el.l.p.innerHeight();this.el.u.css({height:this.d.u[1]});for(var g in j){if(!j.hasOwnProperty(g)){continue}if(j[g].m.html().length==0){continue}var f=(j[g].m.outerHeight(true)-5)*(-1);j[g].e.css("top",f) +}this.resized()};Chatterbox.Channel.prototype.loop=function(){var a=this.el.l.p.find(".logmsg");if(a.length<200){return}a.slice(0,a.length-200).remove();this.resize()};Chatterbox.Channel.prototype.log=function(b){var a=this;this.manager.cascade("log",function(d){a.log_item({html:Chatterbox.render("logmsg",{message:d.message})})},{ns:this.raw,sns:this.namespace,message:b})};Chatterbox.Channel.prototype.log_item=function(d){var a=new Date();var b="";if(this.manager.settings.clock){b=formatTime("{HH}:{mm}:{ss}",a)}else{b=formatTime("{hh}:{mm}:{ss} {mr}",a)}var f=this;this.manager.cascade("log_item",function(g){if(f.visible){f.st=f.el.l.w.scrollTop()}f.el.l.w.append(Chatterbox.render("logitem",g));f.manager.trigger("log_item.after",{item:f.el.l.w.find("li").last(),chan:f});if(f.visible){f.st+=f.el.l.w.find("li.logmsg").last().height();f.el.l.w.scrollTop(f.st)}f.scroll();f.noise()},{ns:this.namespace,ts:b,ms:a.getTime(),message:d.html,user:(d.user||"system").toLowerCase()})};Chatterbox.Channel.prototype.retime=function(){var a=""; +var b=this.el.l.w;if(this.manager.settings.clock){a="{HH}:{mm}:{ss}"}else{a="{hh}:{mm}:{ss} {mr}"}b.find("span.ts").each(function(d,f){el=b.find(f);time=new Date(parseInt(el.prop("id")));el.text(formatTime(a,time))})};Chatterbox.Channel.prototype.server_message=function(d,b){var a=this;this.manager.cascade("server_message",function(f){a.log_item({html:Chatterbox.render("servermsg",{message:f.message,info:f.info})})},{ns:this.namespace,message:d,info:b})};Chatterbox.Channel.prototype.clear=function(){this.el.l.p.find("li.logmsg").remove();this.el.l.p.find("li.loginfo").remove();this.el.l.w.height(0);this.resize()};Chatterbox.Channel.prototype.log_info=function(g,f){var j={ns:this.namespace,ref:g,content:f};this.manager.trigger("log_info.before",j);delete j.ns;var a=this.el.l.w.append(Chatterbox.render("loginfobox",j));this.scroll();var h=this;var d=this.el.l.w.find("li."+j.ref);d.find("a.close").click(function(b){h.el.l.w.find(this).parent().remove();h.resize();return false});this.scroll(); +return d};Chatterbox.Channel.prototype.log_whois=function(l){var g={avatar:'avatar',username:""+l.symbol+l.username+"",info:[],conns:[],raw:l,};for(var m in l.connections){var k=l.connections[m];var o=[];if(k.online){var a=(new Date-(k.online*1000));o.push(["online",DateStamp(a/1000)+formatTime(" [{HH}:{mm}:{ss}]",new Date(a))])}if(k.idle){o.push(["idle",timeLengthString(k.idle)])}if(k.agent){o.push(["agent",k.agent])}if(k.debug){o.push(["debug",k.debug])}o.push(["chatrooms",k.channels.join(" ")]);g.conns.push(o)}this.manager.trigger("log_whois.before",g);var b="";for(var m in g.conns){var j=g.conns[m];var q='

          connection '+((parseInt(m)+1).toString())+":

          ";q+="
            ";for(var p in j){q+="
          • "+j[p][0]+": "+j[p][1]+"
          • "}q+="
          ";b+=q+"
          "}var h="";for(var m in g.info){h+="
        • "+g.info[m]+"
        • "}var n=this.log_info("whois-"+l.username,Chatterbox.render("whoiswrap",{avatar:g.avatar,info:Chatterbox.render("whoisinfo",{username:g.username,info:h,connections:b})})); +var f=n.find("div.avatar");var d=n.find("div.info");d.width(n.find(".whoiswrap").width()-100);f.height(n.height()-10);this.scroll()};Chatterbox.Channel.prototype.log_pc=function(f,g){contents="";for(var d in g){if(!g.hasOwnProperty(d)){continue}var b=g[d];var a="";if(b[2].length==0){a=""+(f?"default privileges":"no members")+""}else{a=b[2]}contents+=String.format("
        • {0} {1}:
          • {2}
        • ",[b[1],b[0],a])}var h={title:"Privilege class "+(f?"permissions":"members"),info:"
            "+contents+"
          "};this.log_info("pc-"+(f?"permissions":"members"),Chatterbox.render("pcinfo",h))};Chatterbox.Channel.prototype.set_header=function(a,f,h,d){a=a.toLowerCase();var b=this.el.m.find("header."+a+" a[href=#edit]");if(this.el.h[a].html()!=""){if(f.html().length!=0){this.server_message(a+" set by "+h)}}this.el.h[a].html(f.html());var g=this;setTimeout(function(){if(f.text().length>0){g.el.h[a].css({display:"block"});var j=(g.el.h[a].outerHeight(true)-5)*(-1); +b.css("top",j)}else{g.el.h[a].css({display:"none"})}g.resize()},100)};Chatterbox.Channel.prototype.get_header=function(a){return this.el.h[a.toLowerCase()]};Chatterbox.Channel.prototype.build_user_list=function(f,a){var h=this.el.u;var d="";var g=null;h.html("");for(var b in a){var d=f[a[b]];h.append('

          '+d+"

            ");g=h.find(".pc#"+d);g.css("display","none")}};Chatterbox.Channel.prototype.reveal_user_list=function(){var g=this.el.u;var d=0;var b=0;var a=null;g.find("div.pc").each(function(h,j){a=g.find(this);b=a.find("ul li").length;d+=b;a.css("display",(b==0?"none":"block"))});g.css("display",(d==0?"none":"block"));var f=this;setTimeout(function(){f.resize()},100)};Chatterbox.Channel.prototype.set_user_list=function(f){if(Object.size(f)==0){return}var d=this.el.u;var a=null;for(var b in f){a=f[b];this.set_user(a,true)}this.reveal_user_list()};Chatterbox.Channel.prototype.set_user=function(g,d){var j=this.el.u.find("div.pc#"+replaceAll(g.pc," ","-")); +var a=j.find("ul");var b=g.conn==1?"":"["+g.conn+"]";var h='
          • '+g.symbol+""+g.name+""+b+"
          • ";if(a.find("a#"+g.name).length==1){return}if(a.find("li").length==0){a.append(h)}else{var k=g.name.toLowerCase();var m=null;var f=false;a.find("li a").each(function(){if(f){return}m=a.find(this);if(k"}h.window.append(Chatterbox.render("userinfo",{username:b.name,avatar:b.avatar,link:b.link,info:j}));f=h.window.find(".userinfo#"+b.name);h.window.find("div.userinfo:not('#"+b.name+"')").remove();var l=g.offset();f.css({top:(l.top-g.height())+10,left:(l.left-(f.width()))-6});f.find(".info").height(f.height());f.hover(function(){f.data("hover",1)},function(m){f.data("hover",0);h.unhover_user(f,m)});f.data("hover",0)};var d=function(j){g.data("hover",0); +h.unhover_user(f,j)};g.off("mouseenter",a);g.off("mouseleave",d);g.on("mouseenter",a);g.on("mouseleave",d)};Chatterbox.Channel.prototype.unhover_user=function(f,d){var g=f.offset();var b=f.outerHeight(true)+g.top;var j=f.outerWidth(true)+g.left;var a=d.pageX;var h=d.pageY;if(a>g.left&&ag.top&&hg.left&&h>g.top&&h<(g.top+15)){return}f.remove()};Chatterbox.Channel.prototype.mute_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).css({display:"none"});this.scroll()};Chatterbox.Channel.prototype.unmute_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).css({display:"list-item"});this.scroll()};Chatterbox.Channel.prototype.clear_user=function(a){if(!a){return}this.el.l.w.find("li.logmsg.u-"+a.toLowerCase()).remove();this.scroll()};Chatterbox.Channel.prototype.pkt_join=function(b,a){if(b.e!="ok"){return}this.set_header("title",(new wsc.MessageString("")),"","");this.set_header("topic",(new wsc.MessageString("")),"","") +};Chatterbox.Channel.prototype.pkt_recv_msg=function(b,a){var d=this;this.manager.cascade("chan.recv_msg",function(h,f){var g=d.manager.client.settings.username.toLowerCase();if(g==h.user.toLowerCase()){return}var k=h.message.toLowerCase();var j=k.indexOf(g)!=-1;if(!j&&h.sns[0]!="@"){return}if(j){d.highlight()}else{d.highlight(false)}d.manager.trigger("tabbed",h)},b)};Chatterbox.Channel.prototype.pkt_recv_action=Chatterbox.Channel.prototype.pkt_recv_msg;Chatterbox.Channel.prototype.pkt_property=function(b,a){var f=b.pkt.arg.p;var d=a.channel(this.namespace);switch(f){case"title":case"topic":this.set_header(f,b.value||(new wsc.MessageString("")),b.by,b.ts);break;case"privclasses":this.build_user_list(d.info.pc,d.info.pc_order.slice(0));break;case"members":break;default:break}};Chatterbox.Chatbook=function(a){this.manager=a;this.view=this.manager.view.find("div.chatbook");this.chan={};this.trail=[];this.current=null;this.manager.on("tab.close.clicked",function(b,d){d.chatbook.remove_channel(b.ns) +})};Chatterbox.Chatbook.prototype.height=function(){return this.view.height()};Chatterbox.Chatbook.prototype.width=function(){return this.view.width()};Chatterbox.Chatbook.prototype.resize=function(b){b=b||600;var d=this.view.innerWidth();for(var a in this.chan){if(!this.chan.hasOwnProperty(a)){continue}var f=this.chan[a];f.resize(d,b)}};Chatterbox.Chatbook.prototype.loop=function(){for(select in this.chan){this.chan[select].loop()}};Chatterbox.Chatbook.prototype.channel=function(a,b){a=this.manager.format_ns(a).toLowerCase();if(!this.chan[a]&&b){this.chan[a]=b}return this.chan[a]};Chatterbox.Chatbook.prototype.channels=function(){chans=-1;for(ns in this.chan){if(this.chan[ns].hidden){continue}chans++}return chans};Chatterbox.Chatbook.prototype.create_channel=function(b,d,a){var f=this.channel(b,this.channel_object(b,d,a));f.build();if(this.trail.indexOf(f.namespace)==-1){this.trail.push(f.namespace)}if(!f.visible){this.toggle_channel(b)}this.manager.resize();return f};Chatterbox.Chatbook.prototype.channel_object=function(a,b){return new Chatterbox.Channel(this.manager,a,b) +};Chatterbox.Chatbook.prototype.toggle_channel=function(a){var d=this.channel(a);var b=d;if(!d){return}if(d.hidden){if(this.current&&this.current==d){return}if(!this.manager.settings.developer){d.hide();return}}if(this.current){if(this.current==d){return}this.current.hide();b=this.current}else{if(this.manager.monitoro!==null){this.manager.monitoro.hide()}}d.show();this.manager.control.focus();this.current=d;this.manager.resize();this.manager.control.cache_input(b,d);this.manager.trigger("channel.selected",{ns:d.raw,chan:d,prev:b});this.manager.client.select_ns(d.raw)};Chatterbox.Chatbook.prototype.remove_channel=function(a){var b=this.channel(a);if(!b){return}if(this.channels()==0&&!b.hidden){return}b.remove();delete this.chan[b.raw.toLowerCase()];if(this.current==b){this.channel_left()}var d=this.trail.indexOf(b.namespace);this.trail.splice(d,1)};Chatterbox.Chatbook.prototype.channel_left=function(){var b=this.current.namespace;var a=this.trail.indexOf(b);if(a<0){return}var f=null;while(true){try{f=this.channel(this.trail[--a]) +}catch(d){a=this.trail.length-1;f=this.channel(this.trail[a])}if(!f.hidden){break}if(this.manager.settings.developer){break}}this.toggle_channel(f.namespace)};Chatterbox.Chatbook.prototype.channel_right=function(){var b=this.current.namespace;var a=this.trail.indexOf(b);if(a==-1){return}var f=null;while(true){try{f=this.channel(this.trail[++a])}catch(d){a=0;f=this.channel(this.trail[0])}if(!f.hidden){break}if(this.manager.settings.developer){break}}this.toggle_channel(f.namespace)};Chatterbox.Chatbook.prototype.each=function(d){var b=null;for(var a in this.chan){if(!this.chan.hasOwnProperty(a)){continue}b=this.chan[a];if(d(b.namespace,b)===false){break}}};Chatterbox.Chatbook.prototype.server_message=function(b,a){for(ns in this.chan){this.chan[ns].server_message(b,a)}};Chatterbox.Chatbook.prototype.log_item=function(a){for(ns in this.chan){this.chan[ns].log_item(a)}};Chatterbox.Chatbook.prototype.log=function(a){for(ns in this.chan){this.chan[ns].log(a)}};Chatterbox.Chatbook.prototype.log_message=function(d,b){try{if(!d.global){if(!d.monitor){this.channel(b.ns).log_item(b) +}else{this.manager.monitoro.log_item(b)}}else{this.log_item(b)}}catch(a){try{this.ui.monitoro.server_message("Failed to log for",b.sns,b.html)}catch(a){console.log(">> Failed to log message for",b.sns,"::");console.log(">>",b.html)}}};Chatterbox.Chatbook.prototype.retime=function(){for(ns in this.chan){this.chan[ns].retime()}};Chatterbox.Chatbook.prototype.developer=function(){this.each(function(a,b){b.developer()})};Chatterbox.Chatbook.prototype.handle=function(f,b){var g=this.manager;var h=this.channel(f.ns);if(!h){return}var a="pkt_"+f.name;try{h[a](f,b)}catch(d){}};Chatterbox.Control=function(b){this.manager=b;this.manager.view.append(Chatterbox.template.control);this.view=this.manager.view.find("div.chatcontrol");this.ml=false;this.history={};this.tab={hit:false,cache:"",matched:[],index:-1,type:0,prefix:["","/",""],};this.el={form:this.view.find("form.msg"),i:{s:this.view.find("form.msg input.msg"),m:this.view.find("form.msg textarea.msg"),c:null,t:this.view.find("ul.buttons a[href~=#multiline].button")},brow:{m:this.view.find("div.brow"),b:this.view.find("div.brow ul.buttons"),s:this.view.find("div.brow ul.states")}}; +this.el.i.c=this.el.i.s;var a=this;this.el.i.t.click(function(d){a.multiline(!a.multiline());return false});this.el.i.s.keydown(function(d){return a.keypress(d)});this.el.i.m.keydown(function(d){return a.keypress(d)});this.el.form.submit(function(d){return a.submit(d)});this.add_button({label:"b",icon:false,href:"#bold",title:"Bold text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"i",icon:false,href:"#italic",title:"Italic text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"u",icon:false,href:"#underline",title:"Underline text",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"sup",icon:false,href:"#sup",title:"Superscript",handler:function(){a.surroundtext(a.el.i.c[0],"","")}});this.add_button({label:"sub",icon:false,href:"#sub",title:"Subscript",handler:function(){a.surroundtext(a.el.i.c[0],"","")}})}; +Chatterbox.Control.prototype.surroundtext=function(j,h,b){var g=j.scrollTop;var a=j.value,d=j.selectionStart,f=j.selectionEnd;var k=j.value.substring(d,f);j.value=a.substring(0,d)+h+k+b+a.substring(f);j.selectionStart=d+h.length;j.selectionEnd=d+h.length+k.length;j.scrollTop=g;j.focus()};Chatterbox.Control.prototype.focus=function(){this.el.i.c.focus()};Chatterbox.Control.prototype.resize=function(){w=this.manager.view.width();this.view.css({width:"100%"});this.el.form.css({width:this.manager.view.width()-20});this.el.i.s.css({width:this.manager.view.width()-100});this.el.i.m.css({width:this.manager.view.width()-90})};Chatterbox.Control.prototype.height=function(){var a=this.view.outerHeight();return a};Chatterbox.Control.prototype.multiline=function(a){if(a==undefined||this.ml==a){return this.ml}this.ml=a;var b=(this.ml?"s":"m");a=(this.ml?"m":"s");this.el.i[b].css("display","none");this.el.i[a].css("display","inline-block");this.el.i.c=this.el.i[a];this.manager.resize();return this.ml +};Chatterbox.Control.prototype.add_button=function(a){a=Object.extend({label:"New",icon:false,href:"#button",title:"Button.",handler:function(){}},(a||{}));if(a.icon!==false){a.icon=" iconic "+a.icon}else{a.icon=" text"}this.el.brow.b.append(Chatterbox.render("brow_button",a));var b=this.el.brow.b.find("a[href="+a.href+"].button");b.click(function(d){a.handler();return false});return b};Chatterbox.Control.prototype.add_state=function(a){a=Object.extend({ref:"state",label:"some state"},(a||{}));var b=this.el.brow.s.find("li#"+a.ref);if(b.length==0){this.el.brow.s.append(Chatterbox.render("brow_state",a));return this.el.brow.s.find("li#"+a.ref)}b.html(a.label);return b};Chatterbox.Control.prototype.rem_state=function(a){return this.el.brow.s.find("li#"+a).remove()};Chatterbox.Control.prototype.chomp=function(){var f=this.el.i.c.val();var b=f.lastIndexOf(" ");if(b==-1){this.el.i.c.val("");return f}var a=f.slice(b+1);this.el.i.c.val(f.slice(0,b));if(a.length==0){return this.chomp()}return a +};Chatterbox.Control.prototype.unchomp=function(a){var b=this.el.i.c.val();if(!b){this.el.i.c.val(a)}else{this.el.i.c.val(b+" "+a)}};Chatterbox.Control.prototype.get_text=function(a){if(a==undefined){return this.el.i.c.val()}this.el.i.c.val(a||"");return this.el.i.c.val()};Chatterbox.Control.prototype.set_text=function(a){this.el.i.c.val(a||"")};Chatterbox.Control.prototype.cache_input=function(b,d){var a=this.get_history(b.namespace);if(a.index>-1){return}a.tmp=this.get_text();this.set_text(this.get_history(d.namespace).tmp)};Chatterbox.Control.prototype.get_history=function(a){if(!a){if(!this.manager.chatbook.current){a="~monitor"}}a=a||this.manager.chatbook.current.namespace;if(!this.history[a]){this.history[a]={index:-1,list:[],tmp:""}}return this.history[a]};Chatterbox.Control.prototype.append_history=function(b){if(!b){return}var a=this.get_history();a.list.unshift(b);a.index=-1;if(a.list.length>100){a.list.pop()}};Chatterbox.Control.prototype.scroll_history=function(a){var d=this.get_history(); +var b=this.get_text();if(d.index==-1){if(b){d.tmp=b}else{d.list[d.index]=b}}if(a){if(d.list.length>0&&d.index<(d.list.length-1)){d.index++}}else{if(d.index>-1){d.index--}}this.set_text(d.list[d.index]||d.tmp)};Chatterbox.Control.prototype.tab_item=function(b){if(!this.tab.hit){this.start_tab(b)}this.chomp();this.tab.index++;if(this.tab.index>=this.tab.matched.length){this.tab.index=-1}if(this.tab.index==-1){this.unchomp(this.tab.prefix[this.tab.type]+this.tab.cache);return}var a=this.get_text()==""?(this.tab.type==0?": ":" "):"";this.unchomp(this.tab.prefix[this.tab.type]+this.tab.matched[this.tab.index]+a)};Chatterbox.Control.prototype.start_tab=function(d){this.tab.hit=true;this.tab.index=-1;this.tab.matched=[];this.tab.type=0;var h=this.chomp();this.unchomp(h);if(h[0]=="/"||h[0]=="#"||h[0]=="@"){this.tab.type=h[0]=="/"?1:2;if(h[0]=="/"){h=h.slice(1)}}else{this.tab.type=0}this.tab.cache=h;h=h.toLowerCase();this.tab.matched=[];if(this.tab.type==0){var j=this.manager.client.channel(this.manager.chatbook.current.namespace); +for(var a in j.info.members){if(a.toLowerCase().indexOf(h)==0){this.tab.matched.push(a)}}}else{if(this.tab.type==1){var g="";for(var b in this.manager.client.cmds){g=this.manager.client.cmds[b];if(g.indexOf(h)==0){this.tab.matched.push(g)}}}else{if(this.tab.type==2){var f=this;this.manager.client.each_channel(function(k,l){if(l.namespace.toLowerCase().indexOf(h)==0){f.tab.matched.push(l.namespace)}})}}}};Chatterbox.Control.prototype.end_tab=function(a){this.tab.hit=false;this.tab.matched=[];this.tab.cache="";this.tab.index=-1};Chatterbox.Control.prototype.submit=function(a){var b=this.get_text();this.append_history(b);this.set_text("");this.handle(a,b);return false};Chatterbox.Control.prototype.keypress=function(d){var b=d.which||d.keyCode;var f=this.tab.hit;var a=false;switch(b){case 13:if(!this.multiline()){this.submit(d)}else{if(d.shiftKey){this.submit(d)}else{a=true}}break;case 38:if(!this.multiline()){this.scroll_history(true);break}a=true;break;case 40:if(!this.multiline()){this.scroll_history(false); +break}a=true;break;case 9:if(d.shiftKey){this.manager.channel_right()}else{this.tab_item(d);f=false}break;case 219:if(d.ctrlKey){this.manager.channel_left()}else{a=true}break;case 221:if(d.ctrlKey){this.manager.channel_right()}else{a=true}break;default:a=true;break}if(f){this.end_tab(d)}return a};Chatterbox.Control.prototype.handle=function(b,g){if(g==""){return}if(!this.manager.chatbook.current){return}var k=false;if(g[0]!="/"){k=true}g=(b.shiftKey?"/npmsg ":(g[0]=="/"?"":"/say "))+g;g=g.slice(1);var l=g.split(" ");var d=l.shift().toLowerCase();var j=this.manager.chatbook.current.namespace;var h=j;if(!k&&l[0]){var f=l[0][0];if((f=="#"||f=="@")&&l[0].length>1){h=this.manager.format_ns(l.shift())}}var m=l.join(" ");var a=this.manager.client.trigger("cmd."+d,{name:"cmd",cmd:d,args:m,target:h,ns:j});if(a==0){this.manager.pager.notice({ref:"cmd-fail",heading:"Command failed",content:'"'+d+'" is not a command.'},false,5000)}};Chatterbox.Navigation=function(a){this.manager=a;this.showclose=this.manager.settings.tabclose; +this.settings={};this.settings.open=false;this.el={n:this.manager.view.find("nav.tabs"),tw:this.manager.view.find("nav.tabs div.tabwrap"),t:this.manager.view.find("nav.tabs #chattabs"),b:this.manager.view.find("nav.tabs #tabnav"),l:this.manager.view.find("nav.tabs #tabnav .arrow_left"),r:this.manager.view.find("nav.tabs #tabnav .arrow_right"),s:this.manager.view.find("nav.tabs #tabnav #settings-button"),};if(!this.showclose){if(!this.el.t.hasClass("hc")){this.el.t.addClass("hc")}}var b=this;this.el.s.click(function(g){if(b.settings.open){return false}var d={e:g,settings:new Chatterbox.Settings.Config(b.manager)};b.configure_page(d);b.manager.trigger("settings.open",d);b.manager.trigger("settings.open.ran",d);var f=d.settings.page("About");f.item("text",{ref:"about-chatterbox",wclass:"centered faint",text:'Using Chatterbox version '+Chatterbox.VERSION+" "+Chatterbox.STATE+' by ~photofroggy.'}); +b.settings.window=new Chatterbox.Settings(b.manager,d.settings);b.settings.window.build();b.settings.open=true;return false});this.el.l.click(function(){b.manager.channel_left();return false});this.el.r.click(function(){b.manager.channel_right();return false})};Chatterbox.Navigation.prototype.configure_page=function(b){var f=this.manager;var d=b.settings.page("Main");var g={};g.theme=replaceAll(f.settings.theme,"wsct_","");g.clock=f.clock();g.tc=f.nav.closer();var a=[];for(i in f.settings.themes){name=replaceAll(f.settings.themes[i],"wsct_","");a.push({value:name,title:name,selected:g.theme==name})}d.item("Form",{ref:"ui",title:"UI",hint:"Timestamp
            Choose between a 24 hour clock and a 12 hour clock.\n\nTheme
            Change the look of the client.\n\nClose Buttons
            Turn tab close buttons on/off.",fields:[["Dropdown",{ref:"theme",label:"Theme",items:a}],["Dropdown",{ref:"clock",label:"Timestamp Format",items:[{value:"24",title:"24 hour",selected:g.clock},{value:"12",title:"12 hour",selected:!g.clock}]}],["Checkbox",{ref:"tabclose",label:"Close Buttons",items:[{value:"yes",title:"On",selected:g.tc}]}],],event:{change:function(h){f.clock(h.data.clock=="24"); +f.theme(h.data.theme);f.nav.closer(h.data.tabclose.indexOf("yes")>-1)},save:function(h){g.clock=f.clock();g.theme=replaceAll(f.theme(),"wsct_","");g.tc=f.nav.closer();f.trigger("settings.save.ui",{clock:g.clock,tabclose:g.tc,theme:"wsct_"+g.theme})},close:function(h){f.clock(g.clock);f.theme(g.theme);f.nav.closer(g.tc)}}})};Chatterbox.Navigation.prototype.height=function(){var a=this.el.n.outerHeight();return a};Chatterbox.Navigation.prototype.add_button=function(a){a=Object.extend({label:"New",icon:false,href:"#button",title:"Button.",handler:function(){}},(a||{}));if(a.icon!==false){a.icon=" iconic "+a.icon}else{a.icon=" text"}this.el.b.prepend(Chatterbox.render("nav_button",a));var b=this.el.b.find("a[href="+a.href+"].button");b.click(function(d){a.handler();return false});this.resize();return b};Chatterbox.Navigation.prototype.add_tab=function(a,b){this.el.t.append(Chatterbox.render("tab",{selector:a,ns:b}));return this.el.t.find("#"+a+"-tab")};Chatterbox.Navigation.prototype.resize=function(){this.el.tw.width(this.el.n.width()-this.el.b.outerWidth()-20); +if(this.settings.open){this.settings.window.resize()}};Chatterbox.Navigation.prototype.closer=function(a){if(a==undefined||a==this.showclose){return this.showclose}this.showclose=a;if(this.showclose){if(!this.el.t.hasClass("hc")){return}this.el.t.removeClass("hc");return}if(this.el.t.hasClass("hc")){return}this.el.t.addClass("hc")};Chatterbox.Pager=function(a){this.manager=a;this.lifespan=20000;this.halflife=5000;this.el={m:null,click:null};this.sound={click:function(){},};this.notices=[];this.build()};Chatterbox.Pager.prototype.build=function(){this.el.m=this.manager.view.find("div.pager")};Chatterbox.Pager.prototype.notice=function(f,l,k,d){var h={frame:null,close:null,foot:null,b:{},options:Object.extend({ref:"notice",icon:"",heading:"Some notice",content:"Notice content goes here."},(f||{})),onclose:function(){},ondestroy:function(){}};h.options.ref+="-"+(new Date()).valueOf();h.options.content=h.options.content.split("\n").join("

            ");this.notices.push(h);this.el.m.append(Chatterbox.render("pager.notice",h.options)); +h.frame=this.el.m.find("#"+h.options.ref).last();h.close=h.frame.find("a.close_notice");h.foot=h.frame.find("footer.buttons");var g={};for(var a in h.options.buttons){if(!h.options.buttons.hasOwnProperty(a)){continue}g=h.options.buttons[a];h.foot.append(Chatterbox.render("pager.button",g));h.b[a]=h.foot.find("a#"+g.ref);h.b[a].click(g.click)}var j=this;h.close.click(function(){h.onclose();j.remove_notice(h);return false});if(!l){if(!k){k=j.lifespan}setTimeout(function(){j.remove_notice(h,true)},k)}if(d!==true){this.manager.sound.click()}return h};Chatterbox.Pager.prototype.remove_notice=function(a,d){var b=this;if(this.notices.indexOf(a)==-1){return false}a.frame.fadeTo((d?this.halflife:300),0).slideUp(function(){a.frame.remove();b.notices.splice(b.notices.indexOf(a),1);a.ondestroy()});if(d){a.frame.mouseenter(function(){if(b.notices.indexOf(a)==-1){return}a.frame.stop(true);a.frame.slideDown(function(){a.frame.fadeTo(300,1);a.frame.mouseleave(function(){setTimeout(function(){b.remove_notice(a,true) +},b.lifespan)})})})}};Chatterbox.Pager.prototype.find_notice=function(a){for(var b in this.notices){if(this.notices[b].options.ref==a){return this.notices[b]}}return null};Chatterbox.Popup=function(b,a){this.manager=b;this.pview=(this.manager||{view:{find:function(){}}}).view;this.window=null;this.closeb=null;this.options=Object.extend({ref:"popup",title:"Popup",close:true,content:""},(a||{}))};Chatterbox.Popup.prototype.build=function(){var b=this.options;if(this.options.close){b.title+=''}this.pview.append(Chatterbox.render("popup",b));this.window=this.pview.find(".floater."+b.ref);if(this.options.close){this.closeb=this.window.find("a.close");var a=this;this.closeb.click(function(d){a.close();return false})}};Chatterbox.Popup.prototype.close=function(){this.window.remove()};Chatterbox.Popup.Prompt=function(b,a){a=a||{};a=Object.extend({position:[0,0],ref:"prompt",title:"Input",close:false,label:"","default":"","submit-button":"Submit",event:{submit:function(){},cancel:function(){}}},a); +Chatterbox.Popup.call(this,b,a);this.data=this.options["default"]};Chatterbox.Popup.Prompt.prototype=new Chatterbox.Popup();Chatterbox.Popup.Prompt.prototype.constructor=Chatterbox.Popup.Prompt;Chatterbox.Popup.Prompt.prototype.build=function(){this.options.content=Chatterbox.template.prompt.main;Chatterbox.Popup.prototype.build.call(this);this.window.css({left:this.options.position[0],top:this.options.position[1]});var a=this;this.window.find(".button.close").click(function(){a.options.event.cancel(a);a.close();return false});this.window.find(".button.submit").click(function(){a.data=a.window.find("input").val();a.options.event.submit(a);a.close();return false});this.window.find("form").submit(function(){a.data=a.window.find("input").val();a.options.event.submit(a);a.close();return false})};Chatterbox.Popup.ItemPicker=function(b,a){a=a||{};a=Object.extend({position:[100,60],ref:"item-picker",title:"Items",event:{select:function(d){}}},a);Chatterbox.Popup.call(this,b,a);this.pview=this.pview.find(".chatbook"); +this.data=this.options["default"];this.pages=[];this.cpage=null};Chatterbox.Popup.ItemPicker.prototype=new Chatterbox.Popup();Chatterbox.Popup.ItemPicker.prototype.constructor=Chatterbox.Popup.ItemPicker;Chatterbox.Popup.ItemPicker.prototype.build=function(){this.options.content=Chatterbox.render("ip.main",{});Chatterbox.Popup.prototype.build.call(this);this.window.css({right:this.options.position[0],bottom:this.options.position[1]});this.closeb.removeClass("medium");this.pbook=this.window.find("section.pages");this.tabs=this.window.find("section.tabs ul");this.buttons=this.window.find("section.buttons");var d=this;var b=null;for(var a in this.pages){if(!this.pages.hasOwnProperty(a)){continue}b=this.pages[a];b.build();if(a==0){this.select_page(b)}}};Chatterbox.Popup.ItemPicker.prototype.refresh=function(){if(this.cpage==null){return}else{this.cpage.refresh()}};Chatterbox.Popup.ItemPicker.prototype.page=function(b,a){b=b.toLowerCase();for(var d in this.pages){if(!this.pages.hasOwnProperty(d)){continue +}if(this.pages[d].name.toLowerCase()==b){return this.pages[d]}}return(a||null)};Chatterbox.Popup.ItemPicker.prototype.add_page=function(a,b){this.pages.push(new (b||Chatterbox.Popup.ItemPicker.Page)(this,a))};Chatterbox.Popup.ItemPicker.prototype.add_button=function(a){a=Object.extend({href:"#button",title:"Button",label:"Button"},(a||{}));this.buttons.append(Chatterbox.render("ip.button",a));return this.buttons.find("a[href="+a.href+"]")};Chatterbox.Popup.ItemPicker.prototype.select=function(a){this.options.event.select(a)};Chatterbox.Popup.ItemPicker.prototype.select_page=function(a){if(!a){return}if(this.cpage!=null){this.cpage.hide()}this.cpage=a||null;if(this.cpage!=null){this.cpage.show()}};Chatterbox.Popup.ItemPicker.Page=function(b,a){this.picker=b;this.options=Object.extend({ref:"page",href:"#page",label:"Page",title:"page",items:[],content:"No items on this page.",},(a||{}));this.name=this.options.label;this.nrefresh=true};Chatterbox.Popup.ItemPicker.Page.prototype.build=function(){this.picker.pbook.append(Chatterbox.render("ip.page",this.options)); +this.picker.tabs.append(Chatterbox.render("ip.tab",this.options));this.view=this.picker.pbook.find("div.page#"+this.options.ref);this.items=this.view.find("ul");this.tab=this.picker.tabs.find("#"+this.options.ref);this.refresh();var a=this;this.tab.find("a").click(function(){a.picker.select_page(a);return false})};Chatterbox.Popup.ItemPicker.Page.prototype.refresh=function(){var a=this.build_list();if(a.length==0){this.options.content="No items on this page."}else{this.options.content="

              "+a+"
            "}this.view.html(this.options.content);this.items=this.view.find("ul");this.hook_events();this.nrefresh=false};Chatterbox.Popup.ItemPicker.Page.prototype.hook_events=function(){var a=this;this.items.find("li").each(function(b,f){var g=a.view.find(f);var d=g.find(".value").html();g.click(function(){a.picker.select(d)})})};Chatterbox.Popup.ItemPicker.Page.prototype.build_list=function(){var d=[];var f=null;var h,g,b;for(var a in this.options.items){if(!this.options.items.hasOwnProperty(a)){continue +}f=this.options.items[a];g=f.value||f;h=f.title||g;b=f.html||false;d.push('
          • '+(b?g:''+g+"")+"
          • ")}return d.join("")};Chatterbox.Popup.ItemPicker.Page.prototype.show=function(){this.tab.addClass("selected");this.view.css("display","block");this.refresh()};Chatterbox.Popup.ItemPicker.Page.prototype.hide=function(){this.tab.removeClass("selected");this.view.css("display","none")};Chatterbox.Protocol=function(){this.messages={chatserver:{keys:["version"],template:'** Connected to llama {version} *',global:true},dAmnServer:{keys:["version"],template:'** Connected to dAmnServer {version} *',global:true},login:{keys:["username","e","data"],template:'** Login as {username}: "{e}" *',global:true},join:{keys:["ns","e"],template:'** Join {ns}: "{e}" *',monitor:true},part:{keys:["ns","e","r"],template:'** Part {ns}: "{e}" * {r}',monitor:true},property:{keys:["ns","p","by","ts","value"],template:'** Got {p} for {ns} *',monitor:true},recv_msg:{keys:["user","message"],template:'<{user}>{message}'},recv_action:{keys:["s","user","message"],template:'* {user}{message}'},recv_join:{keys:["user","s","info"],template:'** {user} has joined *',},recv_part:{keys:["user","r"],template:'** {user} has left * {r}'},recv_privchg:{keys:["user","s","by","pc"],template:'** {user} has been made a member of {pc} by {by} *'},recv_kicked:{keys:["user","s","by","r"],template:'** {user} has been kicked by {by} * {r}'},recv_admin_create:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been created by {user} * {privs}'},recv_admin_update:{keys:["p","user","pc","privs"],template:'** Privilege class {pc} has been updated by {user} * {privs}'},recv_admin_rename:{keys:["p","user","prev","pc"],template:'** Privilege class {prev} has been renamed to {pc} by {user} *'},recv_admin_move:{keys:["p","user","prev","pc","affected"],template:'** All members of {prev} have been moved to {pc} by {user} * {affected} affected user(s)'},recv_admin_remove:{keys:["p","user","pc","affected"],template:'** Privilege class {pc} has been removed by {user} * {affected} affected user(s)'},recv_admin_show:null,recv_admin_showverbose:null,recv_admin_privclass:{keys:["p","e","command"],template:'** Admin command "{command}" failed * {e}'},kicked:{keys:["ns","user","r"],template:'** You have been kicked by {user} * {r}'},ping:null,disconnect:{keys:["e"],template:'** You have been disconnected * {e}',global:true},send:{keys:["ns","e"],template:'** Send error: {e}'},kick:{keys:["ns","user","e"],template:'** Could not kick {user} * {e}'},get:{keys:["ns","p","e"],template:'** Could not get {p} info for {ns} * {e}'},set:{keys:["ns","p","e"],template:'** Could not set {p} * {e}'},kill:{keys:["ns","e"],template:'** Kill error * {e}'},unknown:{keys:["ns","packet"],template:'** Received unknown packet in {ns} * {packet}',monitor:true}} +};Chatterbox.Protocol.prototype.extend_messages=function(b){for(var a in b){this.messages[a]=b[a]}};Chatterbox.Protocol.prototype.log=function(b){var a=this.messages[b.name];return new Chatterbox.Protocol.LogMessage(b,a)};Chatterbox.Protocol.LogMessage=function(b,a){a=a||{};this.event=b;this.template=a.template||"";this.keys=a.keys||[];this.monitor=a.monitor||false;this.global=a.global||false;this._html=false;this._text=false;this._ansi=false};Chatterbox.Protocol.LogMessage.prototype.text=function(){if(this._text===false){this._text=this.render(0)}return this._text};Chatterbox.Protocol.LogMessage.prototype.html=function(){if(this._html===false){this._html=this.render(1)}return this._html};Chatterbox.Protocol.LogMessage.prototype.ansi=function(){if(this._ansi===false){this._ansi=this.render(2)}return this._ansi};Chatterbox.Protocol.LogMessage.prototype.render=function(f){if(f===undefined){f=0}var b=this.template;var g="";for(var a in this.keys){if(!this.keys.hasOwnProperty(a)){continue}key=this.keys[a]; if(key instanceof Array){key=key[1]}if(!this.event.hasOwnProperty(key)||key=="pkt"){continue}g=this.event[key];if(g==null){continue}if(key=="ns"||key=="sns"){key="ns";g=this.event.sns}if(g.hasOwnProperty("_parser")){switch(f){case 1:g=g.html();break;case 2:g=g.ansi();break;case 0:default:g=g.text();break}}b=replaceAll(b,"{"+key+"}",g)}return b};Chatterbox.Settings=function(b,a){Chatterbox.Popup.call(this,b,{ref:"settings",title:"Settings",close:false,content:""});this.config=a;this.saveb=null;this.scb=null;this.tabs=null;this.book=null;this.changed=false;this.manager=b};Chatterbox.Settings.prototype=new Chatterbox.Popup();Chatterbox.Settings.prototype.constructor=Chatterbox.Settings;Chatterbox.Settings.prototype.build=function(){this.options.content=Chatterbox.template.settings.main;Chatterbox.Popup.prototype.build.call(this);this.saveb=this.window.find("a.button.save");this.closeb=this.window.find("a.close");this.scb=this.window.find("a.button.saveclose");this.tabs=this.window.find("nav.tabs ul.tabs"); this.book=this.window.find("div.book");this.config.build(this.manager,this);this.window.find("ul.tabs li").first().addClass("active");this.window.find("div.book div.page").first().addClass("active");var a=this;this.window.find("form").bind("change",function(){a.changed=true});this.config.each_page(function(b,d){d.each_item(function(f,g){g._onchange=function(h){a.changed=true}})});this.saveb.click(function(b){a.save();return false});this.closeb.click(function(b){if(a.changed){if(!confirm("Are you sure? You will lose any unsaved changes.")){return false}}a.close();return false});this.scb.click(function(b){a.save();a.close();return false});this.resize()};Chatterbox.Settings.prototype.resize=function(){var a=this.window.find(".inner");var d=a.find("h2");var f=a.find(".bookwrap");var b=a.find("footer");f.height(a.height()-b.outerHeight()-d.outerHeight()-15);this.book.height(f.innerHeight()-this.tabs.outerHeight()-25);this.book.width(f.innerWidth()-20);this.config.resize()};Chatterbox.Settings.prototype.switch_page=function(b){var d=this.tabs.find("li.active").first(); var a=d.prop("id").split("-",1)[0];d=this.config.page(a.split("_").join(" "));d.hide();b.show()};Chatterbox.Settings.prototype.save=function(){this.config.save(this);this.changed=false;this.manager.trigger("settings.save",{config:this.config})};Chatterbox.Settings.prototype.close=function(){this.window.remove();this.manager.nav.settings.open=false;this.manager.nav.settings.window=null;this.config.close(this);this.manager.trigger("settings.close",{config:this.config})};Chatterbox.Settings.Config=function(a){this.manager=a||null;this.pages=[]};Chatterbox.Settings.Config.prototype.find_page=function(b){var f=b.toLowerCase();var d;for(var a in this.pages){d=this.pages[a];if(d.lname==f){return d}}return null};Chatterbox.Settings.Config.prototype.build=function(d,b){d=d||this.manager;for(var a in this.pages){this.pages[a].build(d,b)}};Chatterbox.Settings.Config.prototype.resize=function(){for(var a in this.pages){this.pages[a].resize()}};Chatterbox.Settings.Config.prototype.page=function(b,a){var d=this.find_page(b); diff --git a/src/ui/base.js b/src/ui/base.js index 9c6bb51..487da5e 100644 --- a/src/ui/base.js +++ b/src/ui/base.js @@ -10,6 +10,35 @@ Chatterbox.STATE = 'beta'; Chatterbox._gum = function( ) {}; + +// jQuery hook. + +( function( $ ) { + $.fn.chatterbox = function( method, client, options ) { + + var ui = $(window).data('chatterbox'); + + if( method == 'init' || ui === undefined ) { + if( ui == undefined ) { + ui = new Chatterbox.UI( $(this), client, options, ($.browser.mozilla || false) ); + $(window).resize(ui.resize); + } + $(window).data('chatterbox', ui); + } + + if( method != 'init' && method != undefined ) { + method = 'jq_' + method; + if( method in ui ) + ui[method]( $(this), options); + } + + return ui; + + }; + +} )( jQuery ); + + /** * This object is the platform for the wsc UI. Everything can be used and * loaded from here. @@ -22,7 +51,7 @@ Chatterbox._gum = function( ) {}; * @param mozilla {Boolean} Is the browser in use made by Mozilla? * @param [events] {Object} EventEmitter object. **/ -Chatterbox.UI = function( client, view, options, mozilla, events ) { +Chatterbox.UI = function( view, client, options, mozilla, events ) { this.client = client; this.events = events || new EventEmitter(); diff --git a/src/ui/protocol.js b/src/ui/protocol.js index e65e68c..e4e3387 100644 --- a/src/ui/protocol.js +++ b/src/ui/protocol.js @@ -1,5 +1,9 @@ /** - * Parser for dAmn-like protocols. + * Rendering for dAmn-like protocols. + * + * This object is mainly used for constructing LogMessage objects with the + * right data. Seemed to make more sense than having multiple definitions of + * LogMessage and/or if...else/switch...case blocks. * * @class Chatterbox.Protocol * @constructor @@ -220,6 +224,8 @@ Chatterbox.Protocol.prototype.log = function( event ) { */ Chatterbox.Protocol.LogMessage = function( event, options ) { + options = options || {}; + this.event = event; this.template = options.template || ''; this.keys = options.keys || [];