/* * # Semantic UI * git://github.com/Semantic-Org/Semantic-UI.git#1.0 * * * Copyright 2014 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT * */ !function(e,n,t,s){"use strict";e.fn.chatroom=function(n){var t,o=e(this),a=o.selector||"",i=(new Date).getTime(),r=[],u=arguments[0],l="string"==typeof u,c=[].slice.call(arguments,1);return e(this).each(function(){var t,o,d,m,p,g,f,h=e.extend(!0,{},e.fn.chatroom.settings,n),v=h.className,C=h.namespace,y=h.selector,b=h.error,w=e(this),x=w.find(y.expandButton),k=w.find(y.userListButton),T=w.find(y.userList),L=(w.find(y.room),w.find(y.userCount)),E=w.find(y.log),A=(w.find(y.message),w.find(y.messageInput)),j=w.find(y.messageButton),P=w.data("module"),_=this,M="",B={};f={width:{log:E.width(),userList:T.outerWidth()},initialize:function(){return Pusher===s&&f.error(b.pusher),h.key===s||h.channelName===s?(f.error(b.key),!1):h.endpoint.message||h.endpoint.authentication?(g=new Pusher(h.key),Pusher.channel_auth_endpoint=h.endpoint.authentication,t=g.subscribe(h.channelName),t.bind("pusher:subscription_succeeded",f.user.list.create),t.bind("pusher:subscription_error",f.error),t.bind("pusher:member_added",f.user.joined),t.bind("pusher:member_removed",f.user.left),t.bind("update_messages",f.message.receive),e.each(h.customEvents,function(e,n){t.bind(e,n)}),k.on("click."+C,f.event.toggleUserList),x.on("click."+C,f.event.toggleExpand),A.on("keydown."+C,f.event.input.keydown).on("keyup."+C,f.event.input.keyup),j.on("mouseenter."+C,f.event.hover).on("mouseleave."+C,f.event.hover).on("click."+C,f.event.submit),E.animate({scrollTop:E.prop("scrollHeight")},400),void w.data("module",f).addClass(v.loading)):(f.error(b.endpoint),!1)},refresh:function(){k.removeClass(v.active),f.width={log:E.width(),userList:T.outerWidth()},k.hasClass(v.active)&&f.user.list.hide(),w.data("module",f)},user:{updateCount:function(){h.userCount&&(B=w.data("users"),m=0,e.each(B,function(){m++}),L.html(h.templates.userCount(m)))},joined:function(n){B=w.data("users"),"anonymous"!=n.id&&B[n.id]===s&&(B[n.id]=n.info,h.randomColor&&n.info.color===s&&(n.info.color=h.templates.color(n.id)),M=h.templates.userList(n.info),n.info.isAdmin?e(M).prependTo(T):e(M).appendTo(T),h.partingMessages&&(E.append(h.templates.joined(n.info)),f.message.scroll.test()),f.user.updateCount())},left:function(e){B=w.data("users"),e!==s&&"anonymous"!==e.id&&(delete B[e.id],w.data("users",B),T.find("[data-id="+e.id+"]").remove(),h.partingMessages&&(E.append(h.templates.left(e.info)),f.message.scroll.test()),f.user.updateCount())},list:{create:function(n){B={},n.each(function(e){"anonymous"!==e.id&&"undefined"!==e.id&&(h.randomColor&&e.info.color===s&&(e.info.color=h.templates.color(e.id)),M=e.info.isAdmin?h.templates.userList(e.info)+M:M+h.templates.userList(e.info),B[e.id]=e.info)}),w.data("users",B).data("user",B[n.me.id]).removeClass(v.loading),T.html(M),f.user.updateCount(),e.proxy(h.onJoin,T.children())()},show:function(){E.animate({width:f.width.log-f.width.userList},{duration:h.speed,easing:h.easing,complete:f.message.scroll.move})},hide:function(){E.stop().animate({width:f.width.log},{duration:h.speed,easing:h.easing,complete:f.message.scroll.move})}}},message:{scroll:{test:function(){p=E.prop("scrollHeight")-E.height(),Math.abs(E.scrollTop()-p)0&&(console.groupCollapsed(n),console.table?console.table(r):e.each(r,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),r=[]}},invoke:function(n,t,o){var a,i;return t=t||c,o=_||o,"string"==typeof n&&P!==s&&(n=n.split(/[\. ]/),a=n.length-1,e.each(n,function(t,o){e.isPlainObject(P[o])&&t!=a?P=P[o]:P[o]!==s?i=P[o]:f.error(b.method,n)})),e.isFunction(i)?i.apply(o,t):i||!1}},l?(P===s&&f.initialize(),f.invoke(u)):(P!==s&&f.destroy(),f.initialize())}),t!==s?t:this},e.fn.chatroom.settings={name:"Chat",namespace:"chat",debug:!1,channel:"present-chat",onJoin:function(){},onMessage:function(){},onExpand:function(){},onContract:function(){},customEvents:{},partingMessages:!1,userCount:!0,randomColor:!0,speed:300,easing:"easeOutQuint",scrollArea:9999,endpoint:{message:!1,authentication:!1},error:{method:"The method you called is not defined",endpoint:"Please define a message and authentication endpoint.",key:"You must specify a pusher key and channel.",pusher:"You must include the Pusher library."},className:{expand:"expand",active:"active",hover:"hover",down:"down",loading:"loading"},selector:{userCount:".actions .message",userListButton:".actions .list.button",expandButton:".actions .expand.button",room:".room",userList:".room .list",log:".room .log",message:".room .log .message",author:".room log .message .author",messageInput:".talk input",messageButton:".talk .send.button"},templates:{userCount:function(e){return e+" users in chat"},color:function(){var e=["#000000","#333333","#666666","#999999","#CC9999","#CC6666","#CC3333","#993333","#663333","#CC6633","#CC9966","#CC9933","#999966","#CCCC66","#99CC66","#669933","#669966","#33A3CC","#336633","#33CCCC","#339999","#336666","#336699","#6666CC","#9966CC","#333399","#663366","#996699","#993366","#CC6699"];return e[Math.floor(Math.random()*e.length)]},message:function(e){var n="";return e.user.isAdmin?(e.user.color="#55356A",n+='
',n+=''):n+='
',n+="

",n+=e.user.color!==s?''+e.user.name+": ":''+e.user.name+": ",n+=""+e.text+"

"},joined:function(e){return typeof e.name!==s?'
'+e.name+" has joined the chat.
":!1},left:function(e){return typeof e.name!==s?'
'+e.name+" has left the chat.
":!1},userList:function(e){var n="";return e.isAdmin&&(e.color="#55356A"),n+='
',n+=e.color!==s?'

'+e.name+"

":'

'+e.name+"

",n+="
"}}}}(jQuery,window,document);