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;d
<a
;d
++)e
=Math
.floor(Math
.random()*b
.length
),c
+=b
.substring(e
,e
+1);return c
}function e(a
){var b
,c
,d
,e
,f
,g
;return b
=Math
.floor(a
/3600),e=a%3600,c=Math.floor(e/60),f
=e
%60,d
=Math
.ceil(f
),g
={h
:b
,m
:c
,s
:d
},g
}function f(a
,b
,c
){var d
,e
,f
,g
,h
,i
;b
/=100,c/=100;if(b
==0)g
=h
=i
=c
*255;else{function j(a
,b
,c
){var d
;return c
<0?c
+=1:c
>1&&(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
="<b>";while(a
.indexOf(String
.fromCharCode(2))!==-1)a
=a
.replace(String
.fromCharCode(2),c
),c
=c
==="<b>"?"</b>":"<b>";c
==="</b>"&&(a
+="</b>")}if(a
.indexOf(String
.fromCharCode(31))!==-1){c
="<u>";while(a
.indexOf(String
.fromCharCode(31))!==-1)a
=a
.replace(String
.fromCharCode(31),c
),c
=c
==="<u>"?"</u>":"<u>";c
==="</u>"&&(a
+="</u>")}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("\ 3")!==-1){e
=a
.indexOf("\ 3"),b
=a
.substr(0,e
);while(e
<a
.length
)f
=c(a
.substr(e
,6)),f
?(g
=a
.indexOf("\ 3",e
+1),h
=a
.indexOf(String
.fromCharCode(15),e
+1),h
!==-1&&(g
===-1?g
=h
:g
=g
<h
?g
:h
),g
===-1&&(g
=a
.length
),i
=d(f
[1]),j
=d(f
[3]),k
=a
.substring(e
+1+f
[1].length
+(j
!==null?f
[2].length
+1:0),g
),b
+='<span style="'+(i
!==null?"color: "+i
+"; ":"")+(j
!==null?"background-color: "+j
+";":"")+'">'+k
+"</span>",e
=g
):(a
[e
]!=="\ 3"&&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;f<g.length;f++)g[f].mode===a&&(d=f);for(f=0;f<g.length;f++)g[f].mode===c&&(e=f);return d<e?-1:d>e?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;e<a.length;e++)for(f=0;f<g.length;f++)if(a.charAt(e)===g[f].symbol){d++;break}return c.substr(d)},displayNick:function(a){var b=this.get("nick
");return a&&this.get("ident
")&&(b+=" ["+this.get("ident
")+"@"+this.get("hostname
")+"]"),b}}),b.model.MemberList=Backbone.Collection.extend({model:b.model.Member,comparator:function(a,c){var d,e,f,g,h,i,j,k=b.gateway.get("user_prefixes
");e=a.get("modes
"),f=c.get("modes
");if(e.length>0){if(f.length===0)return-1;g=h=-1;for(d=0;d<k.length;d++)k[d].mode===e[0]&&(g=d);for(d=0;d<k.length;d++)k[d].mode===f[0]&&(h=d);if(g<h)return-1;if(g>h)return 1}else if(f.length>0)return 1;return i=a.get("nick
").toLocaleUpperCase(),j=c.get("nick
").toLocaleUpperCase(),i<j?-1:i>j?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<a;d++)c+=b;return(c+this).slice(-a)});var h=[{name:"images",onaddmsg:function(a,b){return a.msg?(a.msg=a.msg.replace(/^((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/gi,function(b){a.event_bubbles=!1;var c='<img
class="link_img_a" src
="'+b+'" height
="100%" width
="100%" />';return'<a class="link_ext link_img" target="_blank" rel="nofollow" href="'+b+'" style="height:50px;width:50px;display:block">'+c+'<div class="tt box"></div></a>'}),a):a}},{name:"html_safe",onaddmsg:function(a,b){return a.msg=$("<div/>").text(a.msg).html(),a.nick=$("<div
/>").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
,'<a class="link_ext" target="_blank" rel="nofollow" href="'+a
+'">'+b
+"</a>")}),a
):a
}},{name
:"lftobr",onaddmsg:function(a
,b
){return a
.msg
?(a
.msg
=a
.msg
.replace(/\n/gi,function(a
){return"<br/>"}),a
):a
}},{name
:"nick_colour",onaddmsg:function(a
,b
){if(!a
.msg
)return a
;var c
=this.randColour();return a
.nick
='<span style="color:'+c
+';">'+a
.nick
+"</span>",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
){$('<li><a class="nick"><span class="prefix">'+b
.get("prefix")+"</span>"+b
.get("nick")+"</a></li>").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
=$("<div />").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 class="chan">'+a
+"</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)+"..."),'<a class="link_ext" target="_blank" rel="nofollow" href="'+a
+'">'+b
+"</a>"}),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
='<div class="msg <%= type %>"><div class="time"><%- time %></div><div class="nick" style="<%= nick_style %>"><%- nick %></div><div class="text" style="<%= style %>"><%= msg %> </div></div>',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
=$("<li><span>"+a
.get("name")+"</span></li>"),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('<img src="img/redcross.png" />')},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
=$("<div>").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_pos
<this.buffer
.length
&&(this.buffer_pos
++,d
.val(this.buffer
[this.buffer_pos
]));break;case a
.keyCode
===37&&f
:return b
.app
.panels
.view
.prev(),!1;case a
.keyCode
===39&&f
:return b
.app
.panels
.view
.next(),!1;case a
.keyCode
===9:this.tabcomplete
.active
=!0;if(_
.isEqual(this.tabcomplete
.data
,[])){var g
=[];$.each(b
.app
.panels
.active
.get("members").models
,function(a
,b
){if(!b
)return;g
.push(b
.get("nick"))}),g
=_
.sortBy(g
,function(a
){return a
}),this.tabcomplete
.data
=g
}if(e
[d
[0].selectionStart
-1]===" ")return!1;return function(){var a
=e
.substring(0,d
[0].selectionStart
).split(" "),b
,f
,g
,h
,i
=a
[a
.length
-1];this.tabcomplete
.prefix
===""&&(this.tabcomplete
.prefix
=i
),this.tabcomplete
.data
=_
.select(this.tabcomplete
.data
,function(a
){return a
.toLowerCase().indexOf(c
.tabcomplete
.prefix
.toLowerCase())===0}),this.tabcomplete
.data
.length
>0&&(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
)