|
|
(function(e,t,n,a){e.fn.chat=function(t,n,o){var i=e.extend(!0,{},e.fn.chat.settings,o),s=arguments||!1;return e(this).each(function(){var o,r,l,c,u,d,f=e(this),m=f.find(i.selector.expandButton),p=f.find(i.selector.userListButton),g=f.find(i.selector.userList),h=(f.find(i.selector.room),f.find(i.selector.userCount)),v=f.find(i.selector.log),b=(f.find(i.selector.message),f.find(i.selector.messageInput)),y=f.find(i.selector.messageButton),x=f.data("module"),C=i.className,w=i.namespace,T="",k={};return d={channel:!1,width:{log:v.width(),userList:g.outerWidth()},initialize:function(){return Pusher===a&&d.error(i.errors.pusher),t===a||n===a?(d.error(i.errors.key),!1):i.endpoint.message||i.endpoint.authentication?(u=new Pusher(t),Pusher.channel_auth_endpoint=i.endpoint.authentication,d.channel=u.subscribe(n),d.channel.bind("pusher:subscription_succeeded",d.user.list.create),d.channel.bind("pusher:subscription_error",d.error),d.channel.bind("pusher:member_added",d.user.joined),d.channel.bind("pusher:member_removed",d.user.left),d.channel.bind("update_messages",d.message.receive),e.each(i.customEvents,function(e,t){d.channel.bind(e,t)}),e.fn.hoverClass!==a&&e.fn.downClass!==a&&(m.hoverClass().downClass(),p.hoverClass().downClass(),y.hoverClass().downClass()),p.on("click."+w,d.event.toggleUserList),m.on("click."+w,d.event.toggleExpand),b.on("keydown."+w,d.event.input.keydown).on("keyup."+w,d.event.input.keyup),y.on("mouseenter."+w,d.event.hover).on("mouseleave."+w,d.event.hover).on("click."+w,d.event.submit),v.animate({scrollTop:v.prop("scrollHeight")},400),f.data("module",d).addClass(C.loading),a):(d.error(i.errors.endpoint),!1)},refresh:function(){p.removeClass(C.active),d.width={log:v.width(),userList:g.outerWidth()},p.hasClass(C.active)&&d.user.list.hide(),f.data("module",d)},user:{updateCount:function(){i.userCount&&(k=f.data("users"),l=0,e.each(k,function(){l++}),h.html(i.templates.userCount(l)))},joined:function(t){k=f.data("users"),"anonymous"!=t.id&&k[t.id]===a&&(k[t.id]=t.info,i.randomColor&&t.info.color===a&&(t.info.color=i.templates.color(t.id)),T=i.templates.userList(t.info),t.info.isAdmin?e(T).prependTo(g).preview({type:"user",placement:"left"}):e(T).appendTo(g).preview({type:"user",placement:"left"}),e.fn.preview!==a&&g.children().last().preview({type:"user",placement:"left"}),i.partingMessages&&(v.append(i.templates.joined(t.info)),d.message.scroll.test()),d.user.updateCount())},left:function(e){k=f.data("users"),e!==a&&"anonymous"!==e.id&&(delete k[e.id],f.data("users",k),g.find("[data-id="+e.id+"]").remove(),i.partingMessages&&(v.append(i.templates.left(e.info)),d.message.scroll.test()),d.user.updateCount())},list:{create:function(t){k={},t.each(function(e){"anonymous"!==e.id&&"undefined"!==e.id&&(i.randomColor&&e.info.color===a&&(e.info.color=i.templates.color(e.id)),T=e.info.isAdmin?i.templates.userList(e.info)+T:T+i.templates.userList(e.info),k[e.id]=e.info)}),f.data("users",k).data("user",k[t.me.id]).removeClass(C.loading),g.html(T),e.fn.preview!==a&&g.children().preview({type:"user",placement:"left"}),d.user.updateCount(),e.proxy(i.onJoin,g.children())()},show:function(){v.animate({width:d.width.log-d.width.userList},{duration:i.speed,easing:i.easing,complete:d.message.scroll.move})},hide:function(){v.stop().animate({width:d.width.log},{duration:i.speed,easing:i.easing,complete:d.message.scroll.move})}}},message:{scroll:{test:function(){c=v.prop("scrollHeight")-v.height(),Math.abs(v.scrollTop()-c)<i.scrollArea&&d.message.scroll.move()},move:function(){c=v.prop("scrollHeight")-v.height(),v.scrollTop(c)}},send:function(t){d.utils.emptyString(t)||e.api({url:i.endpoint.message,method:"POST",data:{chat_message:{content:t,timestamp:(new Date).getTime()}}})},receive:function(e){r=e.data,k=f.data("users"),o=f.data("user"),k[r.userID]!==a&&(o===a||o.id!=r.userID)&&(r.user=k[r.userID],d.message.display(r))},display:function(t){v.append(i.templates.message(t)),d.message.scroll.test(),e.proxy(i.onMessage,v.children().last())()}},expand:function(){f.addClass(C.expand),e.proxy(i.onExpand,f)(),d.refresh()},contract:funct
|