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
1 lines
8.3 KiB
!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.expand())},toggleUserList:function(){u.is(":animated")||(r.hasClass(l.active)?(r.removeClass("active"),j.user.list.hide()):(r.addClass(l.active),j.user.list.show()))}},utils:{emptyString:function(a){return"string"==typeof a?-1==a.search(/\S/):!1}},setting:function(b,c){return c===d?k[b]:(a.isPlainObject(b)?a.extend(!0,k,b):k[b]=c,void 0)},internal:function(b,c){return c===d?j[b]:(a.isPlainObject(b)?a.extend(!0,j,b):j[b]=c,void 0)},debug:function(){k.debug&&(k.performance?j.performance.log(arguments):(j.debug=Function.prototype.bind.call(console.info,console,k.name+":"),j.debug.apply(console,arguments)))},verbose:function(){k.verbose&&k.debug&&(k.performance?j.performance.log(arguments):(j.verbose=Function.prototype.bind.call(console.info,console,k.name+":"),j.verbose.apply(console,arguments)))},error:function(){j.error=Function.prototype.bind.call(console.error,console,k.name+":"),j.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;k.performance&&(b=(new Date).getTime(),d=time||b,c=b-d,time=b,performance.push({Element:element,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":c})),clearTimeout(j.performance.timer),j.performance.timer=setTimeout(j.performance.display,100)},display:function(){var b=k.name+":",c=0;time=!1,clearTimeout(j.performance.timer),a.each(performance,function(a,b){c+=b["Execution Time"]}),b+=" "+c+"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&&x!==d&&(b=b.split(/[\. ]/),f=b.length-1,a.each(b,function(b,c){a.isPlainObject(x[c])&&b!=f?x=x[c]:x[c]!==d?g=x[c]:j.error(o.method)})),a.isFunction(g)?g.apply(e,c):g||!1}},methodInvoked?(x===d&&j.initialize(),j.invoke(query)):(x!==d&&j.destroy(),j.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);
|