`;
$('.append-menu').after(menuList);
$('.plugin-listing').append(htmlDOM);
pageLoad();
// Enable pusher logging - don't include this in production
//Pusher.logToConsole = true;
// Add API Key & cluster here to make the connection
var pusher = new Pusher(activeInfo.plugins.includes["CHAT-authKey-include"], {
cluster: activeInfo.plugins.includes["CHAT-cluster-include"],
encrypted: true
});
// Enter a unique channel you wish your users to be subscribed in.
var channel = pusher.subscribe('org_channel');
// bind the server event to get the response data and append it to the message div
channel.bind('my-event',
function(data) {
formatMessage(data);
$('.chat-list').append(formatMessage(data));
$('.custom-send').html('');
$(".chat-list").scrollTop($(".chat-list")[0].scrollHeight);
if($('#container-plugin-chat').hasClass('hidden')){
var chatSound = new Audio(activeInfo.plugins.includes["CHAT-newMessageSound-include"]);
chatSound.play();
message(data.username,data.message,activeInfo.settings.notifications.position,"#FFF","success","20000");
$('.profile-image').addClass('animated loop-animation rubberBand');
$('.chat-counter').removeClass('hidden').html(parseInt($('.chat-counter').text()) + 1);
}
});
// check if the user is subscribed to the above channel
channel.bind('pusher:subscription_succeeded', function(members) {
organizrConsole('Plugin Function','Chat Websocket Connected!');
organizrConsole('Plugin Function','Connecting to Organizr Chat DB');
getMessagesAndUsers(activeInfo.settings.homepage.refresh["CHAT-userRefreshTimeout"], true);
});
/*jslint browser: true*/
/*global $, jQuery, alert*/
$(document).ready(function () {
"use strict";
$('.chat-left-inner > .chatonline').slimScroll({
height: '100%',
position: 'right',
size: "0px",
color: '#dcdcdc'
});
$('.chat-list').slimScroll({
height: '100%',
position: 'right',
size: "0px",
color: '#dcdcdc',
start: 'bottom',
});
$(".open-panel").on("click", function () {
$(".chat-left-aside").toggleClass("open-pnl");
$(".open-panel i").toggleClass("ti-angle-left");
});
});
}
}
}
//Chat functions!
$(document).on('keypress', '.chat-input-send', function(ev) {
var keycode = (ev.keyCode ? ev.keyCode : ev.which);
if (keycode == '13') {
ev.preventDefault();
$('.custom-send-button').click();
}
});
// Send the Message enter by User
$('body').on('click', '.custom-send-button', function(e) {
e.preventDefault();
var message = $('.chat-input-send').val();
// Validate Name field
if (message !== '') {
organizrAPI2('POST','api/v2/plugins/chat/message',{ message : message }).success(function(data) {
// Nada yet
}).fail(function(xhr) {
console.error("Organizr Function: API Connection Failed");
});
// Clear the message input field
$('.chat-input-send').val('');
// Show a loading image while sending
$('.custom-send').html('');
}
});
function formatMessage(msg){
var className = 'odd';
if(msg.username == activeInfo.user.username){
if(activeInfo.user.username == 'Guest' && activeInfo.user.uid !== msg.uid){
className = '';
}
}else{
className = '';
}
return `