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
7.5 KiB
1 lines
7.5 KiB
!function(a,b,c,d){a.fn.chat=function(b,c,e){var f=a.extend(!0,{},a.fn.chat.settings,e),g=arguments||!1;return a(this).each(function(){var e,h,i,j,k,l,m=a(this),n=m.find(f.selector.expandButton),o=m.find(f.selector.userListButton),p=m.find(f.selector.userList),q=(m.find(f.selector.room),m.find(f.selector.userCount)),r=m.find(f.selector.log),s=(m.find(f.selector.message),m.find(f.selector.messageInput)),t=m.find(f.selector.messageButton),u=m.data("module"),v=f.className,w=f.namespace,x="",y={};return l={channel:!1,width:{log:r.width(),userList:p.outerWidth()},initialize:function(){return Pusher===d&&l.error(f.errors.pusher),b===d||c===d?(l.error(f.errors.key),!1):f.endpoint.message||f.endpoint.authentication?(k=new Pusher(b),Pusher.channel_auth_endpoint=f.endpoint.authentication,l.channel=k.subscribe(c),l.channel.bind("pusher:subscription_succeeded",l.user.list.create),l.channel.bind("pusher:subscription_error",l.error),l.channel.bind("pusher:member_added",l.user.joined),l.channel.bind("pusher:member_removed",l.user.left),l.channel.bind("update_messages",l.message.receive),a.each(f.customEvents,function(a,b){l.channel.bind(a,b)}),a.fn.hoverClass!==d&&a.fn.downClass!==d&&(n.hoverClass().downClass(),o.hoverClass().downClass(),t.hoverClass().downClass()),o.on("click."+w,l.event.toggleUserList),n.on("click."+w,l.event.toggleExpand),s.on("keydown."+w,l.event.input.keydown).on("keyup."+w,l.event.input.keyup),t.on("mouseenter."+w,l.event.hover).on("mouseleave."+w,l.event.hover).on("click."+w,l.event.submit),r.animate({scrollTop:r.prop("scrollHeight")},400),m.data("module",l).addClass(v.loading),void 0):(l.error(f.errors.endpoint),!1)},refresh:function(){o.removeClass(v.active),l.width={log:r.width(),userList:p.outerWidth()},o.hasClass(v.active)&&l.user.list.hide(),m.data("module",l)},user:{updateCount:function(){f.userCount&&(y=m.data("users"),i=0,a.each(y,function(){i++}),q.html(f.templates.userCount(i)))},joined:function(b){y=m.data("users"),"anonymous"!=b.id&&y[b.id]===d&&(y[b.id]=b.info,f.randomColor&&b.info.color===d&&(b.info.color=f.templates.color(b.id)),x=f.templates.userList(b.info),b.info.isAdmin?a(x).prependTo(p).preview({type:"user",placement:"left"}):a(x).appendTo(p).preview({type:"user",placement:"left"}),a.fn.preview!==d&&p.children().last().preview({type:"user",placement:"left"}),f.partingMessages&&(r.append(f.templates.joined(b.info)),l.message.scroll.test()),l.user.updateCount())},left:function(a){y=m.data("users"),a!==d&&"anonymous"!==a.id&&(delete y[a.id],m.data("users",y),p.find("[data-id="+a.id+"]").remove(),f.partingMessages&&(r.append(f.templates.left(a.info)),l.message.scroll.test()),l.user.updateCount())},list:{create:function(b){y={},b.each(function(a){"anonymous"!==a.id&&"undefined"!==a.id&&(f.randomColor&&a.info.color===d&&(a.info.color=f.templates.color(a.id)),x=a.info.isAdmin?f.templates.userList(a.info)+x:x+f.templates.userList(a.info),y[a.id]=a.info)}),m.data("users",y).data("user",y[b.me.id]).removeClass(v.loading),p.html(x),a.fn.preview!==d&&p.children().preview({type:"user",placement:"left"}),l.user.updateCount(),a.proxy(f.onJoin,p.children())()},show:function(){r.animate({width:l.width.log-l.width.userList},{duration:f.speed,easing:f.easing,complete:l.message.scroll.move})},hide:function(){r.stop().animate({width:l.width.log},{duration:f.speed,easing:f.easing,complete:l.message.scroll.move})}}},message:{scroll:{test:function(){j=r.prop("scrollHeight")-r.height(),Math.abs(r.scrollTop()-j)<f.scrollArea&&l.message.scroll.move()},move:function(){j=r.prop("scrollHeight")-r.height(),r.scrollTop(j)}},send:function(b){l.utils.emptyString(b)||a.api({url:f.endpoint.message,method:"POST",data:{chat_message:{content:b,timestamp:(new Date).getTime()}}})},receive:function(a){h=a.data,y=m.data("users"),e=m.data("user"),y[h.userID]!==d&&(e===d||e.id!=h.userID)&&(h.user=y[h.userID],l.message.display(h))},display:function(b){r.append(f.templates.message(b)),l.message.scroll.test(),a.proxy(f.onMessage,r.children().last())()}},expand:function(){m.addClass(v.expand),a.proxy(f.onExpand,m)(),l.refresh()},contract:function(){m.removeClass(v.expand),a.proxy(f.onContract,m)(),l.refresh()},event:{input:{keydown:function(a){13==a.which&&t.addClass(v.down)},keyup:function(a){13==a.which&&(t.removeClass(v.down),l.event.submit())}},submit:function(){var a=s.val(),b=m.data("user");b===d||l.utils.emptyString(a)||(l.message.send(a),l.message.display({user:b,text:a}),l.message.scroll.move(),s.val(""))},toggleExpand:function(){m.hasClass(v.expand)?(n.removeClass(v.active),l.contract()):(n.addClass(v.active),l.expand())},toggleUserList:function(){r.is(":animated")||(o.hasClass(v.active)?(o.removeClass("active"),l.user.list.hide()):(o.addClass(v.active),l.user.list.show()))}},utils:{emptyString:function(a){return"string"==typeof a?-1==a.search(/\S/):!1}},debug:function(a){f.debug&&console.info(f.moduleName+": "+a)},error:function(a){console.warn(f.moduleName+": "+a)},invoke:function(b,c,e){var g;return e=e||Array.prototype.slice.call(arguments,2),"string"==typeof b&&u!==d&&(b=b.split("."),a.each(b,function(b,c){return a.isPlainObject(u[c])?(u=u[c],!0):a.isFunction(u[c])?(g=u[c],!0):(l.error(f.errors.method),!1)})),a.isFunction(g)?g.apply(c,e):!1}},u!==d&&g?("invoke"==g[0]&&(g=Array.prototype.slice.call(g,1)),l.invoke(g[0],this,Array.prototype.slice.call(g,1))):(l.initialize(),void 0)}),this},a.fn.chat.settings={moduleName:"Chat Module",debug:!1,namespace:"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},errors:{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 .button.user-list",expandButton:".actions .button.expand",room:".room",userList:".room .user-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);
|