From: Darren Date: Thu, 13 Sep 2012 23:33:59 +0000 (+0100) Subject: Server port/ssl/password options X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0f3d4221accab021b93f89b57d86905229fb956d;p=KiwiIRC.git Server port/ssl/password options --- diff --git a/client_backbone/dev/model_application.js b/client_backbone/dev/model_application.js index 0739de6..b97fcd8 100644 --- a/client_backbone/dev/model_application.js +++ b/client_backbone/dev/model_application.js @@ -52,7 +52,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { } kiwi.gateway.set('kiwi_server', that.kiwi_server + '/kiwi'); kiwi.gateway.set('nick', event.nick); - kiwi.gateway.connect(event.server, 6667, false, false, function () {}); + + kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function () {}); }); }); @@ -105,9 +106,11 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { // Populate the server select box with defaults this.panels.server.server_login.populateFields({ - 'nick': getQueryVariable('nick') || 'kiwi_' + Math.ceil(Math.random() * 10000).toString(), - 'server': getQueryVariable('server') || 'irc.kiwiirc.com', - 'channel': window.location.hash || '#test' + nick: getQueryVariable('nick') || 'kiwi_' + Math.ceil(Math.random() * 10000).toString(), + server: getQueryVariable('server') || 'irc.kiwiirc.com', + port: 6667, + ssl: false, + channel: window.location.hash || '#test' }); }; diff --git a/client_backbone/dev/model_gateway.js b/client_backbone/dev/model_gateway.js index 98335a7..31863e8 100644 --- a/client_backbone/dev/model_gateway.js +++ b/client_backbone/dev/model_gateway.js @@ -93,7 +93,6 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () { this.socket.on('connect', function () { this.emit('irc connect', that.get('nick'), host, port, ssl, password, callback); that.trigger('connect', {}); - console.log("kiwi.gateway.socket.on('connect')"); }); this.socket.on('too_many_connections', function () { diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index a363d1d..f9b7a96 100644 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -79,6 +79,9 @@ kiwi.view.ServerSelect = Backbone.View.extend({ var values = { nick: $('.nick', this.$el).val(), server: $('.server', this.$el).val(), + port: $('.port', this.$el).val(), + ssl: $('.ssl', this.$el).prop('checked'), + password: $('.password', this.$el).val(), channel: $('.channel', this.$el).val() }; @@ -97,10 +100,16 @@ kiwi.view.ServerSelect = Backbone.View.extend({ nick = defaults.nick || ''; server = defaults.server || ''; + port = defaults.port || 6667; + ssl = defaults.ssl || 0; + password = defaults.password || ''; channel = defaults.channel || ''; $('.nick', this.$el).val(nick); $('.server', this.$el).val(server); + $('.port', this.$el).val(port); + $('.ssl', this.$el).prop('checked', ssl); + $('.password', this.$el).val(password); $('.channel', this.$el).val(channel); }, diff --git a/client_backbone/index.html b/client_backbone/index.html index e2fc0b5..b2d2ec1 100644 --- a/client_backbone/index.html +++ b/client_backbone/index.html @@ -59,6 +59,13 @@

+
+ +
+ +
+ + diff --git a/client_backbone/kiwi.js b/client_backbone/kiwi.js index f296ebf..d27609a 100644 --- a/client_backbone/kiwi.js +++ b/client_backbone/kiwi.js @@ -7,7 +7,26 @@ var kiwi = window.kiwi = {}; kiwi.model = {}; -kiwi.view = {}; +kiwi.view = {}; + + +/** + * A global container for third party access + * Will be used to access a limited subset of kiwi functionality + * and data + */ +if (typeof global === 'undefined') { + global = {}; +} + +global.kiwi = { + gateway: undefined, + user: undefined, + server: undefined, + channels: undefined, + + utils: undefined // Re-usable methods +}; kiwi.model.Application = Backbone.Model.extend(new (function () { @@ -19,6 +38,12 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { /** Instance of kiwi.model.PanelList */ this.panels = null; + /** kiwi.view.Application */ + this.view; + + /** kiwi.view.StatusMessage */ + this.message; + /* Address for the kiwi server */ this.kiwi_server = null; @@ -58,7 +83,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { } kiwi.gateway.set('kiwi_server', that.kiwi_server + '/kiwi'); kiwi.gateway.set('nick', event.nick); - kiwi.gateway.connect(event.server, 6667, false, false, function () {}); + + kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function () {}); }); }); @@ -101,6 +127,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { this.topicbar = new kiwi.view.TopicBar({el: $('#topic')[0]}); + this.message = new kiwi.view.StatusMessage({el: $('#status_message')[0]}); + this.panels.server.view.show(); @@ -109,9 +137,11 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { // Populate the server select box with defaults this.panels.server.server_login.populateFields({ - 'nick': getQueryVariable('nick') || 'kiwi_' + Math.ceil(Math.random() * 10000).toString(), - 'server': getQueryVariable('server') || 'irc.kiwiirc.com', - 'channel': window.location.hash || '#test' + nick: getQueryVariable('nick') || 'kiwi_' + Math.ceil(Math.random() * 10000).toString(), + server: getQueryVariable('server') || 'irc.kiwiirc.com', + port: 6667, + ssl: false, + channel: window.location.hash || '#test' }); }; @@ -132,6 +162,25 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { }); + (function () { + var gw_stat = 0; + + gw.on('disconnect', function (event) { + that.message.text('You have been disconnected. Attempting to reconnect..'); + gw_stat = 1; + }); + gw.on('reconnecting', function (event) { + that.message.text('You have been disconnected. Attempting to reconnect again in ' + (event.delay/1000) + ' seconds..'); + }); + gw.on('connect', function (event) { + if (gw_stat !== 1) return; + + that.message.text('It\'s OK, you\'re connected again :)', {timeout: 5000}); + gw_stat = 0; + }); + })(); + + gw.on('onjoin', function (event) { var c, members, user; c = that.panels.getByName(event.channel); @@ -629,7 +678,8 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () { this.socket.on('connect', function () { this.emit('irc connect', that.get('nick'), host, port, ssl, password, callback); - console.log("kiwi.gateway.socket.on('connect')"); + that.trigger('connect', {}); + console.log("kiwi.gateway.socket.on('connect')", host, port); }); this.socket.on('too_many_connections', function () { @@ -639,7 +689,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () { this.socket.on('message', this.parse); this.socket.on('disconnect', function () { - this.emit("disconnect", {}); + that.trigger("disconnect", {}); console.log("kiwi.gateway.socket.on('disconnect')"); }); @@ -649,7 +699,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () { this.socket.on('reconnecting', function (reconnectionDelay, reconnectionAttempts) { console.log("kiwi.gateway.socket.on('reconnecting')"); - this.emit("reconnecting", {delay: reconnectionDelay, attempts: reconnectionAttempts}); + that.trigger("reconnecting", {delay: reconnectionDelay, attempts: reconnectionAttempts}); }); this.socket.on('reconnect_failed', function () { @@ -681,7 +731,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () { * Parses the response from the server */ this.parse = function (item) { - //console.log('gateway event', item); + console.log('gateway event', item); if (item.event !== undefined) { that.trigger('on' + item.event, item); @@ -2001,9 +2051,12 @@ kiwi.view.ServerSelect = Backbone.View.extend({ var values = { nick: $('.nick', this.$el).val(), server: $('.server', this.$el).val(), + port: $('.port', this.$el).val(), + ssl: $('.ssl', this.$el).prop('checked'), + password: $('.password', this.$el).val(), channel: $('.channel', this.$el).val() }; - + this.trigger('server_connect', values); return false; }, @@ -2018,11 +2071,17 @@ kiwi.view.ServerSelect = Backbone.View.extend({ defaults = defaults || {}; nick = defaults.nick || ''; - server = defaults.server || 'irc.kiwiirc.com'; - channel = defaults.channel || '#kiwiirc'; + server = defaults.server || ''; + port = defaults.port || 6667; + ssl = defaults.ssl || 0; + password = defaults.password || ''; + channel = defaults.channel || ''; $('.nick', this.$el).val(nick); $('.server', this.$el).val(server); + $('.port', this.$el).val(port); + $('.ssl', this.$el).prop('checked', ssl); + $('.password', this.$el).val(password); $('.channel', this.$el).val(channel); }, @@ -2511,8 +2570,50 @@ kiwi.view.ControlBox = Backbone.View.extend({ +kiwi.view.StatusMessage = Backbone.View.extend({ + /* Timer for hiding the message */ + tmr: null, + + initialize: function () { + this.$el.hide(); + }, + + text: function (text, opt) { + // Defaults + opt = opt || {}; + opt.type = opt.type || ''; + + this.$el.text(text).attr('class', opt.type); + this.$el.slideDown(kiwi.app.view.doLayout); + + if (opt.timeout) this.doTimeout(opt.timeout); + }, + + html: function (html, opt) { + // Defaults + opt = opt || {}; + opt.type = opt.type || ''; + + this.$el.html(text).attr('class', opt.type); + this.$el.slideDown(kiwi.app.view.doLayout); + + if (opt.timeout) this.doTimeout(opt.timeout); + }, + + hide: function () { + this.$el.slideUp(kiwi.app.view.doLayout); + }, + + doTimeout: function (length) { + if (this.tmr) clearTimeout(this.tmr); + var that = this; + this.tmr = setTimeout(function () { that.hide(); }, length); + } +}); + + + -// This *may* be needed in future kiwi.view.Application = Backbone.View.extend({ initialize: function () { $(window).resize(this.doLayout); @@ -2521,7 +2622,7 @@ kiwi.view.Application = Backbone.View.extend({ this.doLayout(); - $(window).keydown(this.setKeyFocus); + $(document).keydown(this.setKeyFocus); }, @@ -2533,7 +2634,7 @@ kiwi.view.Application = Backbone.View.extend({ } // If we're typing into an input box somewhere, ignore - if (ev.srcElement.tagName.toLowerCase() === 'input') { + if (ev.target.tagName.toLowerCase() === 'input') { return; } diff --git a/client_backbone/kiwi.min.js b/client_backbone/kiwi.min.js index 8209703..2f32cab 100644 --- a/client_backbone/kiwi.min.js +++ b/client_backbone/kiwi.min.js @@ -1 +1 @@ -(function(a){function c(b){var c,d;a.console?(d=a.console.log,a.console.log=function(){b&&d.apply(console,arguments)}):(c=a.opera?a.opera.postError:alert,a.console={},a.console.log=function(a){b&&c(a)})}function d(a){var b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",c="",d,e;for(d=0;d1&&(c-=1),6*c<1?d=a+(b-a)*c*6:2*c<1?d=b:3*c<2?d=a+(b-a)*(2/3-c)*6:d=a,255*d}c<=.5?e=c*(b+1):e=c+b-c*b,d=c*2-e,f=a/360,g=j(d,e,f+1/3),h=j(d,e,f),i=j(d,e,f-1/3)}return[g,h,i]}function g(a){var b,c;if(!a||typeof a!="string")return"";if(a.indexOf(String.fromCharCode(2))!==-1){c="";while(a.indexOf(String.fromCharCode(2))!==-1)a=a.replace(String.fromCharCode(2),c),c=c===""?"":"";c===""&&(a+="")}if(a.indexOf(String.fromCharCode(31))!==-1){c="";while(a.indexOf(String.fromCharCode(31))!==-1)a=a.replace(String.fromCharCode(31),c),c=c===""?"":"";c===""&&(a+="")}return a=function(a){var b,c,d,e,f,g,h,i,j,k;b="",c=function(a){var b=/^\x03([0-9][0-5]?)(,([0-9][0-5]?))?/;return b.exec(a)},d=function(a){switch(parseInt(a,10)){case 0:return"#FFFFFF";case 1:return"#000000";case 2:return"#000080";case 3:return"#008000";case 4:return"#FF0000";case 5:return"#800040";case 6:return"#800080";case 7:return"#FF8040";case 8:return"#FFFF00";case 9:return"#80FF00";case 10:return"#008080";case 11:return"#00FFFF";case 12:return"#0000FF";case 13:return"#FF55FF";case 14:return"#808080";case 15:return"#C0C0C0";default:return null}};if(a.indexOf("")!==-1){e=a.indexOf(""),b=a.substr(0,e);while(e'+k+"",e=g):(a[e]!==""&&a[e]!==String.fromCharCode(15)&&(b+=a[e]),e++);return b}return a}(a),a}var b=a.kiwi={};b.model={},b.view={},b.model.Application=Backbone.Model.extend(new function(){function e(a){c.panels.server.server_login.showError()}var c=this,d={};this.panels=null,this.kiwi_server=null,this.initialize=function(){c=this,this.detectKiwiServer()},this.start=function(){!!getQueryVariable("debug"),b.gateway=new b.model.Gateway,this.bindGatewayCommands(b.gateway),this.initializeClient(),this.view.barsHide(!0),this.panels.server.server_login.bind("server_connect",function(f){var g=this;d=f,g.networkConnecting(),$script(c.kiwi_server+"/socket.io/socket.io.js?ts="+(new Date).getTime(),function(){if(!a.io){e();return}b.gateway.set("kiwi_server",c.kiwi_server+"/kiwi"),b.gateway.set("nick",f.nick),b.gateway.connect(f.server,6667,!1,!1,function(){})})})},this.detectKiwiServer=function(){if(a.location.protocol==="file")this.kiwi_server="http://localhost:7777";else{var b=a.location.protocol==="https"?"https":"http";this.kiwi_server=b+"://"+a.location.host+":"+(a.location.port||"80")}},this.initializeClient=function(){this.view=new b.view.Application({model:this,el:this.get("container")}),this.panels=new b.model.PanelList,this.controlbox=new b.view.ControlBox({el:$("#controlbox")[0]}),this.bindControllboxCommands(this.controlbox),this.topicbar=new b.view.TopicBar({el:$("#topic")[0]}),this.panels.server.view.show(),this.view.doLayout(),this.panels.server.server_login.populateFields({nick:getQueryVariable("nick")||"kiwi_"+Math.ceil(Math.random()*1e4).toString(),server:getQueryVariable("server")||"irc.kiwiirc.com",channel:a.location.hash||"#test"})},this.bindGatewayCommands=function(a){a.on("onmotd",function(a){c.panels.server.addMsg(a.server,a.msg,"motd")}),a.on("onconnect",function(a){c.view.barsShow(),d.channel&&b.gateway.join(d.channel)}),a.on("onjoin",function(a){var d,e,f;d=c.panels.getByName(a.channel),d||(d=new b.model.Channel({name:a.channel}),c.panels.add(d)),e=d.get("members");if(!e)return;f=new b.model.Member({nick:a.nick,ident:a.ident,hostname:a.hostname}),e.add(f)}),a.on("onpart",function(a){var d,e,f,g={};g.type="part",g.message=a.message||"",d=c.panels.getByName(a.channel);if(!d)return;if(a.nick===b.gateway.get("nick")){d.close();return}e=d.get("members");if(!e)return;f=e.getByNick(a.nick);if(!f)return;e.remove(f,g)}),a.on("onquit",function(a){var b,d,e={};e.type="quit",e.message=a.message||"",$.each(c.panels.models,function(c,d){if(!d.isChannel())return;b=d.get("members").getByNick(a.nick),b&&d.get("members").remove(b,e)})}),a.on("onkick",function(a){var d,e,f,g={};g.type="kick",g.by=a.nick,g.message=a.message||"",d=c.panels.getByName(a.channel);if(!d)return;e=d.get("members");if(!e)return;f=e.getByNick(a.kicked);if(!f)return;e.remove(f,g),a.kicked===b.gateway.get("nick")&&e.reset([])}),a.on("onmsg",function(a){var d,e=a.channel==b.gateway.get("nick");e?(d=c.panels.getByName(a.nick),d||(d=new b.model.Channel({name:a.nick}),c.panels.add(d))):(d=c.panels.getByName(a.channel),d||(d=c.panels.server)),d.addMsg(a.nick,a.msg)}),a.on("onnotice",function(a){var b;b=c.panels.getByName(a.target)||c.panels.getByName(a.nick),b||(b=c.panels.server),b.addMsg("["+(a.nick||"")+"]",a.msg)}),a.on("onaction",function(a){var d,e=a.channel==b.gateway.get("nick");e?(d=c.panels.getByName(a.nick),d||(d=new b.model.Channel({name:a.nick}),c.panels.add(d))):(d=c.panels.getByName(a.channel),d||(d=c.panels.server)),d.addMsg("","* "+a.nick+" "+a.msg,"action")}),a.on("ontopic",function(a){var d;d=c.panels.getByName(a.channel);if(!d)return;d.set("topic",a.topic),d.get("name")===b.app.panels.active.get("name")&&c.topicbar.setCurrentTopic(a.topic)}),a.on("ontopicsetby",function(a){var b,d;b=c.panels.getByName(a.channel);if(!b)return;d=(new Date(a.when*1e3)).toLocaleString(),b.addMsg("","Topic set by "+a.nick+" at "+d,"topic")}),a.on("onuserlist",function(a){var d;d=c.panels.getByName(a.channel);if(!d)return;d.temp_userlist=d.temp_userlist||[],_.each(a.users,function(a){var c=new b.model.Member({nick:a.nick,modes:a.modes});d.temp_userlist.push(c)})}),a.on("onuserlist_end",function(a){var b;b=c.panels.getByName(a.channel);if(!b)return;b.get("members").reset(b.temp_userlist||[]),delete b.temp_userlist}),a.on("onmode",function(a){var b,d,e;if(!a.channel)return;b=c.panels.getByName(a.channel);if(!b)return;d=b.get("members");if(!d)return;e=d.getByNick(a.effected_nick);if(!e)return;a.mode[0]==="+"?e.addMode(a.mode.substr(1)):a.mode[0]==="-"&&e.removeMode(a.mode.substr(1))}),a.on("onnick",function(a){var b;$.each(c.panels.models,function(c,d){if(!d.isChannel())return;b=d.get("members").getByNick(a.nick),b&&(b.set("nick",a.newnick),d.addMsg("","== "+a.nick+" is now known as "+a.newnick,"action nick"))})})},this.bindControllboxCommands=function(a){a.on("unknown_command",this.unknownCommand),a.on("command",this.allCommands),a.on("command_msg",this.msgCommand),a.on("command_action",this.actionCommand),a.on("command_me",this.actionCommand),a.on("command_join",this.joinCommand),a.on("command_j",this.joinCommand),a.on("command_part",this.partCommand),a.on("command_p",this.partCommand),a.on("command_nick",function(a){b.gateway.changeNick(a.params[0])}),a.on("command_query",this.queryCommand),a.on("command_q",this.queryCommand),a.on("command_topic",this.topicCommand),a.on("command_notice",this.noticeCommand),a.on("command_css",function(a){var b="?reload="+(new Date).getTime();$('link[rel="stylesheet"]').each(function(){this.href=this.href.replace(/\?.*|$/,b)})})},this.unknownCommand=function(a){var c=a.command+" "+a.params.join(" ");console.log("RAW: "+c),b.gateway.raw(c)},this.allCommands=function(a){console.log("allCommands",a)},this.joinCommand=function(a){var d,e;e=a.params.join(" ").split(","),$.each(e,function(a,e){e=e.trim(),d=c.panels.getByName(e),d||(d=new b.model.Channel({name:e}),b.app.panels.add(d)),b.gateway.join(e)}),d&&d.view.show()},this.queryCommand=function(a){var d,e;d=a.params[0],e=c.panels.getByName(d),e||(e=new b.model.Channel({name:d}),b.app.panels.add(e)),e&&e.view.show()},this.msgCommand=function(a){var d=a.params[0],e=c.panels.getByName(d)||c.panels.server;a.params.shift(),e.addMsg(b.gateway.get("nick"),a.params.join(" ")),b.gateway.privmsg(d,a.params.join(" "))},this.actionCommand=function(a){if(b.app.panels.active===b.app.panels.server)return;var c=b.app.panels.active;c.addMsg("","* "+b.gateway.get("nick")+" "+a.params.join(" "),"action"),b.gateway.action(c.get("name"),a.params.join(" "))},this.partCommand=function(a){a.params.length===0?b.gateway.part(b.app.panels.active.get("name")):_.each(a.params,function(a){b.gateway.part(a)})},this.topicCommand=function(a){var d;if(a.params.length===0)return;c.isChannelName(a.params[0])?(d=a.params[0],a.params.shift()):d=b.app.panels.active.get("name"),b.gateway.topic(d,a.params.join(" "))},this.noticeCommand=function(a){var c;if(a.params.length<=1)return;c=a.params[0],a.params.shift(),b.gateway.notice(c,a.params.join(" "))},this.isChannelName=function(a){var c=b.gateway.get("channel_prefix");return!a||!a.length?!1:c.indexOf(a[0])>-1}}),b.model.Gateway=Backbone.Model.extend(new function(){var a=this;this.defaults={name:"Server",address:"",nick:"",channel_prefix:"#",user_prefixes:["~","&","@","+"],kiwi_server:"http://localhost:7778/kiwi"},this.initialize=function(){a=this,this.socket=this.get("socket"),this.session_id="",network=this},this.connect=function(b,c,d,e,f){this.socket=io.connect(this.get("kiwi_server"),{"try multiple transports":!0,"connect timeout":3e3,"max reconnection attempts":7,"reconnection delay":2e3}),this.socket.on("connect_failed",function(a){console.debug("Unable to connect Socket.IO",a),console.log("kiwi.gateway.socket.on('connect_failed')"),this.socket.disconnect(),this.emit("connect_fail",{reason:a})}),this.socket.on("error",function(a){this.emit("connect_fail",{reason:a}),console.log("kiwi.gateway.socket.on('error')",{reason:a})}),this.socket.on("connecting",function(b){console.log("kiwi.gateway.socket.on('connecting')"),this.emit("connecting"),a.trigger("connecting")}),this.socket.on("connect",function(){this.emit("irc connect",a.get("nick"),b,c,d,e,f),console.log("kiwi.gateway.socket.on('connect')")}),this.socket.on("too_many_connections",function(){this.emit("connect_fail",{reason:"too_many_connections"})}),this.socket.on("message",this.parse),this.socket.on("disconnect",function(){this.emit("disconnect",{}),console.log("kiwi.gateway.socket.on('disconnect')")}),this.socket.on("close",function(){console.log("kiwi.gateway.socket.on('close')")}),this.socket.on("reconnecting",function(a,b){console.log("kiwi.gateway.socket.on('reconnecting')"),this.emit("reconnecting",{delay:a,attempts:b})}),this.socket.on("reconnect_failed",function(){console.log("kiwi.gateway.socket.on('reconnect_failed')")})},this.parse=function(b){if(b.event!==undefined){a.trigger("on"+b.event,b);switch(b.event){case"options":$.each(b.options,function(b,c){switch(b){case"CHANTYPES":a.set("channel_prefix",c.charAt(0));break;case"NETWORK":a.set("name",c);break;case"PREFIX":a.set("user_prefixes",c)}});break;case"connect":a.set("nick",b.nick);break;case"nick":b.nick===a.get("nick")&&a.set("nick",b.newnick);break;case"kiwi":this.emit("kiwi."+b.namespace,b.data)}}},this.sendData=function(a,b){this.socket.emit("message",{sid:this.session_id,data:JSON.stringify(a)},b)},this.privmsg=function(a,b,c){var d={method:"privmsg",args:{target:a,msg:b}};this.sendData(d,c)},this.notice=function(a,b,c){var d={method:"notice",args:{target:a,msg:b}};this.sendData(d,c)},this.ctcp=function(a,b,c,d,e){var f={method:"ctcp",args:{request:a,type:b,target:c,params:d}};this.sendData(f,e)},this.action=function(a,b,c){this.ctcp(!0,"ACTION",a,b,c)},this.join=function(a,b,c){var d={method:"join",args:{channel:a,key:b}};this.sendData(d,c)},this.part=function(a,b){var c={method:"part",args:{channel:a}};this.sendData(c,b)},this.topic=function(a,b,c){var d={method:"topic",args:{channel:a,topic:b}};this.sendData(d,c)},this.kick=function(a,b,c,d){var e={method:"kick",args:{channel:a,nick:b,reason:c}};this.sendData(e,d)},this.quit=function(a,b){a=a||"";var c={method:"quit",args:{message:a}};this.sendData(c,b)},this.raw=function(a,b){a={method:"raw",args:{data:a}},this.sendData(a,b)},this.changeNick=function(a,b){var c={method:"nick",args:{nick:a}};this.sendData(c,b)},this.kiwi=function(a,b,c){b={method:"kiwi",args:{target:a,data:b}},this.sendData(b,c)}}),b.model.Member=Backbone.Model.extend({sortModes:function(a){return a.sort(function(a,c){var d,e,f,g=b.gateway.get("user_prefixes");for(f=0;fe?1:0})},initialize:function(a){var b,c,d;b=this.stripPrefix(this.get("nick")),c=this.get("modes"),c=c||[],this.sortModes(c),this.set({nick:b,modes:c,prefix:this.getPrefix(c)},{silent:!0})},addMode:function(a){var b=a.split(""),c,d;c=this.get("modes"),$.each(b,function(a,b){c.push(b)}),c=this.sortModes(c),this.set({prefix:this.getPrefix(c),modes:c})},removeMode:function(a){var b=a.split(""),c,d;c=this.get("modes"),c=_.reject(c,function(a){return _.indexOf(b,a)!==-1}),this.set({prefix:this.getPrefix(c),modes:c})},getPrefix:function(a){var c="",d=b.gateway.get("user_prefixes");return typeof a[0]!="undefined"&&(c=_.detect(d,function(b){return b.mode===a[0]}),c=c?c.symbol:""),c},stripPrefix:function(a){var c=a,d,e,f,g=b.gateway.get("user_prefixes");d=0;for(e=0;e0){if(f.length===0)return-1;g=h=-1;for(d=0;dh)return 1}else if(f.length>0)return 1;return i=a.get("nick").toLocaleUpperCase(),j=c.get("nick").toLocaleUpperCase(),ij?1:(console.log("Something's gone wrong somewhere - two users have the same nick!"),0)},initialize:function(a){this.view=new b.view.MemberList({model:this})},getByNick:function(a){if(typeof a!="string")return;return this.find(function(b){return a.toLowerCase()===b.get("nick").toLowerCase()})}}),b.model.Panel=Backbone.Model.extend({initialize:function(a){var c=this.get("name")||"";this.view=new b.view.Panel({model:this,name:c}),this.set({scrollback:[],name:c},{silent:!0})},addMsg:function(a,b,c,d){var e,f,g;d=d||{};if(!d||typeof d.time=="undefined")g=new Date,d.time=g.getHours().toString().lpad(2,"0")+":"+g.getMinutes().toString().lpad(2,"0")+":"+g.getSeconds().toString().lpad(2,"0");if(!d||typeof d.style=="undefined")d.style="";e={msg:b,time:d.time,nick:a,chan:this.get("name"),type:c,style:d.style};if(!e)return;typeof e.type!="string"&&(e.type=""),typeof e.msg!="string"&&(e.msg=""),f=this.get("scrollback"),f.push(e),f.length>250&&f.splice(250),this.set({scrollback:f},{silent:!0}),this.trigger("msg",e)},close:function(){this.view.remove(),delete this.view;var a=this.get("members");a&&(a.reset([]),this.unset("members")),this.destroy(),this.cid===b.app.panels.active.cid&&b.app.panels.server.view.show()},isChannel:function(){var a=b.gateway.get("channel_prefix"),c=this.get("name");return c?a.indexOf(c[0])>-1:!1}}),b.model.PanelList=Backbone.Collection.extend({model:b.model.Panel,active:null,comparator:function(a){return a.get("name")},initialize:function(){this.view=new b.view.Tabs({el:$("#toolbar .panellist")[0],model:this}),this.add(new b.model.Server({name:b.gateway.get("name")})),this.server=this.getByName(b.gateway.get("name")),this.bind("active",function(a){this.active=a},this)},getByName:function(a){if(typeof a!="string")return;return this.find(function(b){return a.toLowerCase()===b.get("name").toLowerCase()})}}),b.model.Channel=b.model.Panel.extend({initialize:function(a){var c=this.get("name")||"",d;this.view=new b.view.Channel({model:this,name:c}),this.set({members:new b.model.MemberList,name:c,scrollback:[],topic:""},{silent:!0}),d=this.get("members"),d.bind("add",function(a){this.addMsg(" ","--> "+a.displayNick(!0)+" has joined","action join")},this),d.bind("remove",function(a,b,c){var d=c.message?"("+c.message+")":"";c.type==="quit"?this.addMsg(" ","<-- "+a.displayNick(!0)+" has quit "+d,"action quit"):c.type==="kick"?this.addMsg(" ","<-- "+a.displayNick(!0)+" was kicked by "+c.by+" "+d,"action kick"):this.addMsg(" ","<-- "+a.displayNick(!0)+" has left "+d,"action part")},this)}}),b.model.Server=b.model.Panel.extend({server_login:null,initialize:function(a){var c="Server";this.view=new b.view.Panel({model:this,name:c}),this.set({scrollback:[],name:c},{silent:!0}),this.server_login=new b.view.ServerSelect,this.view.$el.append(this.server_login.$el),this.server_login.show()}}),typeof String.prototype.trim=="undefined"&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),typeof String.prototype.lpad=="undefined"&&(String.prototype.lpad=function(a,b){var c="",d;for(d=0;d';return''+c+'
'}),a):a}},{name:"html_safe",onaddmsg:function(a,b){return a.msg=$("
").text(a.msg).html(),a.nick=$("
").text(a.nick).html(),a}},{name:"activity",onaddmsg:function(a,b){return a}},{name:"highlight",onaddmsg:function(a,b){return a}},{name:"linkify_plain",onaddmsg:function(a,b){return a.msg?(a.msg=a.msg.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,function(a){var b;return a.match(/(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/)?a:(b=a,a.match("^https?://")?b=a:a="http://"+a,''+b+"")}),a):a}},{name:"lftobr",onaddmsg:function(a,b){return a.msg?(a.msg=a.msg.replace(/\n/gi,function(a){return"
"}),a):a}},{name:"nick_colour",onaddmsg:function(a,b){if(!a.msg)return a;var c=this.randColour();return a.nick=''+a.nick+"",a},randColour:function(){var a=this.rand(-250,0),b=this.rand(30,100),c=this.rand(20,70);return"hsl("+a+","+b+"%,"+c+"%)"},rand:function(a,b){return parseInt(Math.random()*(b-a+1),10)+a}},{name:"kiwitest",oninit:function(a,b){console.log("registering namespace"),$(gateway).bind("kiwi.lol.browser",function(a,b){console.log("YAY kiwitest"),console.log(b)})}}];b.plugs={},b.plugs.loaded={},b.plugs.loadPlugin=function(a){var c;return typeof a.name!="string"?!1:(c=b.plugs.run("plugin_load",{plugin:a}),typeof c=="object"&&(b.plugs.loaded[c.plugin.name]=c.plugin,b.plugs.loaded[c.plugin.name].local_data=new b.dataStore("kiwi_plugin_"+c.plugin.name)),b.plugs.run("init",{},{run_only:c.plugin.name}),!0)},b.plugs.unloadPlugin=function(a){if(typeof b.plugs.loaded[a]!="object")return;b.plugs.run("unload",{},{run_only:a}),delete b.plugs.loaded[a]},b.plugs.run=function(a,c,d){var e=c,f,g;c=typeof c=="undefined"?{}:c,d=typeof d=="undefined"?{}:d;for(g in b.plugs.loaded){if(typeof d.run_only=="string"&&d.run_only!==g)continue;if(typeof b.plugs.loaded[g]["on"+a]=="function")try{f=b.plugs.loaded[g]["on"+a](e,d);if(f===null)return null;e=f;if(typeof e.event_bubbles=="boolean"&&e.event_bubbles===!1)return delete e.event_bubbles,e}catch(h){}}return e},b.dataStore=function(a){var b=a;this.get=function(b){return $.jStorage.get(a+"_"+b)},this.set=function(b,c){return $.jStorage.set(a+"_"+b,c)}},b.data=new b.dataStore("kiwi"),function(b){function j(){if("localStorage"in a)try{a.localStorage&&(d=a.localStorage,i="localStorage")}catch(b){}else if("globalStorage"in a)try{a.globalStorage&&(d=a.globalStorage[a.location.hostname],i="globalStorage")}catch(c){}else{e=document.createElement("link");if(!e.addBehavior){e=null;return}e.style.behavior="url(#default#userData)",document.getElementsByTagName("head")[0].appendChild(e),e.load("jStorage");var f="{}";try{f=e.getAttribute("jStorage")}catch(g){}d.jStorage=f,i="userDataBehavior"}k()}function k(){if(d.jStorage)try{c=h(String(d.jStorage))}catch(a){d.jStorage="{}"}else d.jStorage="{}";f=d.jStorage?String(d.jStorage).length:0}function l(){try{d.jStorage=g(c),e&&(e.setAttribute("jStorage",d.jStorage),e.save("jStorage")),f=d.jStorage?String(d.jStorage).length:0}catch(a){}}function m(a){if(!a||typeof a!="string"&&typeof a!="number")throw new TypeError("Key name must be string or numeric");return!0}if(!b||!(b.toJSON||Object.toJSON||a.JSON))throw new Error("jQuery, MooTools or Prototype needs to be loaded before jStorage!");var c={},d={jStorage:"{}"},e=null,f=0,g=b.toJSON||Object.toJSON||a.JSON&&(JSON.encode||JSON.stringify),h=b.evalJSON||a.JSON&&(JSON.decode||JSON.parse)||function(a){return String(a).evalJSON()},i=!1;_XMLService={isXML:function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1},encode:function(a){if(!this.isXML(a))return!1;try{return(new XMLSerializer).serializeToString(a)}catch(b){try{return a.xml}catch(c){}}return!1},decode:function(b){var c="DOMParser"in a&&(new DOMParser).parseFromString||a.ActiveXObject&&function(a){var b=new ActiveXObject("Microsoft.XMLDOM");return b.async="false",b.loadXML(a),b},d;return c?(d=c.call("DOMParser"in a&&new DOMParser||a,b,"text/xml"),this.isXML(d)?d:!1):!1}},b.jStorage={version:"0.1.5.1",set:function(a,b){return m(a),_XMLService.isXML(b)&&(b={_is_xml:!0,xml:_XMLService.encode(b)}),c[a]=b,l(),b},get:function(a,b){return m(a),a in c?c[a]&&typeof c[a]=="object"&&c[a]._is_xml&&c[a]._is_xml?_XMLService.decode(c[a].xml):c[a]:typeof b=="undefined"?null:b},deleteKey:function(a){return m(a),a in c?(delete c[a],l(),!0):!1},flush:function(){return c={},l(),!0},storageObj:function(){function a(){}return a.prototype=c,new a},index:function(){var a=[],b;for(b in c)c.hasOwnProperty(b)&&a.push(b);return a},storageSize:function(){return f},currentBackend:function(){return i},storageAvailable:function(){return!!i},reInit:function(){var a,b;if(e&&e.addBehavior){a=document.createElement("link"),e.parentNode.replaceChild(a,e),e=a,e.style.behavior="url(#default#userData)",document.getElementsByTagName("head")[0].appendChild(e),e.load("jStorage"),b="{}";try{b=e.getAttribute("jStorage")}catch(c){}d.jStorage=b,i="userDataBehavior"}k()}},j()}(a.jQuery||a.$),b.view={},b.view.MemberList=Backbone.View.extend({tagName:"ul",events:{"click .nick":"nickClick"},initialize:function(a){this.model.bind("all",this.render,this),$(this.el).appendTo("#memberlists")},render:function(){var a=$(this.el);a.empty(),this.model.forEach(function(b){$('
  • '+b.get("prefix")+""+b.get("nick")+"
  • ").appendTo(a).data("member",b)})},nickClick:function(a){var c=$(a.currentTarget).parent("li"),d=c.data("member"),e=new b.view.UserBox;e.member=d,$(".userbox",this.$el).remove(),c.append(e.$el)},show:function(){$("#memberlists").children().removeClass("active"),$(this.el).addClass("active")}}),b.view.UserBox=Backbone.View.extend({member:{},events:{"click .query":"queryClick","click .info":"infoClick"},initialize:function(){this.$el=$($("#tmpl_userbox").html())},queryClick:function(a){var c=new b.model.Channel({name:this.member.get("nick")});b.app.panels.add(c),c.view.show()},infoClick:function(a){b.gateway.raw("WHOIS "+this.member.get("nick"))}}),b.view.ServerSelect=Backbone.View.extend({events:{"submit form":"submitLogin","click .show_more":"showMore"},initialize:function(){this.$el=$($("#tmpl_server_select").html()),b.gateway.bind("onconnect",this.networkConnected,this),b.gateway.bind("connecting",this.networkConnecting,this)},submitLogin:function(a){var b={nick:$(".nick",this.$el).val(),server:$(".server",this.$el).val(),channel:$(".channel",this.$el).val()};return this.trigger("server_connect",b),!1},showMore:function(a){$(".more",this.$el).slideDown("fast")},populateFields:function(a){var b,c,d;a=a||{},b=a.nick||"",c=a.server||"irc.kiwiirc.com",d=a.channel||"#kiwiirc",$(".nick",this.$el).val(b),$(".server",this.$el).val(c),$(".channel",this.$el).val(d)},hide:function(){this.$el.slideUp()},show:function(){this.$el.show(),$(".nick",this.$el).focus()},setStatus:function(a,b){$(".status",this.$el).text(a).attr("class","status").addClass(b).show()},clearStatus:function(){$(".status",this.$el).hide()},networkConnected:function(a){this.setStatus("Connected :)","ok"),$("form",this.$el).hide()},networkConnecting:function(a){this.setStatus("Connecting..","ok")},showError:function(a){this.setStatus("Error connecting","error"),$("form",this.$el).show()}}),b.view.Panel=Backbone.View.extend({tagName:"div",className:"messages",events:{"click .chan":"chanClick"},$container:null,initialize:function(a){this.initializePanel(a)},initializePanel:function(a){this.$el.css("display","none"),a.container?this.$container=$(a.container):this.$container=$("#panels .container1"),this.$el.appendTo(this.$container),this.model.bind("msg",this.newMsg,this),this.msg_count=0,this.model.set({view:this},{silent:!0})},render:function(){this.$el.empty(),this.model.get("backscroll").forEach(this.newMsg)},newMsg:function(a){var c,d,e=this.$el,h;a.msg=$("
    ").text(a.msg).html(),c=new RegExp("\\B(["+b.gateway.get("channel_prefix")+"][^ ,.\\007]+)","g"),a.msg=a.msg.replace(c,function(a){return''+a+""}),a.msg=a.msg.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]*))?/gi,function(a){var b;return a.match(/^www\./)&&(a="http://"+a),b=a,b.length>100&&(b=b.substr(0,100)+"..."),''+b+""}),a.msg=g(a.msg),h=function(a){var b=0,c;return _.map(a.split(""),function(a){b+=a.charCodeAt(0)}),c=f(b%255,70,35),c=c[2]|c[1]<<8|c[0]<<16,"#"+c.toString(16)}(a.nick),a.nick_style="color:"+h+";",d='
    <%- time %>
    <%- nick %>
    <%= msg %>
    ',e.append(_.template(d,a)),this.scrollToBottom(),this.msg_count++,this.msg_count>250&&($(".msg:first",this.div).remove(),this.msg_count--)},chanClick:function(a){b.gateway.join($(a.srcElement).text())},show:function(){var a=this.$el;this.$container.children().css("display","none"),a.css("display","block");var c=this.model.get("members");c?(c.view.show(),this.$container.parent().css("right","200px")):($("#memberlists").children().removeClass("active"),this.$container.parent().css("right","0")),this.scrollToBottom(),this.trigger("active",this.model),b.app.panels.trigger("active",this.model)},scrollToBottom:function(){this.$container[0].scrollTop=this.$container[0].scrollHeight}}),b.view.Channel=b.view.Panel.extend({initialize:function(a){this.initializePanel(a),this.model.bind("change:topic",this.topic,this)},topic:function(a){if(typeof a!="string"||!a)a=this.model.get("topic");this.model.addMsg("","=== Topic for "+this.model.get("name")+" is: "+a,"topic"),b.app.panels.active===this&&b.app.topicbar.setCurrentTopic(this.model.get("topic"))}}),b.view.Tabs=Backbone.View.extend({events:{"click li":"tabClick","click li img":"partClick"},initialize:function(){this.model.on("add",this.panelAdded,this),this.model.on("remove",this.panelRemoved,this),this.model.on("reset",this.render,this),this.model.on("active",this.panelActive,this),b.gateway.on("change:name",function(a,b){$("span",this.model.server.tab).text(b)},this)},render:function(){var a=this;this.$el.empty(),this.model.server.tab.data("panel_id",this.model.server.cid).appendTo(this.$el),this.model.forEach(function(b){if(b==a.model.server)return;b.tab.data("panel_id",b.cid).appendTo(this.$el)})},panelAdded:function(a){a.tab=$("
  • "+a.get("name")+"
  • "),a.tab.data("panel_id",a.cid).appendTo(this.$el)},panelRemoved:function(a){a.tab.remove(),delete a.tab},panelActive:function(a){$("img",this.$el).remove(),this.$el.children().removeClass("active"),a.tab.addClass("active"),a.tab.append('')},tabClick:function(a){var b=$(a.currentTarget),c=this.model.getByCid(b.data("panel_id"));if(!c)return;c.view.show()},partClick:function(a){var c=$(a.currentTarget).parent(),d=this.model.getByCid(c.data("panel_id"));d.isChannel()?b.gateway.part(d.get("name")):d.close()},next:function(){var a=b.app.panels.active.tab.next();a.length||(a=$("li:first",this.$el)),a.click()},prev:function(){var a=b.app.panels.active.tab.prev();a.length||(a=$("li:last",this.$el)),a.click()}}),b.view.TopicBar=Backbone.View.extend({events:{"keydown input":"process"},initialize:function(){b.app.panels.bind("active",function(a){this.setCurrentTopic(a.get("topic"))},this)},process:function(a){var c=$(a.currentTarget),d=c.val();if(a.keyCode!==13)return;b.app.panels.active.isChannel()&&b.gateway.topic(b.app.panels.active.get("name"),d)},setCurrentTopic:function(a){a=a||"",a=$("
    ").html(g(a)),$("input",this.$el).val(a.text())}}),b.view.ControlBox=Backbone.View.extend({buffer:[],buffer_pos:0,tabcomplete:{active:!1,data:[],prefix:""},events:{"keydown input":"process"},initialize:function(){var a=this;b.gateway.bind("change:nick",function(){$(".nick",a.$el).text(this.get("nick"))})},process:function(a){var c=this,d=$(a.currentTarget),e=d.val(),f;navigator.appVersion.indexOf("Mac")!==-1?f=a.ctrlKey:f=a.altKey,this.tabcomplete.active&&a.keyCode!==9&&(this.tabcomplete.active=!1,this.tabcomplete.data=[],this.tabcomplete.prefix="");switch(!0){case a.keyCode===13:e=e.trim(),e&&(this.processInput(d.val()),this.buffer.push(d.val()),this.buffer_pos=this.buffer.length),d.val("");break;case a.keyCode===38:this.buffer_pos>0&&(this.buffer_pos--,d.val(this.buffer[this.buffer_pos]));break;case a.keyCode===40:this.buffer_pos0&&(f=d[0].selectionStart-i.length,b=e.substr(0,f),g=this.tabcomplete.data.shift(),this.tabcomplete.data.push(g),b+=g,b+=e.substr(d[0].selectionStart),d.val(b),d[0].setSelectionRange?d[0].setSelectionRange(f+g.length,f+g.length):d[0].createTextRange&&(h=d[0].createTextRange(),h.collapse(!0),h.moveEnd("character",f+g.length),h.moveStart("character",f+g.length),h.select()))}.apply(this),!1}},processInput:function(a){var c,d=a.split(" ");d[0][0]==="/"?(c=d[0].substr(1).toLowerCase(),d=d.splice(1)):(c="msg",d.unshift(b.app.panels.active.get("name"))),this.trigger("command",{command:c,params:d}),this.trigger("command_"+c,{command:c,params:d}),this._callbacks["command_"+c]||this.trigger("unknown_command",{command:c,params:d})}}),b.view.Application=Backbone.View.extend({initialize:function(){$(a).resize(this.doLayout),$("#toolbar").resize(this.doLayout),$("#controlbox").resize(this.doLayout),this.doLayout(),$(a).keydown(this.setKeyFocus)},setKeyFocus:function(a){if(a.ctrlKey||a.altKey)return;if(a.srcElement.tagName.toLowerCase()==="input")return;$("#controlbox .inp").focus()},doLayout:function(){var a=$("#panels"),b=$("#memberlists"),c=$("#toolbar"),d=$("#controlbox"),e={top:c.outerHeight(!0),bottom:d.outerHeight(!0)};a.css(e),b.css(e)},barsHide:function(a){var b=this;a?($("#toolbar").slideUp(0),$("#controlbox").slideUp(0)):($("#toolbar").slideUp(),$("#controlbox").slideUp(function(){b.doLayout()}))},barsShow:function(a){var b=this;a?($("#toolbar").slideDown(0),$("#controlbox").slideDown(0),this.doLayout()):($("#toolbar").slideDown(),$("#controlbox").slideDown(function(){b.doLayout()}))}})})(window) \ No newline at end of file +(function(a){function c(b){var c,d;a.console?(d=a.console.log,a.console.log=function(){b&&d.apply(console,arguments)}):(c=a.opera?a.opera.postError:alert,a.console={},a.console.log=function(a){b&&c(a)})}function d(a){var b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",c="",d,e;for(d=0;d1&&(c-=1),6*c<1?d=a+(b-a)*c*6:2*c<1?d=b:3*c<2?d=a+(b-a)*(2/3-c)*6:d=a,255*d}c<=.5?e=c*(b+1):e=c+b-c*b,d=c*2-e,f=a/360,g=j(d,e,f+1/3),h=j(d,e,f),i=j(d,e,f-1/3)}return[g,h,i]}function g(a){var b,c;if(!a||typeof a!="string")return"";if(a.indexOf(String.fromCharCode(2))!==-1){c="";while(a.indexOf(String.fromCharCode(2))!==-1)a=a.replace(String.fromCharCode(2),c),c=c===""?"":"";c===""&&(a+="")}if(a.indexOf(String.fromCharCode(31))!==-1){c="";while(a.indexOf(String.fromCharCode(31))!==-1)a=a.replace(String.fromCharCode(31),c),c=c===""?"":"";c===""&&(a+="")}return a=function(a){var b,c,d,e,f,g,h,i,j,k;b="",c=function(a){var b=/^\x03([0-9][0-5]?)(,([0-9][0-5]?))?/;return b.exec(a)},d=function(a){switch(parseInt(a,10)){case 0:return"#FFFFFF";case 1:return"#000000";case 2:return"#000080";case 3:return"#008000";case 4:return"#FF0000";case 5:return"#800040";case 6:return"#800080";case 7:return"#FF8040";case 8:return"#FFFF00";case 9:return"#80FF00";case 10:return"#008080";case 11:return"#00FFFF";case 12:return"#0000FF";case 13:return"#FF55FF";case 14:return"#808080";case 15:return"#C0C0C0";default:return null}};if(a.indexOf("")!==-1){e=a.indexOf(""),b=a.substr(0,e);while(e'+k+"",e=g):(a[e]!==""&&a[e]!==String.fromCharCode(15)&&(b+=a[e]),e++);return b}return a}(a),a}var b=a.kiwi={};b.model={},b.view={},typeof global=="undefined"&&(global={}),global.kiwi={gateway:undefined,user:undefined,server:undefined,channels:undefined,utils:undefined},b.model.Application=Backbone.Model.extend(new function(){function e(a){c.panels.server.server_login.showError()}var c=this,d={};this.panels=null,this.view,this.message,this.kiwi_server=null,this.initialize=function(){c=this,this.detectKiwiServer()},this.start=function(){!!getQueryVariable("debug"),b.gateway=new b.model.Gateway,this.bindGatewayCommands(b.gateway),this.initializeClient(),this.view.barsHide(!0),this.panels.server.server_login.bind("server_connect",function(f){var g=this;d=f,g.networkConnecting(),$script(c.kiwi_server+"/socket.io/socket.io.js?ts="+(new Date).getTime(),function(){if(!a.io){e();return}b.gateway.set("kiwi_server",c.kiwi_server+"/kiwi"),b.gateway.set("nick",f.nick),b.gateway.connect(f.server,f.port,f.ssl,f.password,function(){})})})},this.detectKiwiServer=function(){if(a.location.protocol==="file")this.kiwi_server="http://localhost:7777";else{var b=a.location.protocol==="https"?"https":"http";this.kiwi_server=b+"://"+a.location.host+":"+(a.location.port||"80")}},this.initializeClient=function(){this.view=new b.view.Application({model:this,el:this.get("container")}),this.panels=new b.model.PanelList,this.controlbox=new b.view.ControlBox({el:$("#controlbox")[0]}),this.bindControllboxCommands(this.controlbox),this.topicbar=new b.view.TopicBar({el:$("#topic")[0]}),this.message=new b.view.StatusMessage({el:$("#status_message")[0]}),this.panels.server.view.show(),this.view.doLayout(),this.panels.server.server_login.populateFields({nick:getQueryVariable("nick")||"kiwi_"+Math.ceil(Math.random()*1e4).toString(),server:getQueryVariable("server")||"irc.kiwiirc.com",port:6667,ssl:!1,channel:a.location.hash||"#test"})},this.bindGatewayCommands=function(a){a.on("onmotd",function(a){c.panels.server.addMsg(a.server,a.msg,"motd")}),a.on("onconnect",function(a){c.view.barsShow(),d.channel&&b.gateway.join(d.channel)}),function(){var b=0;a.on("disconnect",function(a){c.message.text("You have been disconnected. Attempting to reconnect.."),b=1}),a.on("reconnecting",function(a){c.message.text("You have been disconnected. Attempting to reconnect again in "+a.delay/1e3+" seconds..")}),a.on("connect",function(a){if(b!==1)return;c.message.text("It's OK, you're connected again :)",{timeout:5e3}),b=0})}(),a.on("onjoin",function(a){var d,e,f;d=c.panels.getByName(a.channel),d||(d=new b.model.Channel({name:a.channel}),c.panels.add(d)),e=d.get("members");if(!e)return;f=new b.model.Member({nick:a.nick,ident:a.ident,hostname:a.hostname}),e.add(f)}),a.on("onpart",function(a){var d,e,f,g={};g.type="part",g.message=a.message||"",d=c.panels.getByName(a.channel);if(!d)return;if(a.nick===b.gateway.get("nick")){d.close();return}e=d.get("members");if(!e)return;f=e.getByNick(a.nick);if(!f)return;e.remove(f,g)}),a.on("onquit",function(a){var b,d,e={};e.type="quit",e.message=a.message||"",$.each(c.panels.models,function(c,d){if(!d.isChannel())return;b=d.get("members").getByNick(a.nick),b&&d.get("members").remove(b,e)})}),a.on("onkick",function(a){var d,e,f,g={};g.type="kick",g.by=a.nick,g.message=a.message||"",d=c.panels.getByName(a.channel);if(!d)return;e=d.get("members");if(!e)return;f=e.getByNick(a.kicked);if(!f)return;e.remove(f,g),a.kicked===b.gateway.get("nick")&&e.reset([])}),a.on("onmsg",function(a){var d,e=a.channel==b.gateway.get("nick");e?(d=c.panels.getByName(a.nick),d||(d=new b.model.Channel({name:a.nick}),c.panels.add(d))):(d=c.panels.getByName(a.channel),d||(d=c.panels.server)),d.addMsg(a.nick,a.msg)}),a.on("onnotice",function(a){var b;b=c.panels.getByName(a.target)||c.panels.getByName(a.nick),b||(b=c.panels.server),b.addMsg("["+(a.nick||"")+"]",a.msg)}),a.on("onaction",function(a){var d,e=a.channel==b.gateway.get("nick");e?(d=c.panels.getByName(a.nick),d||(d=new b.model.Channel({name:a.nick}),c.panels.add(d))):(d=c.panels.getByName(a.channel),d||(d=c.panels.server)),d.addMsg("","* "+a.nick+" "+a.msg,"action")}),a.on("ontopic",function(a){var d;d=c.panels.getByName(a.channel);if(!d)return;d.set("topic",a.topic),d.get("name")===b.app.panels.active.get("name")&&c.topicbar.setCurrentTopic(a.topic)}),a.on("ontopicsetby",function(a){var b,d;b=c.panels.getByName(a.channel);if(!b)return;d=(new Date(a.when*1e3)).toLocaleString(),b.addMsg("","Topic set by "+a.nick+" at "+d,"topic")}),a.on("onuserlist",function(a){var d;d=c.panels.getByName(a.channel);if(!d)return;d.temp_userlist=d.temp_userlist||[],_.each(a.users,function(a){var c=new b.model.Member({nick:a.nick,modes:a.modes});d.temp_userlist.push(c)})}),a.on("onuserlist_end",function(a){var b;b=c.panels.getByName(a.channel);if(!b)return;b.get("members").reset(b.temp_userlist||[]),delete b.temp_userlist}),a.on("onmode",function(a){var b,d,e;if(!a.channel)return;b=c.panels.getByName(a.channel);if(!b)return;d=b.get("members");if(!d)return;e=d.getByNick(a.effected_nick);if(!e)return;a.mode[0]==="+"?e.addMode(a.mode.substr(1)):a.mode[0]==="-"&&e.removeMode(a.mode.substr(1))}),a.on("onnick",function(a){var b;$.each(c.panels.models,function(c,d){if(!d.isChannel())return;b=d.get("members").getByNick(a.nick),b&&(b.set("nick",a.newnick),d.addMsg("","== "+a.nick+" is now known as "+a.newnick,"action nick"))})})},this.bindControllboxCommands=function(a){a.on("unknown_command",this.unknownCommand),a.on("command",this.allCommands),a.on("command_msg",this.msgCommand),a.on("command_action",this.actionCommand),a.on("command_me",this.actionCommand),a.on("command_join",this.joinCommand),a.on("command_j",this.joinCommand),a.on("command_part",this.partCommand),a.on("command_p",this.partCommand),a.on("command_nick",function(a){b.gateway.changeNick(a.params[0])}),a.on("command_query",this.queryCommand),a.on("command_q",this.queryCommand),a.on("command_topic",this.topicCommand),a.on("command_notice",this.noticeCommand),a.on("command_css",function(a){var b="?reload="+(new Date).getTime();$('link[rel="stylesheet"]').each(function(){this.href=this.href.replace(/\?.*|$/,b)})})},this.unknownCommand=function(a){var c=a.command+" "+a.params.join(" ");console.log("RAW: "+c),b.gateway.raw(c)},this.allCommands=function(a){console.log("allCommands",a)},this.joinCommand=function(a){var d,e;e=a.params.join(" ").split(","),$.each(e,function(a,e){e=e.trim(),d=c.panels.getByName(e),d||(d=new b.model.Channel({name:e}),b.app.panels.add(d)),b.gateway.join(e)}),d&&d.view.show()},this.queryCommand=function(a){var d,e;d=a.params[0],e=c.panels.getByName(d),e||(e=new b.model.Channel({name:d}),b.app.panels.add(e)),e&&e.view.show()},this.msgCommand=function(a){var d=a.params[0],e=c.panels.getByName(d)||c.panels.server;a.params.shift(),e.addMsg(b.gateway.get("nick"),a.params.join(" ")),b.gateway.privmsg(d,a.params.join(" "))},this.actionCommand=function(a){if(b.app.panels.active===b.app.panels.server)return;var c=b.app.panels.active;c.addMsg("","* "+b.gateway.get("nick")+" "+a.params.join(" "),"action"),b.gateway.action(c.get("name"),a.params.join(" "))},this.partCommand=function(a){a.params.length===0?b.gateway.part(b.app.panels.active.get("name")):_.each(a.params,function(a){b.gateway.part(a)})},this.topicCommand=function(a){var d;if(a.params.length===0)return;c.isChannelName(a.params[0])?(d=a.params[0],a.params.shift()):d=b.app.panels.active.get("name"),b.gateway.topic(d,a.params.join(" "))},this.noticeCommand=function(a){var c;if(a.params.length<=1)return;c=a.params[0],a.params.shift(),b.gateway.notice(c,a.params.join(" "))},this.isChannelName=function(a){var c=b.gateway.get("channel_prefix");return!a||!a.length?!1:c.indexOf(a[0])>-1}}),b.model.Gateway=Backbone.Model.extend(new function(){var a=this;this.defaults={name:"Server",address:"",nick:"",channel_prefix:"#",user_prefixes:["~","&","@","+"],kiwi_server:"http://localhost:7778/kiwi"},this.initialize=function(){a=this,this.socket=this.get("socket"),this.session_id="",network=this},this.connect=function(b,c,d,e,f){this.socket=io.connect(this.get("kiwi_server"),{"try multiple transports":!0,"connect timeout":3e3,"max reconnection attempts":7,"reconnection delay":2e3}),this.socket.on("connect_failed",function(a){console.debug("Unable to connect Socket.IO",a),console.log("kiwi.gateway.socket.on('connect_failed')"),this.socket.disconnect(),this.emit("connect_fail",{reason:a})}),this.socket.on("error",function(a){this.emit("connect_fail",{reason:a}),console.log("kiwi.gateway.socket.on('error')",{reason:a})}),this.socket.on("connecting",function(b){console.log("kiwi.gateway.socket.on('connecting')"),this.emit("connecting"),a.trigger("connecting")}),this.socket.on("connect",function(){this.emit("irc connect",a.get("nick"),b,c,d,e,f),a.trigger("connect",{}),console.log("kiwi.gateway.socket.on('connect')",b,c)}),this.socket.on("too_many_connections",function(){this.emit("connect_fail",{reason:"too_many_connections"})}),this.socket.on("message",this.parse),this.socket.on("disconnect",function(){a.trigger("disconnect",{}),console.log("kiwi.gateway.socket.on('disconnect')")}),this.socket.on("close",function(){console.log("kiwi.gateway.socket.on('close')")}),this.socket.on("reconnecting",function(b,c){console.log("kiwi.gateway.socket.on('reconnecting')"),a.trigger("reconnecting",{delay:b,attempts:c})}),this.socket.on("reconnect_failed",function(){console.log("kiwi.gateway.socket.on('reconnect_failed')")})},this.parse=function(b){console.log("gateway event",b);if(b.event!==undefined){a.trigger("on"+b.event,b);switch(b.event){case"options":$.each(b.options,function(b,c){switch(b){case"CHANTYPES":a.set("channel_prefix",c.charAt(0));break;case"NETWORK":a.set("name",c);break;case"PREFIX":a.set("user_prefixes",c)}});break;case"connect":a.set("nick",b.nick);break;case"nick":b.nick===a.get("nick")&&a.set("nick",b.newnick);break;case"kiwi":this.emit("kiwi."+b.namespace,b.data)}}},this.sendData=function(a,b){this.socket.emit("message",{sid:this.session_id,data:JSON.stringify(a)},b)},this.privmsg=function(a,b,c){var d={method:"privmsg",args:{target:a,msg:b}};this.sendData(d,c)},this.notice=function(a,b,c){var d={method:"notice",args:{target:a,msg:b}};this.sendData(d,c)},this.ctcp=function(a,b,c,d,e){var f={method:"ctcp",args:{request:a,type:b,target:c,params:d}};this.sendData(f,e)},this.action=function(a,b,c){this.ctcp(!0,"ACTION",a,b,c)},this.join=function(a,b,c){var d={method:"join",args:{channel:a,key:b}};this.sendData(d,c)},this.part=function(a,b){var c={method:"part",args:{channel:a}};this.sendData(c,b)},this.topic=function(a,b,c){var d={method:"topic",args:{channel:a,topic:b}};this.sendData(d,c)},this.kick=function(a,b,c,d){var e={method:"kick",args:{channel:a,nick:b,reason:c}};this.sendData(e,d)},this.quit=function(a,b){a=a||"";var c={method:"quit",args:{message:a}};this.sendData(c,b)},this.raw=function(a,b){a={method:"raw",args:{data:a}},this.sendData(a,b)},this.changeNick=function(a,b){var c={method:"nick",args:{nick:a}};this.sendData(c,b)},this.kiwi=function(a,b,c){b={method:"kiwi",args:{target:a,data:b}},this.sendData(b,c)}}),b.model.Member=Backbone.Model.extend({sortModes:function(a){return a.sort(function(a,c){var d,e,f,g=b.gateway.get("user_prefixes");for(f=0;fe?1:0})},initialize:function(a){var b,c,d;b=this.stripPrefix(this.get("nick")),c=this.get("modes"),c=c||[],this.sortModes(c),this.set({nick:b,modes:c,prefix:this.getPrefix(c)},{silent:!0})},addMode:function(a){var b=a.split(""),c,d;c=this.get("modes"),$.each(b,function(a,b){c.push(b)}),c=this.sortModes(c),this.set({prefix:this.getPrefix(c),modes:c})},removeMode:function(a){var b=a.split(""),c,d;c=this.get("modes"),c=_.reject(c,function(a){return _.indexOf(b,a)!==-1}),this.set({prefix:this.getPrefix(c),modes:c})},getPrefix:function(a){var c="",d=b.gateway.get("user_prefixes");return typeof a[0]!="undefined"&&(c=_.detect(d,function(b){return b.mode===a[0]}),c=c?c.symbol:""),c},stripPrefix:function(a){var c=a,d,e,f,g=b.gateway.get("user_prefixes");d=0;for(e=0;e0){if(f.length===0)return-1;g=h=-1;for(d=0;dh)return 1}else if(f.length>0)return 1;return i=a.get("nick").toLocaleUpperCase(),j=c.get("nick").toLocaleUpperCase(),ij?1:(console.log("Something's gone wrong somewhere - two users have the same nick!"),0)},initialize:function(a){this.view=new b.view.MemberList({model:this})},getByNick:function(a){if(typeof a!="string")return;return this.find(function(b){return a.toLowerCase()===b.get("nick").toLowerCase()})}}),b.model.Panel=Backbone.Model.extend({initialize:function(a){var c=this.get("name")||"";this.view=new b.view.Panel({model:this,name:c}),this.set({scrollback:[],name:c},{silent:!0})},addMsg:function(a,b,c,d){var e,f,g;d=d||{};if(!d||typeof d.time=="undefined")g=new Date,d.time=g.getHours().toString().lpad(2,"0")+":"+g.getMinutes().toString().lpad(2,"0")+":"+g.getSeconds().toString().lpad(2,"0");if(!d||typeof d.style=="undefined")d.style="";e={msg:b,time:d.time,nick:a,chan:this.get("name"),type:c,style:d.style};if(!e)return;typeof e.type!="string"&&(e.type=""),typeof e.msg!="string"&&(e.msg=""),f=this.get("scrollback"),f.push(e),f.length>250&&f.splice(250),this.set({scrollback:f},{silent:!0}),this.trigger("msg",e)},close:function(){this.view.remove(),delete this.view;var a=this.get("members");a&&(a.reset([]),this.unset("members")),this.destroy(),this.cid===b.app.panels.active.cid&&b.app.panels.server.view.show()},isChannel:function(){var a=b.gateway.get("channel_prefix"),c=this.get("name");return c?a.indexOf(c[0])>-1:!1}}),b.model.PanelList=Backbone.Collection.extend({model:b.model.Panel,active:null,comparator:function(a){return a.get("name")},initialize:function(){this.view=new b.view.Tabs({el:$("#toolbar .panellist")[0],model:this}),this.add(new b.model.Server({name:b.gateway.get("name")})),this.server=this.getByName(b.gateway.get("name")),this.bind("active",function(a){this.active=a},this)},getByName:function(a){if(typeof a!="string")return;return this.find(function(b){return a.toLowerCase()===b.get("name").toLowerCase()})}}),b.model.Channel=b.model.Panel.extend({initialize:function(a){var c=this.get("name")||"",d;this.view=new b.view.Channel({model:this,name:c}),this.set({members:new b.model.MemberList,name:c,scrollback:[],topic:""},{silent:!0}),d=this.get("members"),d.bind("add",function(a){this.addMsg(" ","--> "+a.displayNick(!0)+" has joined","action join")},this),d.bind("remove",function(a,b,c){var d=c.message?"("+c.message+")":"";c.type==="quit"?this.addMsg(" ","<-- "+a.displayNick(!0)+" has quit "+d,"action quit"):c.type==="kick"?this.addMsg(" ","<-- "+a.displayNick(!0)+" was kicked by "+c.by+" "+d,"action kick"):this.addMsg(" ","<-- "+a.displayNick(!0)+" has left "+d,"action part")},this)}}),b.model.Server=b.model.Panel.extend({server_login:null,initialize:function(a){var c="Server";this.view=new b.view.Panel({model:this,name:c}),this.set({scrollback:[],name:c},{silent:!0}),this.server_login=new b.view.ServerSelect,this.view.$el.append(this.server_login.$el),this.server_login.show()}}),typeof String.prototype.trim=="undefined"&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),typeof String.prototype.lpad=="undefined"&&(String.prototype.lpad=function(a,b){var c="",d;for(d=0;d';return''+c+'
    '}),a):a}},{name:"html_safe",onaddmsg:function(a,b){return a.msg=$("
    ").text(a.msg).html(),a.nick=$("
    ").text(a.nick).html(),a}},{name:"activity",onaddmsg:function(a,b){return a}},{name:"highlight",onaddmsg:function(a,b){return a}},{name:"linkify_plain",onaddmsg:function(a,b){return a.msg?(a.msg=a.msg.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,function(a){var b;return a.match(/(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/)?a:(b=a,a.match("^https?://")?b=a:a="http://"+a,''+b+"")}),a):a}},{name:"lftobr",onaddmsg:function(a,b){return a.msg?(a.msg=a.msg.replace(/\n/gi,function(a){return"
    "}),a):a}},{name:"nick_colour",onaddmsg:function(a,b){if(!a.msg)return a;var c=this.randColour();return a.nick=''+a.nick+"",a},randColour:function(){var a=this.rand(-250,0),b=this.rand(30,100),c=this.rand(20,70);return"hsl("+a+","+b+"%,"+c+"%)"},rand:function(a,b){return parseInt(Math.random()*(b-a+1),10)+a}},{name:"kiwitest",oninit:function(a,b){console.log("registering namespace"),$(gateway).bind("kiwi.lol.browser",function(a,b){console.log("YAY kiwitest"),console.log(b)})}}];b.plugs={},b.plugs.loaded={},b.plugs.loadPlugin=function(a){var c;return typeof a.name!="string"?!1:(c=b.plugs.run("plugin_load",{plugin:a}),typeof c=="object"&&(b.plugs.loaded[c.plugin.name]=c.plugin,b.plugs.loaded[c.plugin.name].local_data=new b.dataStore("kiwi_plugin_"+c.plugin.name)),b.plugs.run("init",{},{run_only:c.plugin.name}),!0)},b.plugs.unloadPlugin=function(a){if(typeof b.plugs.loaded[a]!="object")return;b.plugs.run("unload",{},{run_only:a}),delete b.plugs.loaded[a]},b.plugs.run=function(a,c,d){var e=c,f,g;c=typeof c=="undefined"?{}:c,d=typeof d=="undefined"?{}:d;for(g in b.plugs.loaded){if(typeof d.run_only=="string"&&d.run_only!==g)continue;if(typeof b.plugs.loaded[g]["on"+a]=="function")try{f=b.plugs.loaded[g]["on"+a](e,d);if(f===null)return null;e=f;if(typeof e.event_bubbles=="boolean"&&e.event_bubbles===!1)return delete e.event_bubbles,e}catch(h){}}return e},b.dataStore=function(a){var b=a;this.get=function(b){return $.jStorage.get(a+"_"+b)},this.set=function(b,c){return $.jStorage.set(a+"_"+b,c)}},b.data=new b.dataStore("kiwi"),function(b){function j(){if("localStorage"in a)try{a.localStorage&&(d=a.localStorage,i="localStorage")}catch(b){}else if("globalStorage"in a)try{a.globalStorage&&(d=a.globalStorage[a.location.hostname],i="globalStorage")}catch(c){}else{e=document.createElement("link");if(!e.addBehavior){e=null;return}e.style.behavior="url(#default#userData)",document.getElementsByTagName("head")[0].appendChild(e),e.load("jStorage");var f="{}";try{f=e.getAttribute("jStorage")}catch(g){}d.jStorage=f,i="userDataBehavior"}k()}function k(){if(d.jStorage)try{c=h(String(d.jStorage))}catch(a){d.jStorage="{}"}else d.jStorage="{}";f=d.jStorage?String(d.jStorage).length:0}function l(){try{d.jStorage=g(c),e&&(e.setAttribute("jStorage",d.jStorage),e.save("jStorage")),f=d.jStorage?String(d.jStorage).length:0}catch(a){}}function m(a){if(!a||typeof a!="string"&&typeof a!="number")throw new TypeError("Key name must be string or numeric");return!0}if(!b||!(b.toJSON||Object.toJSON||a.JSON))throw new Error("jQuery, MooTools or Prototype needs to be loaded before jStorage!");var c={},d={jStorage:"{}"},e=null,f=0,g=b.toJSON||Object.toJSON||a.JSON&&(JSON.encode||JSON.stringify),h=b.evalJSON||a.JSON&&(JSON.decode||JSON.parse)||function(a){return String(a).evalJSON()},i=!1;_XMLService={isXML:function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1},encode:function(a){if(!this.isXML(a))return!1;try{return(new XMLSerializer).serializeToString(a)}catch(b){try{return a.xml}catch(c){}}return!1},decode:function(b){var c="DOMParser"in a&&(new DOMParser).parseFromString||a.ActiveXObject&&function(a){var b=new ActiveXObject("Microsoft.XMLDOM");return b.async="false",b.loadXML(a),b},d;return c?(d=c.call("DOMParser"in a&&new DOMParser||a,b,"text/xml"),this.isXML(d)?d:!1):!1}},b.jStorage={version:"0.1.5.1",set:function(a,b){return m(a),_XMLService.isXML(b)&&(b={_is_xml:!0,xml:_XMLService.encode(b)}),c[a]=b,l(),b},get:function(a,b){return m(a),a in c?c[a]&&typeof c[a]=="object"&&c[a]._is_xml&&c[a]._is_xml?_XMLService.decode(c[a].xml):c[a]:typeof b=="undefined"?null:b},deleteKey:function(a){return m(a),a in c?(delete c[a],l(),!0):!1},flush:function(){return c={},l(),!0},storageObj:function(){function a(){}return a.prototype=c,new a},index:function(){var a=[],b;for(b in c)c.hasOwnProperty(b)&&a.push(b);return a},storageSize:function(){return f},currentBackend:function(){return i},storageAvailable:function(){return!!i},reInit:function(){var a,b;if(e&&e.addBehavior){a=document.createElement("link"),e.parentNode.replaceChild(a,e),e=a,e.style.behavior="url(#default#userData)",document.getElementsByTagName("head")[0].appendChild(e),e.load("jStorage"),b="{}";try{b=e.getAttribute("jStorage")}catch(c){}d.jStorage=b,i="userDataBehavior"}k()}},j()}(a.jQuery||a.$),b.view={},b.view.MemberList=Backbone.View.extend({tagName:"ul",events:{"click .nick":"nickClick"},initialize:function(a){this.model.bind("all",this.render,this),$(this.el).appendTo("#memberlists")},render:function(){var a=$(this.el);a.empty(),this.model.forEach(function(b){$('
  • '+b.get("prefix")+""+b.get("nick")+"
  • ").appendTo(a).data("member",b)})},nickClick:function(a){var c=$(a.currentTarget).parent("li"),d=c.data("member"),e=new b.view.UserBox;e.member=d,$(".userbox",this.$el).remove(),c.append(e.$el)},show:function(){$("#memberlists").children().removeClass("active"),$(this.el).addClass("active")}}),b.view.UserBox=Backbone.View.extend({member:{},events:{"click .query":"queryClick","click .info":"infoClick"},initialize:function(){this.$el=$($("#tmpl_userbox").html())},queryClick:function(a){var c=new b.model.Channel({name:this.member.get("nick")});b.app.panels.add(c),c.view.show()},infoClick:function(a){b.gateway.raw("WHOIS "+this.member.get("nick"))}}),b.view.ServerSelect=Backbone.View.extend({events:{"submit form":"submitLogin","click .show_more":"showMore"},initialize:function(){this.$el=$($("#tmpl_server_select").html()),b.gateway.bind("onconnect",this.networkConnected,this),b.gateway.bind("connecting",this.networkConnecting,this)},submitLogin:function(a){var b={nick:$(".nick",this.$el).val(),server:$(".server",this.$el).val(),port:$(".port",this.$el).val(),ssl:$(".ssl",this.$el).prop("checked"),password:$(".password",this.$el).val(),channel:$(".channel",this.$el).val()};return this.trigger("server_connect",b),!1},showMore:function(a){$(".more",this.$el).slideDown("fast")},populateFields:function(a){var b,c,d;a=a||{},b=a.nick||"",c=a.server||"",port=a.port||6667,ssl=a.ssl||0,password=a.password||"",d=a.channel||"",$(".nick",this.$el).val(b),$(".server",this.$el).val(c),$(".port",this.$el).val(port),$(".ssl",this.$el).prop("checked",ssl),$(".password",this.$el).val(password),$(".channel",this.$el).val(d)},hide:function(){this.$el.slideUp()},show:function(){this.$el.show(),$(".nick",this.$el).focus()},setStatus:function(a,b){$(".status",this.$el).text(a).attr("class","status").addClass(b).show()},clearStatus:function(){$(".status",this.$el).hide()},networkConnected:function(a){this.setStatus("Connected :)","ok"),$("form",this.$el).hide()},networkConnecting:function(a){this.setStatus("Connecting..","ok")},showError:function(a){this.setStatus("Error connecting","error"),$("form",this.$el).show()}}),b.view.Panel=Backbone.View.extend({tagName:"div",className:"messages",events:{"click .chan":"chanClick"},$container:null,initialize:function(a){this.initializePanel(a)},initializePanel:function(a){this.$el.css("display","none"),a.container?this.$container=$(a.container):this.$container=$("#panels .container1"),this.$el.appendTo(this.$container),this.model.bind("msg",this.newMsg,this),this.msg_count=0,this.model.set({view:this},{silent:!0})},render:function(){this.$el.empty(),this.model.get("backscroll").forEach(this.newMsg)},newMsg:function(a){var c,d,e=this.$el,h;a.msg=$("
    ").text(a.msg).html(),c=new RegExp("\\B(["+b.gateway.get("channel_prefix")+"][^ ,.\\007]+)","g"),a.msg=a.msg.replace(c,function(a){return''+a+""}),a.msg=a.msg.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]*))?/gi,function(a){var b;return a.match(/^www\./)&&(a="http://"+a),b=a,b.length>100&&(b=b.substr(0,100)+"..."),''+b+""}),a.msg=g(a.msg),h=function(a){var b=0,c;return _.map(a.split(""),function(a){b+=a.charCodeAt(0)}),c=f(b%255,70,35),c=c[2]|c[1]<<8|c[0]<<16,"#"+c.toString(16)}(a.nick),a.nick_style="color:"+h+";",d='
    <%- time %>
    <%- nick %>
    <%= msg %>
    ',e.append(_.template(d,a)),this.scrollToBottom(),this.msg_count++,this.msg_count>250&&($(".msg:first",this.div).remove(),this.msg_count--)},chanClick:function(a){b.gateway.join($(a.srcElement).text())},show:function(){var a=this.$el;this.$container.children().css("display","none"),a.css("display","block");var c=this.model.get("members");c?(c.view.show(),this.$container.parent().css("right","200px")):($("#memberlists").children().removeClass("active"),this.$container.parent().css("right","0")),this.scrollToBottom(),this.trigger("active",this.model),b.app.panels.trigger("active",this.model)},scrollToBottom:function(){this.$container[0].scrollTop=this.$container[0].scrollHeight}}),b.view.Channel=b.view.Panel.extend({initialize:function(a){this.initializePanel(a),this.model.bind("change:topic",this.topic,this)},topic:function(a){if(typeof a!="string"||!a)a=this.model.get("topic");this.model.addMsg("","=== Topic for "+this.model.get("name")+" is: "+a,"topic"),b.app.panels.active===this&&b.app.topicbar.setCurrentTopic(this.model.get("topic"))}}),b.view.Tabs=Backbone.View.extend({events:{"click li":"tabClick","click li img":"partClick"},initialize:function(){this.model.on("add",this.panelAdded,this),this.model.on("remove",this.panelRemoved,this),this.model.on("reset",this.render,this),this.model.on("active",this.panelActive,this),b.gateway.on("change:name",function(a,b){$("span",this.model.server.tab).text(b)},this)},render:function(){var a=this;this.$el.empty(),this.model.server.tab.data("panel_id",this.model.server.cid).appendTo(this.$el),this.model.forEach(function(b){if(b==a.model.server)return;b.tab.data("panel_id",b.cid).appendTo(this.$el)})},panelAdded:function(a){a.tab=$("
  • "+a.get("name")+"
  • "),a.tab.data("panel_id",a.cid).appendTo(this.$el)},panelRemoved:function(a){a.tab.remove(),delete a.tab},panelActive:function(a){$("img",this.$el).remove(),this.$el.children().removeClass("active"),a.tab.addClass("active"),a.tab.append('')},tabClick:function(a){var b=$(a.currentTarget),c=this.model.getByCid(b.data("panel_id"));if(!c)return;c.view.show()},partClick:function(a){var c=$(a.currentTarget).parent(),d=this.model.getByCid(c.data("panel_id"));d.isChannel()?b.gateway.part(d.get("name")):d.close()},next:function(){var a=b.app.panels.active.tab.next();a.length||(a=$("li:first",this.$el)),a.click()},prev:function(){var a=b.app.panels.active.tab.prev();a.length||(a=$("li:last",this.$el)),a.click()}}),b.view.TopicBar=Backbone.View.extend({events:{"keydown input":"process"},initialize:function(){b.app.panels.bind("active",function(a){this.setCurrentTopic(a.get("topic"))},this)},process:function(a){var c=$(a.currentTarget),d=c.val();if(a.keyCode!==13)return;b.app.panels.active.isChannel()&&b.gateway.topic(b.app.panels.active.get("name"),d)},setCurrentTopic:function(a){a=a||"",a=$("
    ").html(g(a)),$("input",this.$el).val(a.text())}}),b.view.ControlBox=Backbone.View.extend({buffer:[],buffer_pos:0,tabcomplete:{active:!1,data:[],prefix:""},events:{"keydown input":"process"},initialize:function(){var a=this;b.gateway.bind("change:nick",function(){$(".nick",a.$el).text(this.get("nick"))})},process:function(a){var c=this,d=$(a.currentTarget),e=d.val(),f;navigator.appVersion.indexOf("Mac")!==-1?f=a.ctrlKey:f=a.altKey,this.tabcomplete.active&&a.keyCode!==9&&(this.tabcomplete.active=!1,this.tabcomplete.data=[],this.tabcomplete.prefix="");switch(!0){case a.keyCode===13:e=e.trim(),e&&(this.processInput(d.val()),this.buffer.push(d.val()),this.buffer_pos=this.buffer.length),d.val("");break;case a.keyCode===38:this.buffer_pos>0&&(this.buffer_pos--,d.val(this.buffer[this.buffer_pos]));break;case a.keyCode===40:this.buffer_pos0&&(f=d[0].selectionStart-i.length,b=e.substr(0,f),g=this.tabcomplete.data.shift(),this.tabcomplete.data.push(g),b+=g,b+=e.substr(d[0].selectionStart),d.val(b),d[0].setSelectionRange?d[0].setSelectionRange(f+g.length,f+g.length):d[0].createTextRange&&(h=d[0].createTextRange(),h.collapse(!0),h.moveEnd("character",f+g.length),h.moveStart("character",f+g.length),h.select()))}.apply(this),!1}},processInput:function(a){var c,d=a.split(" ");d[0][0]==="/"?(c=d[0].substr(1).toLowerCase(),d=d.splice(1)):(c="msg",d.unshift(b.app.panels.active.get("name"))),this.trigger("command",{command:c,params:d}),this.trigger("command_"+c,{command:c,params:d}),this._callbacks["command_"+c]||this.trigger("unknown_command",{command:c,params:d})}}),b.view.StatusMessage=Backbone.View.extend({tmr:null,initialize:function(){this.$el.hide()},text:function(a,c){c=c||{},c.type=c.type||"",this.$el.text(a).attr("class",c.type),this.$el.slideDown(b.app.view.doLayout),c.timeout&&this.doTimeout(c.timeout)},html:function(a,c){c=c||{},c.type=c.type||"",this.$el.html(text).attr("class",c.type),this.$el.slideDown(b.app.view.doLayout),c.timeout&&this.doTimeout(c.timeout)},hide:function(){this.$el.slideUp(b.app.view.doLayout)},doTimeout:function(a){this.tmr&&clearTimeout(this.tmr);var b=this;this.tmr=setTimeout(function(){b.hide()},a)}}),b.view.Application=Backbone.View.extend({initialize:function(){$(a).resize(this.doLayout),$("#toolbar").resize(this.doLayout),$("#controlbox").resize(this.doLayout),this.doLayout(),$(document).keydown(this.setKeyFocus)},setKeyFocus:function(a){if(a.ctrlKey||a.altKey)return;if(a.target.tagName.toLowerCase()==="input")return;$("#controlbox .inp").focus()},doLayout:function(){var a=$("#panels"),b=$("#memberlists"),c=$("#toolbar"),d=$("#controlbox"),e={top:c.outerHeight(!0),bottom:d.outerHeight(!0)};a.css(e),b.css(e)},barsHide:function(a){var b=this;a?($("#toolbar").slideUp(0),$("#controlbox").slideUp(0)):($("#toolbar").slideUp(),$("#controlbox").slideUp(function(){b.doLayout()}))},barsShow:function(a){var b=this;a?($("#toolbar").slideDown(0),$("#controlbox").slideDown(0),this.doLayout()):($("#toolbar").slideDown(),$("#controlbox").slideDown(function(){b.doLayout()}))}})})(window) \ No newline at end of file