/* * On-site Sock Chat client */ var Chat = { server: null, chatContainer: null, accessButtons: null, onlineList: null, connected: false, connect: function(server, force) { // Set server this.server = server; // Set required variables this.chatContainer = document.getElementById('chat'); this.accessButtons = document.getElementById('chatAccessButtons'); this.onlineList = document.getElementById('chatOnlineUsers'); // Check if we haven't already established a connection if(this.connected && !force) { this.accessButtons.innerHTML += ''; } // Attempt to connect to the server this.accessButtons.innerHTML = '
'; // Grab connection indicator var connectionIndicator = document.getElementById('chatConnecting'); setTimeout(function() { if(Chat.connected) { connectionIndicator.setAttribute('title', 'Connected!'); connectionIndicator.children[0].className = 'fa fa-chain'; var accessButtonsCont = ''; } else { connectionIndicator.setAttribute('title', 'Failed to connect, try again later!'); connectionIndicator.children[0].className = 'fa fa-chain-broken'; var accessButtonsCont = ''; } setTimeout(function() { Chat.accessButtons.innerHTML = accessButtonsCont; }, 500); }, 500); }, toggleOnlineList: function() { this.onlineList.className = this.onlineList.className != 'open' ? 'open' : ''; }, toggleTicker: function() { this.chatTicker.className = this.chatTicker.className != 'open' ? 'open' : ''; } };