2013-08-07 21:00:53 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
Copyright (c) 2013 Calvin Montgomery
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Callbacks = {
|
|
|
|
|
|
|
|
error: function (reason) {
|
2014-01-26 20:15:50 +00:00
|
|
|
window.SOCKET_ERROR_REASON = reason;
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* fired when socket connection completes */
|
|
|
|
connect: function() {
|
2014-01-06 01:42:09 +00:00
|
|
|
socket.emit("initChannelCallbacks");
|
2013-08-07 21:00:53 +00:00
|
|
|
socket.emit("joinChannel", {
|
|
|
|
name: CHANNEL.name
|
|
|
|
});
|
2014-01-19 02:18:00 +00:00
|
|
|
|
2013-11-25 22:20:15 +00:00
|
|
|
if (CHANNEL.opts.password) {
|
|
|
|
socket.emit("channelPassword", CHANNEL.opts.password);
|
|
|
|
}
|
2014-01-19 02:18:00 +00:00
|
|
|
|
|
|
|
if (CLIENT.name && CLIENT.guest) {
|
2013-08-07 21:00:53 +00:00
|
|
|
socket.emit("login", {
|
|
|
|
name: CLIENT.name
|
|
|
|
});
|
|
|
|
}
|
2014-01-19 02:18:00 +00:00
|
|
|
|
2013-08-07 21:00:53 +00:00
|
|
|
$("<div/>").addClass("server-msg-reconnect")
|
|
|
|
.text("Connected")
|
|
|
|
.appendTo($("#messagebuffer"));
|
2013-12-15 03:59:47 +00:00
|
|
|
scrollChat();
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
disconnect: function() {
|
|
|
|
if(KICKED)
|
|
|
|
return;
|
|
|
|
$("<div/>")
|
|
|
|
.addClass("server-msg-disconnect")
|
|
|
|
.text("Disconnected from server. Attempting reconnection...")
|
|
|
|
.appendTo($("#messagebuffer"));
|
|
|
|
scrollChat();
|
|
|
|
},
|
|
|
|
|
|
|
|
errorMsg: function(data) {
|
2013-10-17 04:22:37 +00:00
|
|
|
errDialog(data.msg);
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
2013-08-18 23:35:49 +00:00
|
|
|
costanza: function (data) {
|
|
|
|
hidePlayer();
|
|
|
|
$("#costanza-modal").modal("hide");
|
2013-12-15 03:59:47 +00:00
|
|
|
var modal = makeModal();
|
|
|
|
modal.attr("id", "costanza-modal")
|
2013-08-18 23:35:49 +00:00
|
|
|
.appendTo($("body"));
|
|
|
|
|
2013-12-15 03:59:47 +00:00
|
|
|
var body = $("<div/>").addClass("modal-body")
|
|
|
|
.appendTo(modal.find(".modal-content"));
|
2013-08-18 23:35:49 +00:00
|
|
|
$("<img/>").attr("src", "http://i0.kym-cdn.com/entries/icons/original/000/005/498/1300044776986.jpg")
|
|
|
|
.appendTo(body);
|
|
|
|
|
|
|
|
$("<strong/>").text(data.msg).appendTo(body);
|
2013-12-15 03:59:47 +00:00
|
|
|
hidePlayer();
|
2013-08-18 23:35:49 +00:00
|
|
|
modal.modal();
|
|
|
|
},
|
|
|
|
|
2013-08-07 21:00:53 +00:00
|
|
|
announcement: function(data) {
|
|
|
|
$("#announcements").html("");
|
|
|
|
makeAlert(data.title, data.text)
|
|
|
|
.appendTo($("#announcements"));
|
|
|
|
},
|
|
|
|
|
|
|
|
kick: function(data) {
|
|
|
|
KICKED = true;
|
|
|
|
$("<div/>").addClass("server-msg-disconnect")
|
|
|
|
.text("Kicked: " + data.reason)
|
|
|
|
.appendTo($("#messagebuffer"));
|
|
|
|
scrollChat();
|
|
|
|
},
|
|
|
|
|
|
|
|
noflood: function(data) {
|
|
|
|
$("<div/>")
|
|
|
|
.addClass("server-msg-disconnect")
|
|
|
|
.text(data.action + ": " + data.msg)
|
|
|
|
.appendTo($("#messagebuffer"));
|
|
|
|
scrollChat();
|
|
|
|
},
|
|
|
|
|
2013-11-25 22:20:15 +00:00
|
|
|
needPassword: function (wrongpw) {
|
|
|
|
var div = $("<div/>");
|
|
|
|
$("<strong/>").text("Channel Password")
|
|
|
|
.appendTo(div);
|
|
|
|
if (wrongpw) {
|
|
|
|
$("<br/>").appendTo(div);
|
|
|
|
$("<span/>").addClass("text-error")
|
|
|
|
.text("Wrong Password")
|
|
|
|
.appendTo(div);
|
|
|
|
}
|
|
|
|
|
2013-12-15 03:59:47 +00:00
|
|
|
var pwbox = $("<input/>").addClass("form-control")
|
2013-11-25 22:20:15 +00:00
|
|
|
.attr("type", "password")
|
|
|
|
.appendTo(div);
|
2013-12-15 03:59:47 +00:00
|
|
|
var submit = $("<button/>").addClass("btn btn-xs btn-default btn-block")
|
|
|
|
.css("margin-top", "5px")
|
2013-11-25 22:20:15 +00:00
|
|
|
.text("Submit")
|
|
|
|
.appendTo(div);
|
|
|
|
var parent = chatDialog(div);
|
|
|
|
parent.attr("id", "needpw");
|
|
|
|
var sendpw = function () {
|
2014-01-26 03:29:56 +00:00
|
|
|
socket.emit("channelPassword", pwbox.val());
|
2013-11-25 22:20:15 +00:00
|
|
|
parent.remove();
|
|
|
|
};
|
|
|
|
submit.click(sendpw);
|
|
|
|
pwbox.keydown(function (ev) {
|
|
|
|
if (ev.keyCode == 13) {
|
|
|
|
sendpw();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
pwbox.focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelNeedPassword: function () {
|
|
|
|
$("#needpw").remove();
|
|
|
|
},
|
|
|
|
|
2013-11-19 21:14:40 +00:00
|
|
|
chatCooldown: function (time) {
|
|
|
|
time = time + 200;
|
|
|
|
$("#chatline").css("color", "#ff0000");
|
|
|
|
if (CHATTHROTTLE && $("#chatline").data("throttle_timer")) {
|
|
|
|
clearTimeout($("#chatline").data("throttle_timer"));
|
|
|
|
}
|
|
|
|
CHATTHROTTLE = true;
|
|
|
|
$("#chatline").data("throttle_timer", setTimeout(function () {
|
|
|
|
CHATTHROTTLE = false;
|
|
|
|
$("#chatline").css("color", "");
|
|
|
|
}, time));
|
|
|
|
},
|
|
|
|
|
2013-08-07 21:00:53 +00:00
|
|
|
channelNotRegistered: function() {
|
|
|
|
var div = $("<div/>").addClass("alert alert-info")
|
|
|
|
.attr("id", "chregnotice")
|
|
|
|
.insertBefore($("#main"));
|
|
|
|
$("<button/>").addClass("close pull-right").html("×")
|
|
|
|
.appendTo(div)
|
|
|
|
.click(function() { div.remove(); });
|
|
|
|
$("<h3/>").text("This channel isn't registered").appendTo(div);
|
|
|
|
$("<button/>").addClass("btn btn-primary").text("Register it")
|
2013-09-06 03:54:30 +00:00
|
|
|
.attr("id", "chanregisterbtn")
|
2013-08-07 21:00:53 +00:00
|
|
|
.appendTo(div)
|
|
|
|
.click(function() {
|
2013-09-06 03:54:30 +00:00
|
|
|
$(this).attr("disabled", true)
|
|
|
|
.text("Registering...");
|
2013-08-07 21:00:53 +00:00
|
|
|
socket.emit("registerChannel");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
registerChannel: function(data) {
|
2013-09-06 03:54:30 +00:00
|
|
|
if ($("#chanregisterbtn").length > 0) {
|
|
|
|
$("#chanregisterbtn").text("Register it")
|
|
|
|
.attr("disabled", false);
|
|
|
|
}
|
2013-08-07 21:00:53 +00:00
|
|
|
if(data.success) {
|
|
|
|
$("#chregnotice").remove();
|
|
|
|
}
|
|
|
|
else {
|
2013-12-15 03:59:47 +00:00
|
|
|
makeAlert("Error", data.error, "alert-danger")
|
2013-08-07 21:00:53 +00:00
|
|
|
.insertAfter($("#chregnotice"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
unregisterChannel: function(data) {
|
|
|
|
if(data.success) {
|
|
|
|
alert("Channel unregistered");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert(data.error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setMotd: function(data) {
|
|
|
|
CHANNEL.motd = data.html;
|
|
|
|
CHANNEL.motd_text = data.motd;
|
2013-11-14 04:36:43 +00:00
|
|
|
if ($("#motdwrap").find(".motdeditor").length > 0) {
|
|
|
|
$("#motdwrap .motdeditor").val(CHANNEL.motd_text);
|
|
|
|
} else {
|
|
|
|
$("#motd").html(CHANNEL.motd);
|
|
|
|
}
|
2013-08-07 21:00:53 +00:00
|
|
|
$("#motdtext").val(CHANNEL.motd_text);
|
2013-10-03 03:26:28 +00:00
|
|
|
if(data.motd != "") {
|
|
|
|
$("#motdwrap").show();
|
2013-08-07 21:00:53 +00:00
|
|
|
$("#motd").show();
|
2013-12-15 03:59:47 +00:00
|
|
|
$("#togglemotd").find(".glyphicon-plus")
|
|
|
|
.removeClass("glyphicon-plus")
|
|
|
|
.addClass("glyphicon-minus");
|
2013-10-03 03:26:28 +00:00
|
|
|
}
|
2013-08-07 21:00:53 +00:00
|
|
|
else
|
2013-10-03 03:26:28 +00:00
|
|
|
$("#motdwrap").hide();
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
chatFilters: function(entries) {
|
2014-01-16 17:53:34 +00:00
|
|
|
var tbl = $("#cs-chatfilters table");
|
|
|
|
tbl.data("entries", entries);
|
|
|
|
formatCSChatFilterList();
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
2014-01-19 02:18:00 +00:00
|
|
|
updateChatFilter: function (f) {
|
|
|
|
var entries = $("#cs-chatfilters table").data("entries") || [];
|
|
|
|
var found = false;
|
|
|
|
for (var i = 0; i < entries.length; i++) {
|
|
|
|
if (entries[i].name === f.name) {
|
|
|
|
entries[i] = f;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
entries.push(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#cs-chatfilters table").data("entries", entries);
|
|
|
|
formatCSChatFilterList();
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteChatFilter: function (f) {
|
|
|
|
var entries = $("#cs-chatfilters table").data("entries") || [];
|
|
|
|
var found = false;
|
|
|
|
for (var i = 0; i < entries.length; i++) {
|
|
|
|
if (entries[i].name === f.name) {
|
|
|
|
entries[i] = f;
|
|
|
|
found = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found !== false) {
|
|
|
|
entries.splice(found, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#cs-chatfilters table").data("entries", entries);
|
|
|
|
formatCSChatFilterList();
|
|
|
|
},
|
|
|
|
|
2013-08-07 21:00:53 +00:00
|
|
|
channelOpts: function(opts) {
|
|
|
|
document.title = opts.pagetitle;
|
|
|
|
PAGETITLE = opts.pagetitle;
|
|
|
|
$("#chanexternalcss").remove();
|
|
|
|
if(opts.externalcss.trim() != "" && !USEROPTS.ignore_channelcss) {
|
|
|
|
$("<link/>")
|
|
|
|
.attr("rel", "stylesheet")
|
|
|
|
.attr("href", opts.externalcss)
|
|
|
|
.attr("id", "chanexternalcss")
|
|
|
|
.appendTo($("head"));
|
|
|
|
}
|
|
|
|
if(opts.externaljs.trim() != "" && !USEROPTS.ignore_channeljs) {
|
|
|
|
if(opts.externaljs != CHANNEL.opts.externaljs) {
|
|
|
|
$.getScript(opts.externaljs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CHANNEL.opts = opts;
|
|
|
|
|
|
|
|
if(opts.allow_voteskip)
|
|
|
|
$("#voteskip").attr("disabled", false);
|
|
|
|
else
|
|
|
|
$("#voteskip").attr("disabled", true);
|
|
|
|
handlePermissionChange();
|
|
|
|
},
|
|
|
|
|
|
|
|
setPermissions: function(perms) {
|
|
|
|
CHANNEL.perms = perms;
|
2014-01-20 18:16:30 +00:00
|
|
|
genPermissionsEditor();
|
2013-08-07 21:00:53 +00:00
|
|
|
handlePermissionChange();
|
|
|
|
},
|
|
|
|
|
|
|
|
channelCSSJS: function(data) {
|
|
|
|
$("#chancss").remove();
|
|
|
|
CHANNEL.css = data.css;
|
|
|
|
$("#csstext").val(data.css);
|
|
|
|
if(data.css && !USEROPTS.ignore_channelcss) {
|
|
|
|
$("<style/>").attr("type", "text/css")
|
|
|
|
.attr("id", "chancss")
|
|
|
|
.text(data.css)
|
|
|
|
.appendTo($("head"));
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#chanjs").remove();
|
|
|
|
CHANNEL.js = data.js;
|
|
|
|
$("#jstext").val(data.js);
|
|
|
|
|
|
|
|
if(data.js && !USEROPTS.ignore_channeljs) {
|
|
|
|
$("<script/>").attr("type", "text/javascript")
|
|
|
|
.attr("id", "chanjs")
|
|
|
|
.text(data.js)
|
|
|
|
.appendTo($("body"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
banlist: function(entries) {
|
2014-01-09 02:12:02 +00:00
|
|
|
var tbl = $("#cs-banlist table");
|
2014-01-09 23:43:07 +00:00
|
|
|
tbl.data("entries", entries);
|
|
|
|
formatCSBanlist();
|
2014-01-12 23:06:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
banlistRemove: function (data) {
|
|
|
|
var entries = $("#cs-banlist table").data("entries") || [];
|
|
|
|
var found = false;
|
|
|
|
for (var i = 0; i < entries.length; i++) {
|
|
|
|
if (entries[i].id === data.id) {
|
|
|
|
found = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found !== false) {
|
|
|
|
entries.splice(i, 1);
|
|
|
|
$("#cs-banlist table").data("entries", entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
formatCSBanlist();
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
recentLogins: function(entries) {
|
|
|
|
var tbl = $("#loginhistory table");
|
|
|
|
// I originally added this check because of a race condition
|
|
|
|
// Now it seems to work without but I don't trust it
|
|
|
|
if(!tbl.hasClass("table")) {
|
|
|
|
setTimeout(function() {
|
|
|
|
Callbacks.recentLogins(entries);
|
|
|
|
}, 100);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(tbl.children().length > 1) {
|
|
|
|
$(tbl.children()[1]).remove();
|
|
|
|
}
|
|
|
|
for(var i = 0; i < entries.length; i++) {
|
|
|
|
var tr = document.createElement("tr");
|
|
|
|
var name = $("<td/>").text(entries[i].name).appendTo(tr);
|
|
|
|
var aliases = $("<td/>").text(entries[i].aliases.join(", ")).appendTo(tr);
|
|
|
|
var time = new Date(entries[i].time).toTimeString();
|
|
|
|
$("<td/>").text(time).appendTo(tr);
|
|
|
|
|
|
|
|
$(tr).appendTo(tbl);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
channelRanks: function(entries) {
|
2014-01-09 02:12:02 +00:00
|
|
|
var tbl = $("#cs-chanranks table");
|
2014-01-09 23:16:09 +00:00
|
|
|
tbl.data("entries", entries);
|
|
|
|
formatCSModList();
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
2014-01-09 05:45:26 +00:00
|
|
|
channelRankFail: function (data) {
|
2014-01-09 23:16:09 +00:00
|
|
|
makeAlert("Error", data.msg, "alert-danger").insertAfter($("#cs-chanranks h4"));
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
readChanLog: function (data) {
|
|
|
|
var log = $("#chanlog_contents");
|
|
|
|
if(log.length == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(data.success) {
|
2013-11-16 05:55:35 +00:00
|
|
|
log.data("log", data.data);
|
2013-08-07 21:00:53 +00:00
|
|
|
log.text(data.data);
|
2013-11-16 05:56:25 +00:00
|
|
|
filterChannelLog();
|
2013-08-07 21:00:53 +00:00
|
|
|
} else {
|
|
|
|
log.text("Error reading channel log");
|
|
|
|
}
|
|
|
|
log.scrollTop(log.prop("scrollHeight"));
|
|
|
|
},
|
|
|
|
|
|
|
|
voteskip: function(data) {
|
2014-01-14 00:31:12 +00:00
|
|
|
var icon = $("#voteskip").find(".glyphicon").remove();
|
2013-08-07 21:00:53 +00:00
|
|
|
if(data.count > 0) {
|
2014-01-14 00:31:12 +00:00
|
|
|
$("#voteskip").text(" ("+data.count+"/"+data.need+")");
|
|
|
|
} else {
|
|
|
|
$("#voteskip").text("");
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
2014-01-14 00:31:12 +00:00
|
|
|
|
|
|
|
icon.prependTo($("#voteskip"));
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* REGION Rank Stuff */
|
|
|
|
|
|
|
|
rank: function(r) {
|
|
|
|
if(r >= 255)
|
|
|
|
SUPERADMIN = true;
|
|
|
|
CLIENT.rank = r;
|
|
|
|
handlePermissionChange();
|
|
|
|
if(SUPERADMIN && $("#setrank").length == 0) {
|
|
|
|
$("<a/>").attr("href", "/acp.html")
|
|
|
|
.attr("target", "_blank")
|
|
|
|
.text("ACP")
|
|
|
|
.appendTo($("<li/>").appendTo($(".nav")[0]));
|
|
|
|
var li = $("<li/>").addClass("dropdown")
|
|
|
|
.attr("id", "setrank")
|
|
|
|
.appendTo($(".nav")[0]);
|
|
|
|
$("<a/>").addClass("dropdown-toggle")
|
|
|
|
.attr("data-toggle", "dropdown")
|
|
|
|
.attr("href", "javascript:void(0)")
|
|
|
|
.html("Set Rank <b class='caret'></b>")
|
|
|
|
.appendTo(li);
|
|
|
|
var menu = $("<ul/>").addClass("dropdown-menu")
|
|
|
|
.appendTo(li);
|
|
|
|
|
|
|
|
function addRank(r, disp) {
|
|
|
|
var li = $("<li/>").appendTo(menu);
|
|
|
|
$("<a/>").attr("href", "javascript:void(0)")
|
|
|
|
.html(disp)
|
|
|
|
.click(function() {
|
|
|
|
socket.emit("borrow-rank", r);
|
|
|
|
})
|
|
|
|
.appendTo(li);
|
|
|
|
}
|
|
|
|
|
|
|
|
addRank(0, "<span class='userlist_guest'>Guest</span>");
|
|
|
|
addRank(1, "<span>Registered</span>");
|
|
|
|
addRank(2, "<span class='userlist_op'>Moderator</span>");
|
|
|
|
addRank(3, "<span class='userlist_owner'>Admin</span>");
|
|
|
|
addRank(255, "<span class='userlist_siteadmin'>Superadmin</span>");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
login: function(data) {
|
|
|
|
if(!data.success) {
|
2013-08-18 17:48:49 +00:00
|
|
|
if(data.error != "Session expired") {
|
2013-08-07 21:00:53 +00:00
|
|
|
alert(data.error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CLIENT.name = data.name;
|
2014-01-19 02:18:00 +00:00
|
|
|
CLIENT.guest = data.guest;
|
2013-08-07 21:00:53 +00:00
|
|
|
CLIENT.logged_in = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* REGION Chat */
|
|
|
|
usercount: function(count) {
|
2013-09-04 22:47:24 +00:00
|
|
|
CHANNEL.usercount = count;
|
2013-08-07 21:00:53 +00:00
|
|
|
var text = count + " connected user";
|
|
|
|
if(count != 1) {
|
|
|
|
text += "s";
|
|
|
|
}
|
|
|
|
$("#usercount").text(text);
|
|
|
|
},
|
|
|
|
|
|
|
|
chatMsg: function(data) {
|
|
|
|
addChatMessage(data);
|
|
|
|
},
|
|
|
|
|
|
|
|
joinMessage: function(data) {
|
|
|
|
if(USEROPTS.joinmessage)
|
|
|
|
addChatMessage(data);
|
|
|
|
},
|
|
|
|
|
|
|
|
clearchat: function() {
|
|
|
|
$("#messagebuffer").html("");
|
|
|
|
},
|
|
|
|
|
|
|
|
userlist: function(data) {
|
2013-12-19 04:50:19 +00:00
|
|
|
$(".userlist_item").remove();
|
2013-08-07 21:00:53 +00:00
|
|
|
for(var i = 0; i < data.length; i++) {
|
|
|
|
Callbacks.addUser(data[i]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addUser: function(data) {
|
2013-08-22 00:20:26 +00:00
|
|
|
var user = findUserlistItem(data.name);
|
|
|
|
// Remove previous instance of user, if there was one
|
|
|
|
if(user !== null)
|
|
|
|
user.remove();
|
2013-08-07 21:00:53 +00:00
|
|
|
var div = $("<div/>")
|
2013-08-07 21:55:39 +00:00
|
|
|
.addClass("userlist_item");
|
2013-12-19 04:50:19 +00:00
|
|
|
var icon = $("<span/>").appendTo(div);
|
2013-08-07 21:00:53 +00:00
|
|
|
var nametag = $("<span/>").text(data.name).appendTo(div);
|
2013-11-09 04:12:17 +00:00
|
|
|
div.data("name", data.name);
|
|
|
|
div.data("rank", data.rank);
|
2013-12-19 04:50:19 +00:00
|
|
|
div.data("leader", Boolean(data.leader));
|
2013-11-09 04:12:17 +00:00
|
|
|
div.data("profile", data.profile);
|
2014-01-08 04:47:00 +00:00
|
|
|
div.data("meta", data.meta);
|
2013-11-15 01:50:17 +00:00
|
|
|
div.data("afk", data.meta.afk);
|
2014-01-19 02:18:00 +00:00
|
|
|
if (data.meta.muted || data.meta.smuted) {
|
|
|
|
div.data("icon", "glyphicon-volume-off");
|
|
|
|
} else {
|
|
|
|
div.data("icon", false);
|
|
|
|
}
|
2013-08-07 21:00:53 +00:00
|
|
|
formatUserlistItem(div, data);
|
|
|
|
addUserDropdown(div, data);
|
|
|
|
div.appendTo($("#userlist"));
|
2013-08-08 14:54:07 +00:00
|
|
|
sortUserlist();
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
2014-01-08 04:47:00 +00:00
|
|
|
setUserMeta: function (data) {
|
|
|
|
var user = findUserlistItem(data.name);
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-19 22:50:14 +00:00
|
|
|
user.data("meta", data.meta);
|
2014-01-19 07:58:35 +00:00
|
|
|
if (data.meta.muted || data.meta.smuted) {
|
|
|
|
user.data("icon", "glyphicon-volume-off");
|
|
|
|
} else {
|
|
|
|
user.data("icon", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
formatUserlistItem(user, data);
|
|
|
|
addUserDropdown(user, data);
|
|
|
|
sortUserlist();
|
2014-01-08 04:47:00 +00:00
|
|
|
},
|
|
|
|
|
2013-11-15 01:50:17 +00:00
|
|
|
setUserProfile: function (data) {
|
|
|
|
var user = findUserlistItem(data.name);
|
|
|
|
if (user === null)
|
|
|
|
return;
|
|
|
|
user.data("profile", data.profile);
|
|
|
|
formatUserlistItem(user);
|
|
|
|
},
|
|
|
|
|
2013-11-09 03:46:30 +00:00
|
|
|
setLeader: function (name) {
|
|
|
|
$(".userlist_item").each(function () {
|
2013-12-19 04:50:19 +00:00
|
|
|
$(this).find(".glyphicon-star-empty").remove();
|
2013-11-09 04:12:17 +00:00
|
|
|
if ($(this).data("leader")) {
|
|
|
|
$(this).data("leader", false);
|
|
|
|
addUserDropdown($(this));
|
|
|
|
}
|
2013-11-09 03:46:30 +00:00
|
|
|
});
|
2013-11-15 04:23:33 +00:00
|
|
|
if (name === "") {
|
|
|
|
CLIENT.leader = false;
|
|
|
|
if(LEADTMR)
|
|
|
|
clearInterval(LEADTMR);
|
|
|
|
LEADTMR = false;
|
2013-11-09 03:46:30 +00:00
|
|
|
return;
|
2013-11-15 04:23:33 +00:00
|
|
|
}
|
2013-11-09 03:46:30 +00:00
|
|
|
var user = findUserlistItem(name);
|
|
|
|
if (user) {
|
2013-11-09 04:12:17 +00:00
|
|
|
user.data("leader", true);
|
|
|
|
formatUserlistItem(user);
|
|
|
|
addUserDropdown(user);
|
|
|
|
}
|
|
|
|
if (name === CLIENT.name) {
|
|
|
|
CLIENT.leader = true;
|
|
|
|
// I'm a leader! Set up sync function
|
|
|
|
if(LEADTMR)
|
|
|
|
clearInterval(LEADTMR);
|
|
|
|
LEADTMR = setInterval(sendVideoUpdate, 5000);
|
2013-11-15 16:24:43 +00:00
|
|
|
handlePermissionChange();
|
|
|
|
} else if (CLIENT.leader) {
|
2013-11-09 04:12:17 +00:00
|
|
|
CLIENT.leader = false;
|
2013-11-15 16:24:43 +00:00
|
|
|
handlePermissionChange();
|
2013-11-09 04:12:17 +00:00
|
|
|
if(LEADTMR)
|
|
|
|
clearInterval(LEADTMR);
|
|
|
|
LEADTMR = false;
|
2013-11-09 03:46:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-09 04:12:17 +00:00
|
|
|
setUserRank: function (data) {
|
2014-01-19 22:50:14 +00:00
|
|
|
var entries = $("#cs-chanranks table").data("entries") || [];
|
2014-01-09 23:16:09 +00:00
|
|
|
var found = false;
|
|
|
|
for (var i = 0; i < entries.length; i++) {
|
|
|
|
if (entries[i].name === data.name) {
|
|
|
|
entries[i].rank = data.rank;
|
|
|
|
found = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found === false) {
|
|
|
|
entries.push(data);
|
|
|
|
} else if (entries[found].rank < 2) {
|
|
|
|
entries.splice(found, 1);
|
|
|
|
}
|
|
|
|
formatCSModList();
|
2014-01-09 05:45:26 +00:00
|
|
|
|
2013-11-09 04:12:17 +00:00
|
|
|
var user = findUserlistItem(data.name);
|
|
|
|
if (user === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
user.data("rank", data.rank);
|
2013-11-15 16:24:43 +00:00
|
|
|
if (data.name === CLIENT.name) {
|
|
|
|
CLIENT.rank = data.rank;
|
|
|
|
handlePermissionChange();
|
|
|
|
}
|
2013-11-09 04:12:17 +00:00
|
|
|
formatUserlistItem(user);
|
|
|
|
addUserDropdown(user);
|
2014-01-09 05:45:26 +00:00
|
|
|
if (USEROPTS.sort_rank) {
|
2013-11-09 04:12:17 +00:00
|
|
|
sortUserlist();
|
2014-01-09 05:45:26 +00:00
|
|
|
}
|
2013-11-09 04:12:17 +00:00
|
|
|
},
|
|
|
|
|
2013-11-09 18:33:18 +00:00
|
|
|
setUserIcon: function (data) {
|
|
|
|
var user = findUserlistItem(data.name);
|
|
|
|
if (user === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
user.data("icon", data.icon);
|
|
|
|
formatUserlistItem(user);
|
|
|
|
},
|
|
|
|
|
2013-08-07 21:00:53 +00:00
|
|
|
setAFK: function (data) {
|
2013-08-07 21:55:39 +00:00
|
|
|
var user = findUserlistItem(data.name);
|
|
|
|
if(user === null)
|
|
|
|
return;
|
2013-11-15 01:50:17 +00:00
|
|
|
user.data("afk", data.afk);
|
|
|
|
formatUserlistItem(user);
|
2013-08-08 14:54:07 +00:00
|
|
|
if(USEROPTS.sort_afk)
|
|
|
|
sortUserlist();
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
userLeave: function(data) {
|
2013-08-07 21:55:39 +00:00
|
|
|
var user = findUserlistItem(data.name);
|
|
|
|
if(user !== null)
|
|
|
|
user.remove();
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
drinkCount: function(count) {
|
|
|
|
if(count != 0) {
|
|
|
|
var text = count + " drink";
|
|
|
|
if(count != 1) {
|
|
|
|
text += "s";
|
|
|
|
}
|
|
|
|
$("#drinkcount").text(text);
|
|
|
|
$("#drinkbar").show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#drinkbar").hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* REGION Playlist Stuff */
|
|
|
|
playlist: function(data) {
|
2013-08-12 04:24:48 +00:00
|
|
|
PL_QUEUED_ACTIONS = [];
|
2013-08-07 21:00:53 +00:00
|
|
|
// Clear the playlist first
|
|
|
|
var q = $("#queue");
|
|
|
|
q.html("");
|
|
|
|
|
|
|
|
for(var i = 0; i < data.length; i++) {
|
|
|
|
var li = makeQueueEntry(data[i], false);
|
|
|
|
li.attr("title", data[i].queueby
|
|
|
|
? ("Added by: " + data[i].queueby)
|
|
|
|
: "Added by: Unknown");
|
|
|
|
li.appendTo(q);
|
|
|
|
}
|
|
|
|
|
|
|
|
rebuildPlaylist();
|
|
|
|
},
|
|
|
|
|
|
|
|
setPlaylistMeta: function(data) {
|
|
|
|
var c = data.count + " item";
|
|
|
|
if(data.count != 1)
|
|
|
|
c += "s";
|
|
|
|
$("#plcount").text(c);
|
|
|
|
$("#pllength").text(data.time);
|
|
|
|
},
|
|
|
|
|
|
|
|
queue: function(data) {
|
2013-10-01 18:35:29 +00:00
|
|
|
PL_ACTION_QUEUE.queue(function (plq) {
|
|
|
|
var li = makeQueueEntry(data.item, true);
|
|
|
|
if (data.item.uid === PL_CURRENT)
|
|
|
|
li.addClass("queue_active");
|
|
|
|
li.hide();
|
|
|
|
var q = $("#queue");
|
|
|
|
li.attr("title", data.item.queueby
|
|
|
|
? ("Added by: " + data.item.queueby)
|
|
|
|
: "Added by: Unknown");
|
|
|
|
if (data.after === "prepend") {
|
|
|
|
li.prependTo(q);
|
2014-01-14 06:52:56 +00:00
|
|
|
li.show("fade", function () {
|
2013-10-01 18:35:29 +00:00
|
|
|
plq.release();
|
|
|
|
});
|
|
|
|
} else if (data.after === "append") {
|
|
|
|
li.appendTo(q);
|
2014-01-14 06:52:56 +00:00
|
|
|
li.show("fade", function () {
|
2013-10-01 18:35:29 +00:00
|
|
|
plq.release();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var liafter = playlistFind(data.after);
|
|
|
|
if (!liafter) {
|
|
|
|
plq.release();
|
|
|
|
return;
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
2013-10-01 18:35:29 +00:00
|
|
|
li.insertAfter(liafter);
|
2014-01-14 06:52:56 +00:00
|
|
|
li.show("fade", function () {
|
2013-10-01 18:35:29 +00:00
|
|
|
plq.release();
|
|
|
|
});
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-11-11 04:26:30 +00:00
|
|
|
queueWarn: function (data) {
|
|
|
|
queueMessage(data, "alert-warning");
|
|
|
|
},
|
|
|
|
|
2013-10-06 06:43:25 +00:00
|
|
|
queueFail: function (data) {
|
2013-12-19 04:50:19 +00:00
|
|
|
queueMessage(data, "alert-danger");
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setTemp: function(data) {
|
|
|
|
var li = $(".pluid-" + data.uid);
|
|
|
|
if(li.length == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(data.temp)
|
|
|
|
li.addClass("queue_temp");
|
|
|
|
else
|
|
|
|
li.removeClass("queue_temp");
|
|
|
|
|
|
|
|
li.data("temp", data.temp);
|
|
|
|
var btn = li.find(".qbtn-tmp");
|
|
|
|
if(btn.length > 0) {
|
|
|
|
if(data.temp) {
|
|
|
|
btn.html(btn.html().replace("Make Temporary",
|
|
|
|
"Make Permanent"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
btn.html(btn.html().replace("Make Permanent",
|
|
|
|
"Make Temporary"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
"delete": function(data) {
|
2013-10-01 18:35:29 +00:00
|
|
|
PL_ACTION_QUEUE.queue(function (plq) {
|
|
|
|
PL_WAIT_SCROLL = true;
|
|
|
|
var li = $(".pluid-" + data.uid);
|
2014-01-14 06:52:56 +00:00
|
|
|
li.hide("fade", function() {
|
2013-10-01 18:35:29 +00:00
|
|
|
li.remove();
|
|
|
|
plq.release();
|
|
|
|
PL_WAIT_SCROLL = false;
|
|
|
|
});
|
2013-08-07 21:00:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
moveVideo: function(data) {
|
2013-10-04 03:11:47 +00:00
|
|
|
PL_ACTION_QUEUE.queue(function (plq) {
|
|
|
|
playlistMove(data.from, data.after, function () {
|
|
|
|
plq.release();
|
2013-08-07 21:00:53 +00:00
|
|
|
});
|
2013-10-04 03:11:47 +00:00
|
|
|
});
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setCurrent: function(uid) {
|
2013-10-01 18:25:05 +00:00
|
|
|
PL_CURRENT = uid;
|
|
|
|
$("#queue li").removeClass("queue_active");
|
|
|
|
var li = $(".pluid-" + uid);
|
|
|
|
if (li.length !== 0) {
|
|
|
|
li.addClass("queue_active");
|
|
|
|
var tmr = setInterval(function () {
|
|
|
|
if (!PL_WAIT_SCROLL) {
|
|
|
|
scrollQueue();
|
|
|
|
clearInterval(tmr);
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
2013-10-01 18:25:05 +00:00
|
|
|
}, 100);
|
|
|
|
}
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
changeMedia: function(data) {
|
|
|
|
if(CHANNEL.opts.allow_voteskip)
|
|
|
|
$("#voteskip").attr("disabled", false);
|
|
|
|
|
|
|
|
$("#currenttitle").text("Currently Playing: " + data.title);
|
|
|
|
|
|
|
|
if(data.type != "sc" && PLAYER.type == "sc")
|
|
|
|
// [](/goddamnitmango)
|
|
|
|
fixSoundcloudShit();
|
|
|
|
|
|
|
|
if(data.type != "jw" && PLAYER.type == "jw") {
|
|
|
|
// Is it so hard to not mess up my DOM?
|
|
|
|
$("<div/>").attr("id", "ytapiplayer")
|
|
|
|
.insertBefore($("#ytapiplayer_wrapper"));
|
|
|
|
$("#ytapiplayer_wrapper").remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data.type != PLAYER.type) {
|
|
|
|
loadMediaPlayer(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMediaUpdate(data);
|
|
|
|
},
|
|
|
|
|
|
|
|
mediaUpdate: function(data) {
|
|
|
|
handleMediaUpdate(data);
|
|
|
|
},
|
|
|
|
|
2014-01-08 04:47:00 +00:00
|
|
|
setPlaylistLocked: function (locked) {
|
|
|
|
CHANNEL.openqueue = !locked;
|
2013-08-07 21:00:53 +00:00
|
|
|
handlePermissionChange();
|
|
|
|
if(CHANNEL.openqueue) {
|
|
|
|
$("#qlockbtn").removeClass("btn-danger")
|
|
|
|
.addClass("btn-success")
|
|
|
|
.attr("title", "Playlist Unlocked");
|
2014-01-14 00:31:12 +00:00
|
|
|
$("#qlockbtn").find("span")
|
2013-12-19 04:50:19 +00:00
|
|
|
.removeClass("glyphicon-lock")
|
|
|
|
.addClass("glyphicon-ok");
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#qlockbtn").removeClass("btn-success")
|
|
|
|
.addClass("btn-danger")
|
|
|
|
.attr("title", "Playlist Locked");
|
2014-01-14 00:31:12 +00:00
|
|
|
$("#qlockbtn").find("span")
|
2013-12-19 04:50:19 +00:00
|
|
|
.removeClass("glyphicon-ok")
|
|
|
|
.addClass("glyphicon-lock");
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
searchResults: function(data) {
|
|
|
|
$("#search_clear").remove();
|
|
|
|
clearSearchResults();
|
|
|
|
$("#library").data("entries", data.results);
|
2013-12-19 04:50:19 +00:00
|
|
|
$("<button/>").addClass("btn btn-default btn-sm btn-block")
|
2013-08-07 21:00:53 +00:00
|
|
|
.css("margin-left", "0")
|
|
|
|
.attr("id", "search_clear")
|
|
|
|
.text("Clear Results")
|
|
|
|
.click(function() {
|
|
|
|
clearSearchResults();
|
|
|
|
})
|
|
|
|
.insertBefore($("#library"));
|
2013-09-24 20:19:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
$("#search_pagination").remove();
|
2013-09-24 18:19:41 +00:00
|
|
|
var opts = {
|
|
|
|
preLoadPage: function () {
|
|
|
|
$("#library").html("");
|
|
|
|
},
|
2013-08-07 21:00:53 +00:00
|
|
|
|
2013-09-24 18:19:41 +00:00
|
|
|
generator: function (item, page, index) {
|
|
|
|
var li = makeSearchEntry(item, false);
|
|
|
|
if(hasPermission("playlistadd")) {
|
|
|
|
addLibraryButtons(li, item.id, data.source);
|
|
|
|
}
|
|
|
|
$(li).appendTo($("#library"));
|
|
|
|
},
|
2013-08-07 21:00:53 +00:00
|
|
|
|
2014-01-22 04:41:53 +00:00
|
|
|
itemsPerPage: 10
|
2013-09-24 18:19:41 +00:00
|
|
|
};
|
2013-08-07 21:00:53 +00:00
|
|
|
|
2013-09-24 18:19:41 +00:00
|
|
|
var p = Paginate(data.results, opts);
|
2014-01-22 04:41:53 +00:00
|
|
|
p.paginator.insertAfter($("#library"))
|
|
|
|
.addClass("pull-right")
|
2013-09-24 18:19:41 +00:00
|
|
|
.attr("id", "search_pagination");
|
|
|
|
$("#library").data("paginator", p);
|
2013-08-07 21:00:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* REGION Polls */
|
|
|
|
newPoll: function(data) {
|
|
|
|
Callbacks.closePoll();
|
|
|
|
var pollMsg = $("<div/>").addClass("poll-notify")
|
2013-12-01 23:20:42 +00:00
|
|
|
.html(data.initiator + " opened a poll: \"" + data.title + "\"")
|
2013-08-07 21:00:53 +00:00
|
|
|
.appendTo($("#messagebuffer"));
|
|
|
|
scrollChat();
|
|
|
|
|
|
|
|
var poll = $("<div/>").addClass("well active").prependTo($("#pollwrap"));
|
|
|
|
$("<button/>").addClass("close pull-right").html("×")
|
|
|
|
.appendTo(poll)
|
|
|
|
.click(function() { poll.remove(); });
|
|
|
|
if(hasPermission("pollctl")) {
|
2013-12-19 04:50:19 +00:00
|
|
|
$("<button/>").addClass("btn btn-danger btn-sm pull-right").text("End Poll")
|
2013-08-07 21:00:53 +00:00
|
|
|
.appendTo(poll)
|
|
|
|
.click(function() {
|
|
|
|
socket.emit("closePoll")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-12-01 23:20:42 +00:00
|
|
|
$("<h3/>").html(data.title).appendTo(poll);
|
2013-08-07 21:00:53 +00:00
|
|
|
for(var i = 0; i < data.options.length; i++) {
|
|
|
|
(function(i) {
|
2013-09-21 05:25:00 +00:00
|
|
|
var callback = function () {
|
|
|
|
socket.emit("vote", {
|
|
|
|
option: i
|
|
|
|
});
|
|
|
|
poll.find(".option button").each(function() {
|
|
|
|
$(this).attr("disabled", "disabled");
|
|
|
|
});
|
|
|
|
$(this).parent().addClass("option-selected");
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
2013-12-19 04:50:19 +00:00
|
|
|
$("<button/>").addClass("btn btn-default btn-sm").text(data.counts[i])
|
2013-12-01 23:20:42 +00:00
|
|
|
.prependTo($("<div/>").addClass("option").html(data.options[i])
|
2013-08-07 21:00:53 +00:00
|
|
|
.appendTo(poll))
|
|
|
|
.click(callback);
|
|
|
|
})(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
poll.find(".btn").attr("disabled", !hasPermission("pollvote"));
|
|
|
|
},
|
|
|
|
|
|
|
|
updatePoll: function(data) {
|
|
|
|
var poll = $("#pollwrap .active");
|
|
|
|
var i = 0;
|
|
|
|
poll.find(".option button").each(function() {
|
2013-09-21 05:25:00 +00:00
|
|
|
$(this).html(data.counts[i]);
|
2013-08-07 21:00:53 +00:00
|
|
|
i++;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
closePoll: function() {
|
|
|
|
if($("#pollwrap .active").length != 0) {
|
|
|
|
var poll = $("#pollwrap .active");
|
|
|
|
poll.removeClass("active").addClass("muted");
|
|
|
|
poll.find(".option button").each(function() {
|
|
|
|
$(this).attr("disabled", true);
|
|
|
|
});
|
|
|
|
poll.find(".btn-danger").each(function() {
|
|
|
|
$(this).remove()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
savePlaylist: function(data) {
|
|
|
|
if(data.success) {
|
|
|
|
makeAlert("Success", "Playlist saved.", "alert-success");
|
|
|
|
}
|
|
|
|
else {
|
2013-12-19 04:50:19 +00:00
|
|
|
makeAlert("Error", data.error, "alert-danger")
|
2013-08-07 21:00:53 +00:00
|
|
|
.addClass("span12")
|
|
|
|
.insertBefore($("#userpl_list"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
listPlaylists: function(data) {
|
|
|
|
if(data.error) {
|
2013-12-19 04:50:19 +00:00
|
|
|
makeAlert("Error", data.error, "alert-danger")
|
2013-08-07 21:00:53 +00:00
|
|
|
.insertBefore($("#userpl_list"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var pls = data.pllist;
|
|
|
|
pls.sort(function(a, b) {
|
|
|
|
var x = a.name.toLowerCase();
|
|
|
|
var y = b.name.toLowerCase();
|
|
|
|
if(x < y) return -1;
|
|
|
|
if(x > y) return 1;
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
$("#userpl_list").html("");
|
|
|
|
for(var i = 0; i < pls.length; i++) {
|
|
|
|
var li = $("<li/>").appendTo($("#userpl_list"))
|
|
|
|
.addClass("well");
|
|
|
|
li.data("pl-name", pls[i].name);
|
|
|
|
$("<div/>").text(pls[i].name).appendTo(li)
|
|
|
|
.css("float", "left")
|
|
|
|
.css("margin-left", "1em");
|
|
|
|
var metastr = pls[i].count + " item";
|
|
|
|
if(pls[i].count != 1) {
|
|
|
|
metastr += "s";
|
|
|
|
}
|
|
|
|
metastr +=", playtime " + pls[i].time;
|
|
|
|
$("<div/>").text(metastr)
|
|
|
|
.css("float", "right")
|
|
|
|
.appendTo(li);
|
|
|
|
var bg = $("<div/>").addClass("btn-group")
|
|
|
|
.css("float", "left")
|
|
|
|
.prependTo(li);
|
|
|
|
var del = $("<button/>")
|
2013-12-19 04:50:19 +00:00
|
|
|
.addClass("btn btn-xs btn-danger")
|
2013-08-07 21:00:53 +00:00
|
|
|
.prependTo(bg);
|
2013-12-19 04:50:19 +00:00
|
|
|
$("<span/>").addClass("glyphicon glyphicon-trash").appendTo(del);
|
2013-08-07 21:00:53 +00:00
|
|
|
(function(li) {
|
|
|
|
del.click(function() {
|
|
|
|
var go = confirm("Are you sure you want to delete playlist '" + li.data("pl-name") + "'?");
|
|
|
|
if(go) {
|
|
|
|
socket.emit("deletePlaylist", {
|
|
|
|
name: li.data("pl-name")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})(li);
|
|
|
|
if(hasPermission("playlistaddlist")) {
|
|
|
|
(function(li) {
|
2013-12-19 04:50:19 +00:00
|
|
|
$("<button/>").addClass("btn btn-xs btn-default")
|
2013-08-07 21:00:53 +00:00
|
|
|
.text("End")
|
|
|
|
.prependTo(bg)
|
|
|
|
.click(function() {
|
|
|
|
socket.emit("queuePlaylist", {
|
|
|
|
name: li.data("pl-name"),
|
|
|
|
pos: "end"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})(li);
|
|
|
|
|
|
|
|
if(hasPermission("playlistnext")) {
|
|
|
|
(function(li) {
|
2013-12-19 04:50:19 +00:00
|
|
|
$("<button/>").addClass("btn btn-xs btn-default")
|
2013-08-07 21:00:53 +00:00
|
|
|
.text("Next")
|
|
|
|
.prependTo(bg)
|
|
|
|
.click(function() {
|
|
|
|
socket.emit("queuePlaylist", {
|
|
|
|
name: li.data("pl-name"),
|
|
|
|
pos: "next"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})(li);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-08 04:47:00 +00:00
|
|
|
var SOCKET_DEBUG = true;
|
2013-08-07 21:00:53 +00:00
|
|
|
setupCallbacks = function() {
|
|
|
|
for(var key in Callbacks) {
|
|
|
|
(function(key) {
|
|
|
|
socket.on(key, function(data) {
|
2014-01-25 19:49:34 +00:00
|
|
|
if (SOCKET_DEBUG)
|
2013-08-07 21:00:53 +00:00
|
|
|
console.log(key, data);
|
|
|
|
Callbacks[key](data);
|
|
|
|
});
|
|
|
|
})(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 04:59:08 +00:00
|
|
|
try {
|
2014-01-26 20:15:50 +00:00
|
|
|
if (typeof io === "undefined") {
|
|
|
|
makeAlert("Uh oh!", "It appears the connection to <code>" + IO_URL + "</code> " +
|
|
|
|
"has failed. If this error persists, a firewall or " +
|
|
|
|
"antivirus is likely blocking the connection, or the " +
|
|
|
|
"server is down.", "alert-danger")
|
|
|
|
.appendTo($("#announcements"));
|
|
|
|
throw false;
|
|
|
|
}
|
|
|
|
|
2014-01-24 04:59:08 +00:00
|
|
|
if (NO_WEBSOCKETS || USEROPTS.altsocket) {
|
|
|
|
var i = io.transports.indexOf("websocket");
|
|
|
|
if (i >= 0) {
|
|
|
|
io.transports.splice(i, 1);
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-24 04:59:08 +00:00
|
|
|
var opts = {};
|
|
|
|
if (location.protocol === "https:" || USEROPTS.secure_connection) {
|
|
|
|
opts.secure = true;
|
2013-08-07 21:00:53 +00:00
|
|
|
}
|
2014-01-24 04:59:08 +00:00
|
|
|
socket = io.connect(IO_URL, opts);
|
|
|
|
setupCallbacks();
|
|
|
|
} catch (e) {
|
2014-01-26 20:15:50 +00:00
|
|
|
if (e) {
|
|
|
|
Callbacks.disconnect();
|
|
|
|
}
|
2014-01-24 04:59:08 +00:00
|
|
|
}
|