You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
8.3 KiB

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