From 6168523a1c1ecc37b7481dd83646597553f6caf4 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 9 May 2013 12:05:39 -0400 Subject: [PATCH] Refactor callbacks --- www/assets/js/callbacks.js | 482 ++++++++++++++++++++++++++++--------- www/assets/js/client.js | 36 +-- www/assets/js/functions.js | 299 ----------------------- 3 files changed, 386 insertions(+), 431 deletions(-) diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index ffc98b69..8d56afa6 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -1,72 +1,176 @@ -/* -The MIT License (MIT) -Copyright (c) 2013 Calvin Montgomery +Callbacks = { -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -// Wrapped in a function so I can ensure that the socket -// is defined before these statements are run -function initCallbacks() { - /* REGION Globals */ - - socket.on("disconnect", function() { - handleDisconnect(); - }); - - socket.on("announcement", function(data) { - showAnnouncement(data.title, data.text); - }); - - /* REGION Channel Meta */ - socket.on("kick", function(data) { - KICKED = true; - $("
") - .addClass("server-msg-disconnect") - .text("Kicked: " + data.reason) + connect: function() { + socket.emit("joinChannel", { + name: CHANNEL + }); + if(uname && session) { + socket.emit("login", { + name: uname, + session: session + }); + } + $("
").addClass("server-msg-reconnect") + .text("Connected") .appendTo($("#messagebuffer")); $("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight")); - }); + }, - socket.on("noflood", function(data) { + disconnect: function() { + if(KICKED) + return; + $("
") + .addClass("server-msg-disconnect") + .text("Disconnected from server. Attempting reconnection...") + .appendTo($("#messagebuffer")); + $("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight")); + }, + + announcement: function(data) { + var div = $("
").addClass("alert") + .insertAfter($(".row")[0]); + $("