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.
 
 
 

1 lines
8.3 KiB

!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),n.expand())},toggleUserList:function(){t.is(":animated")||(q.hasClass(e.active)?(q.removeClass("active"),n.user.list.hide()):(q.addClass(e.active),n.user.list.show()))}},utils:{emptyString:function(a){return"string"==typeof a?-1==a.search(/\S/):!1}},setting:function(b,e){return e===d?c[b]:(a.isPlainObject(b)?a.extend(!0,c,b):c[b]=e,void 0)},internal:function(b,c){return c===d?n[b]:(a.isPlainObject(b)?a.extend(!0,n,b):n[b]=c,void 0)},debug:function(){c.debug&&(c.performance?n.performance.log(arguments):(n.debug=Function.prototype.bind.call(console.info,console,c.name+":"),n.debug.apply(console,arguments)))},verbose:function(){c.verbose&&c.debug&&(c.performance?n.performance.log(arguments):(n.verbose=Function.prototype.bind.call(console.info,console,c.name+":"),n.verbose.apply(console,arguments)))},error:function(){n.error=Function.prototype.bind.call(console.error,console,c.name+":"),n.error.apply(console,arguments)},performance:{log:function(a){var b,d,e;c.performance&&(b=(new Date).getTime(),e=time||b,d=b-e,time=b,performance.push({Element:element,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":d})),clearTimeout(n.performance.timer),n.performance.timer=setTimeout(n.performance.display,100)},display:function(){var b=c.name+":",e=0;time=!1,clearTimeout(n.performance.timer),a.each(performance,function(a,b){e+=b["Execution Time"]}),b+=" "+e+"ms",moduleSelector&&(b+=" '"+moduleSelector+"'"),b+=" ("+$allDropdowns.size()+")",(console.group!==d||console.table!==d)&&performance.length>0&&(console.groupCollapsed(b),console.table?console.table(performance):a.each(performance,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),performance=[]}},invoke:function(b,c,e){var f,g;return c=c||queryArguments,e=element||e,"string"==typeof b&&w!==d&&(b=b.split(/[\. ]/),f=b.length-1,a.each(b,function(b,c){a.isPlainObject(w[c])&&b!=f?w=w[c]:w[c]!==d?g=w[c]:n.error(h.method)})),a.isFunction(g)?g.apply(e,c):g||!1}},methodInvoked?(w===d&&n.initialize(),invokedResponse=n.invoke(query)):(w!==d&&n.destroy(),n.initialize())}),invokedResponse?invokedResponse:this},a.fn.chatroom.settings={name:"Chat",debug:!1,namespace:"chat",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(a){return a+" users in chat"},color:function(){var a=["#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 a[Math.floor(Math.random()*a.length)]},message:function(a){var b="";return a.user.isAdmin?(a.user.color="#55356A",b+='<div class="admin message">',b+='<span class="quirky ui flag team"></span>'):b+='<div class="message">',b+="<p>",b+=a.user.color!==d?'<span class="author" style="color: '+a.user.color+';">'+a.user.name+"</span>: ":'<span class="author">'+a.user.name+"</span>: ",b+=""+a.text+" </p>"+"</div>"},joined:function(a){return typeof a.name!==d?'<div class="status">'+a.name+" has joined the chat.</div>":!1},left:function(a){return typeof a.name!==d?'<div class="status">'+a.name+" has left the chat.</div>":!1},userList:function(a){var b="";return a.isAdmin&&(a.color="#55356A"),b+='<div class="user" data-id="'+a.id+'">'+' <div class="image">'+' <img src="'+a.avatarURL+'">'+" </div>",b+=a.color!==d?' <p><a href="/users/'+a.id+'" target="_blank" style="color: '+a.color+';">'+a.name+"</a></p>":' <p><a href="/users/'+a.id+'" target="_blank">'+a.name+"</a></p>",b+="</div>"}}}}(jQuery,window,document);