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

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