Callbacks = { /* fired when socket connection completes */ connect: function() { HAS_CONNECTED_BEFORE = true; SOCKETIO_CONNECT_ERROR_COUNT = 0; $("#socketio-connect-error").remove(); socket.emit("joinChannel", { name: CHANNEL.name }); if (CHANNEL.opts.password) { socket.emit("channelPassword", CHANNEL.opts.password); } if (CLIENT.name && CLIENT.guest) { socket.emit("login", { name: CLIENT.name }); } $("
").addClass("server-msg-reconnect") .text("Connected") .appendTo($("#messagebuffer")); scrollChat(); stopQueueSpinner(null); }, disconnect: function() { if(KICKED) return; $("
") .addClass("server-msg-disconnect") .text("Disconnected from server.") .appendTo($("#messagebuffer")); scrollChat(); }, // Socket.IO error callback error: function (msg) { window.SOCKET_ERROR_REASON = reason; $("
") .addClass("server-msg-disconnect") .text("Unable to connect: " + msg) .appendTo($("#messagebuffer")); }, errorMsg: function(data) { if (data.alert) { alert(data.msg); } else { errDialog(data.msg); } }, costanza: function (data) { $("#costanza-modal").modal("hide"); var modal = makeModal(); modal.attr("id", "costanza-modal") .appendTo($("body")); var body = $("
").addClass("modal-body") .appendTo(modal.find(".modal-content")); $("").attr("src", "http://i0.kym-cdn.com/entries/icons/original/000/005/498/1300044776986.jpg") .appendTo(body); $("").text(data.msg).appendTo(body); modal.modal(); }, announcement: function(data) { // Suppress this announcement for people who have already closed it if (data.id && CyTube.ui.suppressedAnnouncementId && data.id === CyTube.ui.suppressedAnnouncementId) { return; } $("#announcements").html(""); var signature = "
\u2014" + data.from; var announcement = makeAlert(data.title, data.text + signature) .appendTo($("#announcements")); if (data.id) { announcement.find(".close").click(function suppressThisAnnouncement() { CyTube.ui.suppressedAnnouncementId = data.id; setOpt("suppressed_announcement_id", data.id); }); } }, kick: function(data) { KICKED = true; $("
").addClass("server-msg-disconnect") .text("Kicked: " + data.reason) .appendTo($("#messagebuffer")); scrollChat(); }, noflood: function(data) { $("
") .addClass("server-msg-disconnect") .text(data.action + ": " + data.msg) .appendTo($("#messagebuffer")); scrollChat(); }, spamFiltered: function(data) { var message = "Spam Filtered."; switch (data.reason) { case "NEW_USER_CHAT": message = "Your account is too new to chat in this channel. " + "Please wait a while and try again."; break; case "NEW_USER_CHAT_LINK": message = "Your account is too new to post links in this channel. " + "Please wait a while and try again."; break; } errDialog(message); }, needPassword: function (wrongpw) { var div = $("
"); $("").text("Channel Password") .appendTo(div); if (wrongpw) { $("
").appendTo(div); $("").addClass("text-error") .text("Wrong Password") .appendTo(div); } var pwbox = $("").addClass("form-control") .attr("type", "password") .appendTo(div); var submit = $("