2013-06-09 22:18:27 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
Copyright (c) 2013 Calvin Montgomery
|
2013-06-22 23:38:44 +00:00
|
|
|
|
2013-06-09 22:18:27 +00:00
|
|
|
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:
|
2013-06-22 23:38:44 +00:00
|
|
|
|
2013-06-09 22:18:27 +00:00
|
|
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
2013-06-22 23:38:44 +00:00
|
|
|
|
2013-06-09 22:18:27 +00:00
|
|
|
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 = {
|
|
|
|
|
2013-07-27 20:42:42 +00:00
|
|
|
error: function (reason) {
|
|
|
|
var d = $("<div/>").addClass("alert alert-error span12")
|
|
|
|
.appendTo($("#announcements"));
|
|
|
|
$("<h3/>").text("Uh-oh!").appendTo(d);
|
|
|
|
$("<p/>").html("The socket.io connection failed."+
|
|
|
|
"Try going to the "+
|
|
|
|
"'Options' menu and enabling 'Alternate socket "+
|
|
|
|
" connection'. If that doesn't help, talk to "+
|
|
|
|
"someone on <a href='http://webchat.6irc.net/?"+
|
|
|
|
"channels=synchtube'>IRC</a>").appendTo(d);
|
|
|
|
var data = {
|
|
|
|
iourl: IO_URL,
|
|
|
|
weburl: WEB_URL,
|
|
|
|
transports: io.transports,
|
|
|
|
fallback: USEROPTS.altsocket,
|
|
|
|
reason: reason
|
|
|
|
};
|
|
|
|
|
|
|
|
var r = JSON.stringify(data);
|
|
|
|
$("<em/>").text("When asking for help, give the following "+
|
|
|
|
"information to an administrator:").appendTo(d);
|
|
|
|
$("<code/>").text(r).appendTo(d)
|
|
|
|
.css("white-space", "pre-wrap");
|
|
|
|
},
|
|
|
|
|
2013-06-09 22:18:27 +00:00
|
|
|
/* fired when socket connection completes */
|
|
|
|
connect: function() {
|
|
|
|
socket.emit("joinChannel", {
|
|
|
|
name: CHANNEL.name
|
|
|
|
});
|
2013-06-11 15:29:21 +00:00
|
|
|
if(NAME && SESSION) {
|
2013-06-09 22:18:27 +00:00
|
|
|
socket.emit("login", {
|
|
|
|
name: NAME,
|
|
|
|
session: SESSION
|
|
|
|
});
|
|
|
|
}
|
2013-06-25 14:27:35 +00:00
|
|
|
// Guest auto-relogin
|
|
|
|
else if(CLIENT.name) {
|
|
|
|
socket.emit("login", {
|
|
|
|
name: CLIENT.name
|
|
|
|
});
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
$("<div/>").addClass("server-msg-reconnect")
|
|
|
|
.text("Connected")
|
|
|
|
.appendTo($("#messagebuffer"));
|
|
|
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
|
|
|
},
|
|
|
|
|
|
|
|
disconnect: function() {
|
|
|
|
if(KICKED)
|
|
|
|
return;
|
|
|
|
$("<div/>")
|
|
|
|
.addClass("server-msg-disconnect")
|
|
|
|
.text("Disconnected from server. Attempting reconnection...")
|
|
|
|
.appendTo($("#messagebuffer"));
|
|
|
|
scrollChat();
|
|
|
|
},
|
|
|
|
|
|
|
|
errorMsg: function(data) {
|
|
|
|
alert(data.msg);
|
|
|
|
},
|
|
|
|
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
|
|
|
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")
|
|
|
|
.appendTo(div)
|
|
|
|
.click(function() {
|
|
|
|
socket.emit("registerChannel");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
registerChannel: function(data) {
|
|
|
|
if(data.success) {
|
|
|
|
$("#chregnotice").remove();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
makeAlert("Error", data.error, "alert-error")
|
|
|
|
.insertAfter($("#chregnotice"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
unregisterChannel: function(data) {
|
|
|
|
if(data.success) {
|
|
|
|
alert("Channel unregistered");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert(data.error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setMotd: function(data) {
|
2013-06-19 23:39:40 +00:00
|
|
|
CHANNEL.motd = data.html;
|
2013-07-02 19:42:26 +00:00
|
|
|
CHANNEL.motd_text = data.motd;
|
2013-06-09 22:18:27 +00:00
|
|
|
$("#motd").html(data.html);
|
2013-07-02 19:42:26 +00:00
|
|
|
$("#motdtext").val(CHANNEL.motd_text);
|
2013-06-09 22:18:27 +00:00
|
|
|
if(data.motd != "")
|
|
|
|
$("#motd").show();
|
|
|
|
else
|
|
|
|
$("#motd").hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
chatFilters: function(entries) {
|
2013-06-18 14:57:53 +00:00
|
|
|
var tbl = $("#filteredit table");
|
|
|
|
if(!tbl.hasClass("table")) {
|
|
|
|
setTimeout(function() {
|
|
|
|
Callbacks.chatFilters(entries);
|
|
|
|
}, 100);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-18 19:59:45 +00:00
|
|
|
tbl.find(".filter-row").remove();
|
2013-06-09 22:18:27 +00:00
|
|
|
for(var i = 0; i < entries.length; i++) {
|
|
|
|
var f = entries[i];
|
2013-06-18 19:59:45 +00:00
|
|
|
var tr = $("<tr/>").appendTo(tbl).addClass("filter-row");
|
2013-06-09 22:18:27 +00:00
|
|
|
var remove = $("<button/>").addClass("btn btn-mini btn-danger")
|
|
|
|
.appendTo($("<td/>").appendTo(tr));
|
2013-06-18 14:57:53 +00:00
|
|
|
$("<i/>").addClass("icon-trash").appendTo(remove);
|
2013-06-09 22:18:27 +00:00
|
|
|
var name = $("<code/>").text(f.name)
|
|
|
|
.appendTo($("<td/>").appendTo(tr));
|
|
|
|
var regex = $("<code/>").text(f.source)
|
|
|
|
.appendTo($("<td/>").appendTo(tr));
|
|
|
|
var flags = $("<code/>").text(f.flags)
|
|
|
|
.appendTo($("<td/>").appendTo(tr));
|
|
|
|
var replace = $("<code/>").text(f.replace)
|
|
|
|
.appendTo($("<td/>").appendTo(tr));
|
2013-06-18 14:57:53 +00:00
|
|
|
var linktd = $("<td/>").appendTo(tr);
|
|
|
|
var link = $("<input/>").attr("type", "checkbox")
|
2013-06-18 15:51:42 +00:00
|
|
|
.prop("checked", f.filterlinks).appendTo(linktd);
|
2013-06-09 22:18:27 +00:00
|
|
|
var activetd = $("<td/>").appendTo(tr);
|
|
|
|
var active = $("<input/>").attr("type", "checkbox")
|
|
|
|
.prop("checked", f.active).appendTo(activetd);
|
2013-06-18 15:51:42 +00:00
|
|
|
(function(f) {
|
|
|
|
regex.click(function() {
|
|
|
|
if(this.find(".filter-regex-edit").length > 0)
|
|
|
|
return;
|
|
|
|
var r = this.text();
|
|
|
|
this.text("");
|
|
|
|
var edit = $("<input/>").attr("type", "text")
|
|
|
|
.css("font-family", "Monospace")
|
|
|
|
.attr("placeholder", r)
|
|
|
|
.val(r)
|
|
|
|
.addClass("filter-regex-edit")
|
|
|
|
.appendTo(this)
|
|
|
|
.focus();
|
2013-06-09 22:18:27 +00:00
|
|
|
|
2013-06-18 15:51:42 +00:00
|
|
|
function save() {
|
|
|
|
var r = this.val();
|
|
|
|
var r2 = r;
|
|
|
|
if(r.trim() == "")
|
|
|
|
r = this.attr("placeholder");
|
|
|
|
this.parent().text(r);
|
|
|
|
f.source = r;
|
|
|
|
socket.emit("updateFilter", f);
|
|
|
|
}
|
|
|
|
edit.blur(save.bind(edit));
|
|
|
|
edit.keydown(function(ev) {
|
|
|
|
if(ev.keyCode == 13)
|
|
|
|
save.bind(edit)();
|
|
|
|
});
|
|
|
|
}.bind(regex));
|
|
|
|
flags.click(function() {
|
|
|
|
if(this.find(".filter-flags-edit").length > 0)
|
|
|
|
return;
|
|
|
|
var r = this.text();
|
|
|
|
this.text("");
|
|
|
|
var edit = $("<input/>").attr("type", "text")
|
|
|
|
.css("font-family", "Monospace")
|
|
|
|
.attr("placeholder", r)
|
|
|
|
.val(r)
|
|
|
|
.addClass("filter-flags-edit")
|
|
|
|
.appendTo(this)
|
|
|
|
.focus();
|
|
|
|
|
|
|
|
function save() {
|
|
|
|
var r = this.val();
|
|
|
|
var r2 = r;
|
|
|
|
if(r.trim() == "")
|
|
|
|
r = this.attr("placeholder");
|
|
|
|
this.parent().text(r);
|
|
|
|
f.flags = r;
|
|
|
|
socket.emit("updateFilter", f);
|
|
|
|
}
|
|
|
|
edit.blur(save.bind(edit));
|
|
|
|
edit.keydown(function(ev) {
|
|
|
|
if(ev.keyCode == 13)
|
|
|
|
save.bind(edit)();
|
|
|
|
});
|
|
|
|
}.bind(flags));
|
|
|
|
replace.click(function() {
|
|
|
|
if(this.find(".filter-replace-edit").length > 0)
|
|
|
|
return;
|
|
|
|
var r = this.text();
|
|
|
|
this.text("");
|
|
|
|
var edit = $("<input/>").attr("type", "text")
|
|
|
|
.css("font-family", "Monospace")
|
|
|
|
.attr("placeholder", r)
|
|
|
|
.val(r)
|
|
|
|
.addClass("filter-replace-edit")
|
|
|
|
.appendTo(this)
|
|
|
|
.focus();
|
|
|
|
|
|
|
|
function save() {
|
|
|
|
var r = this.val();
|
|
|
|
var r2 = r;
|
|
|
|
if(r.trim() == "")
|
|
|
|
r = this.attr("placeholder");
|
|
|
|
this.parent().text(r);
|
|
|
|
f.replace = r;
|
|
|
|
socket.emit("updateFilter", f);
|
|
|
|
}
|
|
|
|
edit.blur(save.bind(edit));
|
|
|
|
edit.keydown(function(ev) {
|
|
|
|
if(ev.keyCode == 13)
|
|
|
|
save.bind(edit)();
|
|
|
|
});
|
|
|
|
}.bind(replace));
|
|
|
|
|
|
|
|
remove.click(function() {
|
|
|
|
socket.emit("removeFilter", f);
|
2013-06-09 22:18:27 +00:00
|
|
|
});
|
2013-06-18 15:51:42 +00:00
|
|
|
|
|
|
|
active.click(function() {
|
|
|
|
// Apparently when you check a checkbox, its value is changed
|
|
|
|
// before this callback. When you uncheck it, its value is not
|
|
|
|
// changed before this callback
|
|
|
|
// [](/amgic)
|
|
|
|
var enabled = active.prop("checked");
|
|
|
|
f.active = (f.active == enabled) ? !enabled : enabled;
|
|
|
|
socket.emit("updateFilter", f);
|
2013-06-09 22:18:27 +00:00
|
|
|
});
|
2013-06-18 15:51:42 +00:00
|
|
|
link.click(function() {
|
|
|
|
var enabled = link.prop("checked");
|
|
|
|
f.filterlinks = (f.filterlinks == enabled) ? !enabled : enabled;
|
|
|
|
socket.emit("updateFilter", f);
|
|
|
|
});
|
|
|
|
})(f);
|
2013-06-09 22:18:27 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 15:51:42 +00:00
|
|
|
$(tbl.children()[1]).sortable({
|
|
|
|
start: function(ev, ui) {
|
|
|
|
FILTER_FROM = ui.item.prevAll().length;
|
|
|
|
},
|
|
|
|
update: function(ev, ui) {
|
|
|
|
FILTER_TO = ui.item.prevAll().length;
|
|
|
|
if(FILTER_TO != FILTER_FROM) {
|
|
|
|
socket.emit("moveFilter", {
|
|
|
|
from: FILTER_FROM,
|
|
|
|
to: FILTER_TO
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-06-09 22:18:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
channelOpts: function(opts) {
|
|
|
|
document.title = opts.pagetitle;
|
|
|
|
PAGETITLE = opts.pagetitle;
|
2013-06-17 22:16:59 +00:00
|
|
|
$("#chanexternalcss").remove();
|
2013-06-26 02:03:14 +00:00
|
|
|
if(opts.externalcss.trim() != "" && !USEROPTS.ignore_channelcss) {
|
2013-06-09 22:18:27 +00:00
|
|
|
$("<link/>")
|
|
|
|
.attr("rel", "stylesheet")
|
2013-06-17 22:16:59 +00:00
|
|
|
.attr("href", opts.externalcss)
|
|
|
|
.attr("id", "chanexternalcss")
|
2013-06-09 22:18:27 +00:00
|
|
|
.appendTo($("head"));
|
|
|
|
}
|
2013-06-26 02:03:14 +00:00
|
|
|
if(opts.externaljs.trim() != "" && !USEROPTS.ignore_channeljs) {
|
2013-06-17 22:16:59 +00:00
|
|
|
if(opts.externaljs != CHANNEL.opts.externaljs) {
|
|
|
|
$.getScript(opts.externaljs);
|
2013-06-09 22:18:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CHANNEL.opts = opts;
|
|
|
|
|
|
|
|
if(opts.allow_voteskip)
|
|
|
|
$("#voteskip").attr("disabled", false);
|
|
|
|
else
|
|
|
|
$("#voteskip").attr("disabled", true);
|
|
|
|
handlePermissionChange();
|
|
|
|
},
|
|
|
|
|
|
|
|
setPermissions: function(perms) {
|
|
|
|
CHANNEL.perms = perms;
|
|
|
|
if(CLIENT.rank >= Rank.Admin)
|
2013-06-17 22:16:59 +00:00
|
|
|
genPermissionsEditor();
|
2013-06-09 22:18:27 +00:00
|
|
|
handlePermissionChange();
|
|
|
|
},
|
|
|
|
|
|
|
|
channelCSSJS: function(data) {
|
|
|
|
$("#chancss").remove();
|
2013-06-19 23:39:40 +00:00
|
|
|
CHANNEL.css = data.css;
|
2013-06-09 22:18:27 +00:00
|
|
|
$("#csstext").val(data.css);
|
2013-06-26 02:03:14 +00:00
|
|
|
if(data.css && !USEROPTS.ignore_channelcss) {
|
2013-06-09 22:18:27 +00:00
|
|
|
$("<style/>").attr("type", "text/css")
|
|
|
|
.attr("id", "chancss")
|
|
|
|
.text(data.css)
|
|
|
|
.appendTo($("head"));
|
|
|
|
}
|
|
|
|
|
2013-06-26 02:03:14 +00:00
|
|
|
$("#chanjs").remove();
|
|
|
|
CHANNEL.js = data.js;
|
|
|
|
$("#jstext").val(data.js);
|
|
|
|
|
|
|
|
if(data.js && !USEROPTS.ignore_channeljs) {
|
2013-06-09 22:18:27 +00:00
|
|
|
$("<script/>").attr("type", "text/javascript")
|
|
|
|
.attr("id", "chanjs")
|
|
|
|
.text(data.js)
|
|
|
|
.appendTo($("body"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
banlist: function(entries) {
|
|
|
|
var tbl = $("#banlist table");
|
2013-06-19 21:54:27 +00:00
|
|
|
// I originally added this check because of a race condition
|
|
|
|
// Now it seems to work without but I don't trust it
|
2013-06-18 03:57:29 +00:00
|
|
|
if(!tbl.hasClass("table")) {
|
|
|
|
setTimeout(function() {
|
|
|
|
Callbacks.banlist(entries);
|
|
|
|
}, 100);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
if(tbl.children().length > 1) {
|
|
|
|
$(tbl.children()[1]).remove();
|
|
|
|
}
|
|
|
|
for(var i = 0; i < entries.length; i++) {
|
2013-06-18 03:57:29 +00:00
|
|
|
var tr = document.createElement("tr");
|
2013-06-09 22:18:27 +00:00
|
|
|
var remove = $("<button/>").addClass("btn btn-mini btn-danger")
|
|
|
|
.appendTo($("<td/>").appendTo(tr));
|
|
|
|
$("<i/>").addClass("icon-remove-circle").appendTo(remove);
|
2013-06-18 03:57:29 +00:00
|
|
|
var ip = $("<td/>").text(entries[i].ip_displayed).appendTo(tr);
|
2013-06-09 22:18:27 +00:00
|
|
|
var name = $("<td/>").text(entries[i].name).appendTo(tr);
|
2013-06-18 03:57:29 +00:00
|
|
|
var aliases = $("<td/>").text(entries[i].aliases.join(", ")).appendTo(tr);
|
2013-06-09 22:18:27 +00:00
|
|
|
var banner = $("<td/>").text(entries[i].banner).appendTo(tr);
|
|
|
|
|
2013-06-25 13:59:14 +00:00
|
|
|
var callback = (function(ip_hidden, name) { return function() {
|
2013-06-09 22:18:27 +00:00
|
|
|
socket.emit("unban", {
|
2013-06-25 13:59:14 +00:00
|
|
|
ip_hidden: ip_hidden,
|
2013-06-09 22:18:27 +00:00
|
|
|
name: name
|
|
|
|
});
|
2013-06-18 03:57:29 +00:00
|
|
|
} })(entries[i].ip_hidden, entries[i].name);
|
2013-06-09 22:18:27 +00:00
|
|
|
remove.click(callback);
|
2013-06-18 03:57:29 +00:00
|
|
|
|
|
|
|
$(tr).appendTo(tbl);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
recentLogins: function(entries) {
|
|
|
|
var tbl = $("#loginhistory table");
|
2013-06-19 21:54:27 +00:00
|
|
|
// I originally added this check because of a race condition
|
|
|
|
// Now it seems to work without but I don't trust it
|
2013-06-18 03:57:29 +00:00
|
|
|
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);
|
2013-06-09 22:18:27 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
channelRanks: function(entries) {
|
2013-06-18 14:46:28 +00:00
|
|
|
var tbl = $("#channelranks table");
|
2013-06-19 21:54:27 +00:00
|
|
|
// I originally added this check because of a race condition
|
|
|
|
// Now it seems to work without but I don't trust it
|
2013-06-18 14:46:28 +00:00
|
|
|
if(!tbl.hasClass("table")) {
|
|
|
|
setTimeout(function() {
|
|
|
|
Callbacks.channelRanks(entries);
|
|
|
|
}, 100);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
entries.sort(function(a, b) {
|
|
|
|
var x = a.name.toLowerCase();
|
|
|
|
var y = b.name.toLowerCase();
|
|
|
|
return y == x ? 0 : (x < y ? -1 : 1);
|
|
|
|
});
|
|
|
|
$("#channelranks").data("entries", entries);
|
|
|
|
if(tbl.children().length > 1) {
|
|
|
|
$(tbl.children()[1]).remove();
|
|
|
|
}
|
2013-07-31 14:57:59 +00:00
|
|
|
var p = tbl.data("paginator");
|
|
|
|
if(p) {
|
|
|
|
p.items = entries;
|
|
|
|
p.loadPage(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var opts = {
|
|
|
|
preLoadPage: function (p) {
|
|
|
|
tbl.find("tbody").remove();
|
|
|
|
tbl.data("page", p);
|
|
|
|
},
|
|
|
|
generator: function (item, page, index) {
|
|
|
|
var tr = $("<tr/>").appendTo(tbl);
|
|
|
|
var name = $("<td/>").text(item.name).appendTo(tr);
|
|
|
|
name.addClass(getNameColor(item.rank));
|
|
|
|
var rank = $("<td/>").text(item.rank)
|
|
|
|
.css("min-width", "220px")
|
|
|
|
.appendTo(tr);
|
|
|
|
rank.click(function() {
|
|
|
|
if(this.find(".rank-edit").length > 0)
|
|
|
|
return;
|
|
|
|
var r = this.text();
|
|
|
|
this.text("");
|
|
|
|
var edit = $("<input/>").attr("type", "text")
|
|
|
|
.attr("placeholder", r)
|
|
|
|
.addClass("rank-edit")
|
|
|
|
.appendTo(this)
|
|
|
|
.focus();
|
|
|
|
if(parseInt(r) >= CLIENT.rank) {
|
|
|
|
edit.attr("disabled", true);
|
|
|
|
}
|
|
|
|
function save() {
|
|
|
|
var r = this.val();
|
|
|
|
var r2 = r;
|
|
|
|
if(r.trim() == "" || parseInt(r) >= CLIENT.rank || parseInt(r) < 1)
|
|
|
|
r = this.attr("placeholder");
|
|
|
|
r = parseInt(r) + "";
|
|
|
|
this.parent().text(r);
|
|
|
|
socket.emit("setChannelRank", {
|
|
|
|
user: item.name,
|
|
|
|
rank: parseInt(r)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
edit.blur(save.bind(edit));
|
|
|
|
edit.keydown(function(ev) {
|
|
|
|
if(ev.keyCode == 13)
|
|
|
|
save.bind(edit)();
|
|
|
|
});
|
|
|
|
}.bind(rank));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var p = Paginate(entries, opts);
|
|
|
|
p.paginator.insertBefore($("#channelranks table"));
|
|
|
|
tbl.data("paginator", p);
|
2013-06-09 22:18:27 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setChannelRank: function(data) {
|
|
|
|
var ents = $("#channelranks").data("entries");
|
|
|
|
for(var i = 0; i < ents.length; i++) {
|
|
|
|
if(ents[i].name == data.user) {
|
|
|
|
ents[i].rank = data.rank;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("#channelranks").data("entries", ents);
|
2013-07-31 14:57:59 +00:00
|
|
|
$("#channelranks table").data("paginator").loadPage(
|
|
|
|
$("#channelranks table").data("page")
|
|
|
|
);
|
2013-06-09 22:18:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
voteskip: function(data) {
|
|
|
|
if(data.count > 0) {
|
|
|
|
$("#voteskip").text("Voteskip ("+data.count+"/"+data.need+")");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#voteskip").text("Voteskip");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* REGION Rank Stuff */
|
|
|
|
|
|
|
|
rank: function(r) {
|
2013-06-22 23:38:44 +00:00
|
|
|
if(r >= 255)
|
|
|
|
SUPERADMIN = true;
|
2013-06-09 22:18:27 +00:00
|
|
|
CLIENT.rank = r;
|
|
|
|
handlePermissionChange();
|
2013-06-22 23:38:44 +00:00
|
|
|
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>");
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* should not be relevant since registration is on account.html */
|
|
|
|
register: function(data) {
|
|
|
|
if(data.error) {
|
|
|
|
alert(data.error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
login: function(data) {
|
|
|
|
if(!data.success) {
|
|
|
|
if(data.error != "Invalid session") {
|
|
|
|
alert(data.error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#welcome").text("Logged in as " + data.name);
|
|
|
|
$("#loginform").css("display", "none");
|
|
|
|
$("#logoutform").css("display", "");
|
|
|
|
$("#loggedin").css("display", "");
|
|
|
|
SESSION = data.session || "";
|
|
|
|
CLIENT.name = data.name;
|
|
|
|
CLIENT.logged_in = true;
|
|
|
|
if(SESSION) {
|
|
|
|
createCookie("cytube_uname", CLIENT.name, 7);
|
|
|
|
createCookie("cytube_session", SESSION, 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* REGION Chat */
|
|
|
|
usercount: function(count) {
|
|
|
|
var text = count + " connected user";
|
|
|
|
if(count != 1) {
|
|
|
|
text += "s";
|
|
|
|
}
|
|
|
|
$("#usercount").text(text);
|
|
|
|
},
|
|
|
|
|
|
|
|
chatMsg: function(data) {
|
|
|
|
addChatMessage(data);
|
|
|
|
},
|
|
|
|
|
2013-06-18 14:46:28 +00:00
|
|
|
joinMessage: function(data) {
|
|
|
|
if(USEROPTS.joinmessage)
|
|
|
|
addChatMessage(data);
|
|
|
|
},
|
|
|
|
|
2013-06-09 22:18:27 +00:00
|
|
|
clearchat: function() {
|
|
|
|
$("#messagebuffer").html("");
|
|
|
|
},
|
|
|
|
|
|
|
|
userlist: function(data) {
|
|
|
|
$(".userlist_item").each(function() { $(this).remove(); });
|
|
|
|
for(var i = 0; i < data.length; i++) {
|
|
|
|
Callbacks.addUser(data[i]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addUser: function(data) {
|
|
|
|
var div = $("<div/>").attr("class", "userlist_item");
|
|
|
|
var flair = $("<span/>").appendTo(div);
|
|
|
|
var nametag = $("<span/>").text(data.name).appendTo(div);
|
|
|
|
formatUserlistItem(div, data);
|
|
|
|
addUserDropdown(div, data.name);
|
|
|
|
var users = $("#userlist").children();
|
|
|
|
for(var i = 0; i < users.length; i++) {
|
|
|
|
var othername = users[i].children[1].innerHTML;
|
|
|
|
if(othername.toLowerCase() > data.name.toLowerCase()) {
|
|
|
|
div.insertBefore(users[i]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
div.appendTo($("#userlist"));
|
|
|
|
},
|
|
|
|
|
|
|
|
updateUser: function(data) {
|
|
|
|
if(data.name == CLIENT.name) {
|
|
|
|
CLIENT.leader = data.leader;
|
|
|
|
CLIENT.rank = data.rank;
|
|
|
|
handlePermissionChange();
|
|
|
|
if(CLIENT.leader) {
|
|
|
|
// I'm a leader! Set up sync function
|
|
|
|
if(LEADTMR)
|
|
|
|
clearInterval(LEADTMR);
|
|
|
|
LEADTMR = setInterval(function() {
|
|
|
|
PLAYER.getTime(function(seconds) {
|
|
|
|
socket.emit("mediaUpdate", {
|
|
|
|
id: PLAYER.id,
|
|
|
|
currentTime: seconds,
|
|
|
|
paused: PLAYER.paused,
|
|
|
|
type: PLAYER.type
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
// I'm not a leader. Don't send syncs to the server
|
|
|
|
else {
|
|
|
|
if(LEADTMR)
|
|
|
|
clearInterval(LEADTMR);
|
|
|
|
LEADTMR = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
var users = $("#userlist").children();
|
|
|
|
for(var i = 0; i < users.length; i++) {
|
|
|
|
var name = users[i].children[1].innerHTML;
|
|
|
|
// Reformat user
|
|
|
|
if(name == data.name) {
|
|
|
|
formatUserlistItem($(users[i]), data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
userLeave: function(data) {
|
|
|
|
var users = $("#userlist").children();
|
|
|
|
for(var i = 0; i < users.length; i++) {
|
|
|
|
var name = users[i].children[1].innerHTML;
|
|
|
|
if(name == data.name) {
|
|
|
|
$(users[i]).remove();
|
|
|
|
// Note: no break statement here because allowing
|
|
|
|
// the loop to continue means a free cleanup if something
|
|
|
|
// goes wrong and there's a duplicate name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-06-11 15:29:21 +00:00
|
|
|
drinkCount: function(count) {
|
|
|
|
if(count != 0) {
|
|
|
|
var text = count + " drink";
|
2013-06-11 23:51:00 +00:00
|
|
|
if(count != 1) {
|
2013-06-09 22:18:27 +00:00
|
|
|
text += "s";
|
|
|
|
}
|
|
|
|
$("#drinkcount").text(text);
|
|
|
|
$("#drinkbar").show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#drinkbar").hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* REGION Playlist Stuff */
|
|
|
|
playlist: function(data) {
|
|
|
|
// Clear the playlist first
|
|
|
|
var q = $("#queue");
|
|
|
|
q.html("");
|
|
|
|
|
|
|
|
for(var i = 0; i < data.length; i++) {
|
2013-06-25 03:03:21 +00:00
|
|
|
var li = makeQueueEntry(data[i], false);
|
|
|
|
li.attr("title", data[i].queueby
|
|
|
|
? ("Added by: " + data[i].queueby)
|
|
|
|
: "Added by: Unknown");
|
|
|
|
li.appendTo(q);
|
2013-06-09 22:18:27 +00:00
|
|
|
}
|
2013-06-26 01:49:02 +00:00
|
|
|
|
|
|
|
rebuildPlaylist();
|
2013-06-09 22:18:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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-07-03 15:26:10 +00:00
|
|
|
queueAction({
|
|
|
|
fn: function () {
|
|
|
|
var li = makeQueueEntry(data.item, true);
|
|
|
|
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);
|
|
|
|
li.show("blind");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(data.after === "append") {
|
|
|
|
li.appendTo(q);
|
|
|
|
li.show("blind");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var liafter = playlistFind(data.after);
|
|
|
|
if(!liafter) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
li.insertAfter(liafter);
|
|
|
|
li.show("blind");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-06-09 22:18:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
queueFail: function(data) {
|
|
|
|
if(!data) {
|
|
|
|
data = "Queue failed. Check your link to make sure it is valid.";
|
|
|
|
}
|
|
|
|
makeAlert("Error", data, "alert-error")
|
2013-06-26 03:09:37 +00:00
|
|
|
.addClass("span12")
|
2013-06-09 22:18:27 +00:00
|
|
|
.insertAfter($("#mediaurl").parent());
|
|
|
|
},
|
|
|
|
|
|
|
|
setTemp: function(data) {
|
2013-06-29 22:09:20 +00:00
|
|
|
var li = $(".pluid-" + data.uid);
|
|
|
|
if(li.length == 0)
|
|
|
|
return false;
|
|
|
|
|
2013-06-09 22:18:27 +00:00
|
|
|
if(data.temp)
|
|
|
|
li.addClass("queue_temp");
|
|
|
|
else
|
|
|
|
li.removeClass("queue_temp");
|
2013-06-29 22:09:20 +00:00
|
|
|
|
2013-07-09 17:21:40 +00:00
|
|
|
li.data("temp", data.temp);
|
2013-06-09 22:18:27 +00:00
|
|
|
var btn = li.find(".qbtn-tmp");
|
2013-06-27 22:15:29 +00:00
|
|
|
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"));
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
"delete": function(data) {
|
2013-07-03 15:26:10 +00:00
|
|
|
queueAction({
|
|
|
|
fn: function () {
|
2013-07-27 14:30:12 +00:00
|
|
|
PL_WAIT_SCROLL = true;
|
2013-07-03 15:26:10 +00:00
|
|
|
var li = $(".pluid-" + data.uid);
|
|
|
|
li.hide("blind", function() {
|
|
|
|
li.remove();
|
2013-07-27 14:30:12 +00:00
|
|
|
PL_WAIT_SCROLL = false;
|
2013-07-03 15:26:10 +00:00
|
|
|
});
|
2013-07-03 19:51:35 +00:00
|
|
|
return true;
|
2013-07-03 15:26:10 +00:00
|
|
|
}
|
2013-06-27 22:15:29 +00:00
|
|
|
});
|
2013-06-09 22:18:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
moveVideo: function(data) {
|
2013-07-03 15:26:10 +00:00
|
|
|
if(data.moveby != CLIENT.name) {
|
|
|
|
queueAction({
|
|
|
|
fn: function () {
|
|
|
|
playlistMove(data.from, data.after);
|
2013-07-03 19:51:35 +00:00
|
|
|
return true;
|
2013-07-03 15:26:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
},
|
|
|
|
|
2013-06-30 19:33:38 +00:00
|
|
|
setCurrent: function(uid) {
|
2013-07-03 15:26:10 +00:00
|
|
|
queueAction({
|
|
|
|
fn: function () {
|
|
|
|
PL_CURRENT = uid;
|
|
|
|
var qli = $("#queue li");
|
|
|
|
qli.removeClass("queue_active");
|
|
|
|
var li = $(".pluid-" + uid);
|
|
|
|
if(li.length == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
|
2013-07-03 15:26:10 +00:00
|
|
|
li.addClass("queue_active");
|
2013-07-27 14:30:12 +00:00
|
|
|
var timer = setInterval(function () {
|
|
|
|
if(!PL_WAIT_SCROLL) {
|
|
|
|
scrollQueue();
|
|
|
|
clearInterval(timer);
|
|
|
|
}
|
|
|
|
}, 100);
|
2013-07-03 19:51:35 +00:00
|
|
|
return true;
|
2013-07-03 15:32:44 +00:00
|
|
|
},
|
|
|
|
can_wait: true
|
2013-07-03 15:26:10 +00:00
|
|
|
});
|
2013-06-30 19:33:38 +00:00
|
|
|
},
|
2013-06-09 22:18:27 +00:00
|
|
|
|
2013-06-30 19:33:38 +00:00
|
|
|
changeMedia: function(data) {
|
2013-06-09 22:18:27 +00:00
|
|
|
if(CHANNEL.opts.allow_voteskip)
|
|
|
|
$("#voteskip").attr("disabled", false);
|
|
|
|
|
|
|
|
$("#currenttitle").text("Currently Playing: " + data.title);
|
2013-06-27 22:15:29 +00:00
|
|
|
|
2013-06-09 22:18:27 +00:00
|
|
|
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) {
|
2013-07-27 20:42:42 +00:00
|
|
|
if(data.type === "vi" && typeof $f !== "function") {
|
|
|
|
setTimeout(function () {
|
|
|
|
Callbacks.changeMedia(data);
|
|
|
|
}, 100);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
PLAYER = new Player(data);
|
|
|
|
}
|
|
|
|
if(PLAYER.update) {
|
|
|
|
PLAYER.update(data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mediaUpdate: function(data) {
|
|
|
|
if(PLAYER.update) {
|
|
|
|
PLAYER.update(data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setPlaylistLocked: function(data) {
|
|
|
|
CHANNEL.openqueue = !data.locked;
|
2013-06-11 15:29:21 +00:00
|
|
|
handlePermissionChange();
|
2013-06-09 22:18:27 +00:00
|
|
|
if(CHANNEL.openqueue) {
|
|
|
|
$("#qlockbtn").removeClass("btn-danger")
|
|
|
|
.addClass("btn-success")
|
|
|
|
.text("Lock Playlist");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#qlockbtn").removeClass("btn-success")
|
|
|
|
.addClass("btn-danger")
|
|
|
|
.text("Unlock Playlist");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
searchResults: function(data) {
|
2013-06-22 23:02:55 +00:00
|
|
|
$("#search_clear").remove();
|
2013-06-09 22:18:27 +00:00
|
|
|
clearSearchResults();
|
|
|
|
$("#library").data("entries", data.results);
|
|
|
|
if(data.results.length > 100) {
|
|
|
|
var pag = $("<div/>").addClass("pagination")
|
|
|
|
.attr("id", "search_pagination")
|
|
|
|
.insertAfter($("#library"));
|
|
|
|
var btns = $("<ul/>").appendTo(pag);
|
|
|
|
for(var i = 0; i < data.results.length / 100; i++) {
|
|
|
|
var li = $("<li/>").appendTo(btns);
|
|
|
|
(function(i) {
|
|
|
|
$("<a/>").attr("href", "javascript:void(0)")
|
|
|
|
.text(i+1)
|
|
|
|
.click(function() {
|
|
|
|
loadSearchPage(i);
|
|
|
|
})
|
|
|
|
.appendTo(li);
|
|
|
|
})(i);
|
|
|
|
}
|
|
|
|
}
|
2013-06-22 23:02:55 +00:00
|
|
|
$("<button/>").addClass("btn btn-block")
|
2013-06-25 14:29:12 +00:00
|
|
|
.addClass("span12")
|
|
|
|
.css("margin-left", "0")
|
2013-06-22 23:02:55 +00:00
|
|
|
.attr("id", "search_clear")
|
|
|
|
.text("Clear Results")
|
|
|
|
.click(function() {
|
|
|
|
clearSearchResults();
|
|
|
|
})
|
|
|
|
.insertBefore($("#library"));
|
2013-06-09 22:18:27 +00:00
|
|
|
loadSearchPage(0);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* REGION Polls */
|
|
|
|
newPoll: function(data) {
|
|
|
|
Callbacks.closePoll();
|
|
|
|
var pollMsg = $("<div/>").addClass("poll-notify")
|
|
|
|
.text(data.initiator + " opened a poll: \"" + data.title + "\"")
|
|
|
|
.appendTo($("#messagebuffer"));
|
|
|
|
scrollChat();
|
|
|
|
|
2013-06-11 19:41:03 +00:00
|
|
|
var poll = $("<div/>").addClass("well active").prependTo($("#pollwrap"));
|
2013-06-09 22:18:27 +00:00
|
|
|
$("<button/>").addClass("close pull-right").html("×")
|
|
|
|
.appendTo(poll)
|
|
|
|
.click(function() { poll.remove(); });
|
|
|
|
if(hasPermission("pollctl")) {
|
|
|
|
$("<button/>").addClass("btn btn-danger pull-right").text("End Poll")
|
|
|
|
.appendTo(poll)
|
|
|
|
.click(function() {
|
|
|
|
socket.emit("closePoll")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$("<h3/>").text(data.title).appendTo(poll);
|
|
|
|
for(var i = 0; i < data.options.length; i++) {
|
|
|
|
(function(i) {
|
|
|
|
var callback = function() {
|
|
|
|
socket.emit("vote", {
|
|
|
|
option: i
|
|
|
|
});
|
|
|
|
poll.find(".option button").each(function() {
|
|
|
|
$(this).attr("disabled", "disabled");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$("<button/>").addClass("btn").text(data.counts[i])
|
|
|
|
.prependTo($("<div/>").addClass("option").text(data.options[i])
|
|
|
|
.appendTo(poll))
|
|
|
|
.click(callback);
|
|
|
|
})(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
poll.find(".btn").attr("disabled", !hasPermission("pollvote"));
|
|
|
|
},
|
|
|
|
|
|
|
|
updatePoll: function(data) {
|
2013-06-19 23:39:40 +00:00
|
|
|
var poll = $("#pollwrap .active");
|
2013-06-09 22:18:27 +00:00
|
|
|
var i = 0;
|
|
|
|
poll.find(".option button").each(function() {
|
|
|
|
$(this).text(data.counts[i]);
|
|
|
|
i++;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
closePoll: function() {
|
2013-06-11 19:41:03 +00:00
|
|
|
if($("#pollwrap .active").length != 0) {
|
|
|
|
var poll = $("#pollwrap .active");
|
2013-06-09 22:18:27 +00:00
|
|
|
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 {
|
|
|
|
makeAlert("Error", data.error, "alert-error")
|
|
|
|
.addClass("span12")
|
|
|
|
.insertBefore($("#userpl_list"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
listPlaylists: function(data) {
|
|
|
|
if(data.error) {
|
|
|
|
makeAlert("Error", data.error, "alert-error")
|
|
|
|
.addClass("span12")
|
|
|
|
.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/>")
|
|
|
|
.addClass("btn btn-mini btn-danger")
|
|
|
|
.prependTo(bg);
|
|
|
|
$("<i/>").addClass("icon-trash").appendTo(del);
|
|
|
|
(function(li) {
|
|
|
|
del.click(function() {
|
2013-06-21 03:11:38 +00:00
|
|
|
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")
|
|
|
|
});
|
|
|
|
}
|
2013-06-09 22:18:27 +00:00
|
|
|
});
|
|
|
|
})(li);
|
|
|
|
if(hasPermission("playlistaddlist")) {
|
|
|
|
(function(li) {
|
|
|
|
$("<button/>").addClass("btn btn-mini")
|
|
|
|
.text("End")
|
|
|
|
.prependTo(bg)
|
|
|
|
.click(function() {
|
|
|
|
socket.emit("queuePlaylist", {
|
|
|
|
name: li.data("pl-name"),
|
|
|
|
pos: "end"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})(li);
|
|
|
|
|
|
|
|
if(hasPermission("playlistnext")) {
|
|
|
|
(function(li) {
|
|
|
|
$("<button/>").addClass("btn btn-mini")
|
|
|
|
.text("Next")
|
|
|
|
.prependTo(bg)
|
|
|
|
.click(function() {
|
|
|
|
socket.emit("queuePlaylist", {
|
|
|
|
name: li.data("pl-name"),
|
|
|
|
pos: "next"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})(li);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-29 22:09:20 +00:00
|
|
|
|
2013-07-09 17:24:25 +00:00
|
|
|
var SOCKET_DEBUG = false;
|
2013-06-09 22:18:27 +00:00
|
|
|
setupCallbacks = function() {
|
|
|
|
for(var key in Callbacks) {
|
|
|
|
(function(key) {
|
2013-06-11 15:29:21 +00:00
|
|
|
socket.on(key, function(data) {
|
2013-06-29 22:09:20 +00:00
|
|
|
if(SOCKET_DEBUG)
|
|
|
|
console.log(key, data);
|
2013-06-11 15:29:21 +00:00
|
|
|
Callbacks[key](data);
|
2013-06-09 22:18:27 +00:00
|
|
|
});
|
|
|
|
})(key);
|
|
|
|
}
|
|
|
|
}
|
2013-06-11 15:29:21 +00:00
|
|
|
|
2013-07-13 20:15:57 +00:00
|
|
|
$.getScript(IO_URL+"/socket.io/socket.io.js", function() {
|
|
|
|
try {
|
|
|
|
if(NO_WEBSOCKETS) {
|
|
|
|
var i = io.transports.indexOf("websocket");
|
|
|
|
if(i >= 0)
|
|
|
|
io.transports.splice(i, 1);
|
|
|
|
}
|
|
|
|
socket = io.connect(IO_URL);
|
|
|
|
setupCallbacks();
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
Callbacks.disconnect();
|
|
|
|
}
|
|
|
|
});
|