2013-06-06 23:38:47 +00:00
|
|
|
/* Generalized show/hide function */
|
|
|
|
function generateToggle(chevron, div) {
|
|
|
|
$(chevron).click(function() {
|
|
|
|
if($(div).css("display") == "none") {
|
2013-06-09 18:03:41 +00:00
|
|
|
$(chevron).html($(chevron).html().replace(/Show/, "Hide"));
|
2013-06-06 23:38:47 +00:00
|
|
|
$(div).show();
|
|
|
|
$(chevron+" i").removeClass("icon-chevron-down")
|
|
|
|
.addClass("icon-chevron-up");
|
|
|
|
}
|
|
|
|
else {
|
2013-06-09 18:03:41 +00:00
|
|
|
$(chevron).html($(chevron).html().replace(/Hide/, "Show"));
|
2013-06-06 23:38:47 +00:00
|
|
|
$(div).hide();
|
|
|
|
$(chevron+" i").removeClass("icon-chevron-up")
|
|
|
|
.addClass("icon-chevron-down");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-06-06 21:48:21 +00:00
|
|
|
|
2013-06-07 03:13:24 +00:00
|
|
|
/* setup show/hide toggles */
|
2013-06-06 23:38:47 +00:00
|
|
|
generateToggle("#usercountwrap", "#userlist");
|
|
|
|
generateToggle("#librarytoggle", "#librarywrap");
|
|
|
|
generateToggle("#userpltoggle", "#userplaylistwrap");
|
|
|
|
generateToggle("#playlisttoggle", "#playlist_controls");
|
2013-06-07 03:13:24 +00:00
|
|
|
|
|
|
|
/* navbar stuff */
|
|
|
|
$("#optlink").click(showOptionsMenu);
|
2013-06-07 22:09:36 +00:00
|
|
|
|
|
|
|
function guestLogin() {
|
|
|
|
socket.emit("login", {
|
2013-06-07 03:13:24 +00:00
|
|
|
name: $("#guestname").val(),
|
|
|
|
});
|
2013-06-07 22:09:36 +00:00
|
|
|
}
|
|
|
|
$("#guestlogin").click(guestLogin);
|
|
|
|
$("#guestname").keydown(function(ev) {
|
|
|
|
if(ev.keyCode == 13) {
|
|
|
|
guestLogin();
|
|
|
|
}
|
2013-06-07 03:13:24 +00:00
|
|
|
});
|
2013-06-07 22:09:36 +00:00
|
|
|
|
2013-06-07 03:13:24 +00:00
|
|
|
$("#login").click(showLoginMenu);
|
|
|
|
$("#logout").click(function() {
|
|
|
|
eraseCookie("cytube_name");
|
|
|
|
eraseCookie("cytube_session");
|
2013-06-07 22:09:36 +00:00
|
|
|
document.location.reload(true);
|
2013-06-07 03:13:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/* chatbox */
|
2013-06-09 18:03:41 +00:00
|
|
|
$("#chatline").keydown(function(ev) {
|
2013-06-07 03:13:24 +00:00
|
|
|
if(ev.keyCode == 13) {
|
|
|
|
var msg = $("#chatline").val();
|
|
|
|
if(msg.trim()) {
|
|
|
|
if(USEROPTS.modhat && CLIENT.rank >= Rank.Moderator) {
|
|
|
|
msg = "/m " + msg;
|
|
|
|
}
|
|
|
|
socket.emit("chatMsg", {
|
|
|
|
msg: msg
|
|
|
|
});
|
|
|
|
CHATHIST.push($("#chatline").val());
|
|
|
|
CHATLISTIDX = CHATHIST.length;
|
|
|
|
$("#chatline").val("");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(ev.keyCode == 9) {
|
|
|
|
var words = $("#chatline").val().split(" ");
|
|
|
|
var current = words[words.length - 1].toLowerCase();
|
|
|
|
var users = $("#userlist").children();
|
|
|
|
var match = null;
|
|
|
|
for(var i = 0; i < users.length; i++) {
|
|
|
|
var name = users[i].children[1].innerHTML.toLowerCase();
|
|
|
|
if(name.indexOf(current) == 0 && match == null) {
|
|
|
|
match = users[i].children[1].innerHTML;
|
|
|
|
}
|
|
|
|
else if(name.indexOf(current) == 0) {
|
|
|
|
match = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(match != null) {
|
|
|
|
words[words.length - 1] = match;
|
|
|
|
if(words.length == 1)
|
|
|
|
words[0] += ": ";
|
|
|
|
else
|
|
|
|
words[words.length - 1] += " ";
|
|
|
|
$("#chatline").val(words.join(" "));
|
|
|
|
}
|
|
|
|
ev.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(ev.keyCode == 38) {
|
|
|
|
if(CHATHISTIDX == CHATHIST.length) {
|
|
|
|
CHATHIST.push($("#chatline").val());
|
|
|
|
}
|
|
|
|
if(CHATHISTIDX > 0) {
|
|
|
|
CHATHISTIDX--;
|
|
|
|
$("#chatline").val(CHATHIST[CHATHISTIDX]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(ev.keyCode == 40) {
|
|
|
|
if(CHATHISTIDX < CHATHIST.length - 1) {
|
|
|
|
CHATHISTIDX++;
|
|
|
|
$("#chatline").val(CHATHIST[CHATHISTIDX]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* poll controls */
|
|
|
|
$("#newpollbtn").click(showPollMenu);
|
|
|
|
|
|
|
|
/* search controls */
|
|
|
|
$("#library_search").click(function() {
|
|
|
|
socket.emit("searchMedia", {
|
|
|
|
source: "library",
|
|
|
|
query: $("#library_query").val().toLowerCase()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#library_query").keydown(function(ev) {
|
|
|
|
if(ev.keyCode == 13) {
|
|
|
|
socket.emit("searchMedia", {
|
|
|
|
source: "library",
|
|
|
|
query: $("#library_query").val().toLowerCase()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#youtube_search").click(function() {
|
|
|
|
socket.emit("searchMedia", {
|
|
|
|
source: "yt",
|
|
|
|
query: $("#library_query").val().toLowerCase()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/* user playlists */
|
|
|
|
|
|
|
|
$("#userpltoggle").click(function() {
|
|
|
|
socket.emit("listPlaylists");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#userpl_save").click(function() {
|
|
|
|
if($("#userpl_name").val().trim() == "") {
|
|
|
|
makeAlert("Invalid Name", "Playlist name cannot be empty", "alert-error")
|
|
|
|
.addClass("span12")
|
|
|
|
.insertAfter($("#userpl_save").parent());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
socket.emit("savePlaylist", {
|
|
|
|
name: $("#userpl_name").val()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/* playlist controls */
|
2013-06-07 22:09:36 +00:00
|
|
|
|
2013-06-09 18:03:41 +00:00
|
|
|
$(function() {
|
|
|
|
$("#queue").sortable();
|
|
|
|
$("#queue").disableSelection();
|
|
|
|
});
|
|
|
|
|
2013-06-07 22:09:36 +00:00
|
|
|
function queue(pos) {
|
|
|
|
var links = $("#mediaurl").val().split(",");
|
|
|
|
if(pos == "next") {
|
|
|
|
links = links.reverse();
|
|
|
|
}
|
|
|
|
links.forEach(function(link) {
|
|
|
|
var data = parseMediaLink(link);
|
|
|
|
socket.emit("queue", {
|
|
|
|
id: data.id,
|
|
|
|
type: data.type,
|
|
|
|
pos: "end"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#queue_next").click(function() {
|
|
|
|
queue("next");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#queue_end").click(function() {
|
|
|
|
queue("end");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#mediaurl").keydown(function(ev) {
|
|
|
|
if(ev.keyCode == 13) {
|
|
|
|
queue("end");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#qlockbtn").click(function() {
|
|
|
|
socket.emit("togglePlaylistLock");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#getplaylist").click(function() {
|
|
|
|
var callback = function(data) {
|
|
|
|
socket.listeners("playlist").splice(
|
|
|
|
socket.listeners("playlist").indexOf(callback)
|
|
|
|
);
|
|
|
|
var list = [];
|
|
|
|
for(var i = 0; i < data.pl.length; i++) {
|
|
|
|
var entry = formatURL(data.pl[i]);
|
|
|
|
// TODO formatURL in util.js
|
|
|
|
list.push(entry);
|
|
|
|
}
|
|
|
|
var urls = list.join(",");
|
|
|
|
|
|
|
|
var modal = $("<div/>").addClass("modal hide fade")
|
|
|
|
.appendTo($("body"));
|
|
|
|
var head = $("<div/>").addClass("modal-header")
|
|
|
|
.appendTo(modal);
|
|
|
|
$("<button/>").addClass("close")
|
|
|
|
.attr("data-dismiss", "modal")
|
|
|
|
.attr("aria-hidden", "true")
|
|
|
|
.html("×")
|
|
|
|
.appendTo(head);
|
|
|
|
$("<h3/>").text("Playlist URLs").appendTo(head);
|
|
|
|
var body = $("<div/>").addClass("modal-body").appendTo(modal);
|
|
|
|
$("<input/>").attr("type", "text")
|
|
|
|
.val(urls)
|
|
|
|
.appendTo(body);
|
|
|
|
$("<div/>").addClass("modal-footer").appendTo(modal);
|
|
|
|
modal.on("hidden", function() {
|
|
|
|
modal.remove();
|
|
|
|
});
|
|
|
|
modal.modal();
|
|
|
|
}
|
|
|
|
socket.on("playlist", callback);
|
|
|
|
socket.emit("requestPlaylist");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#clearplaylist").click(function() {
|
|
|
|
var clear = confirm("Are you sure you want to clear the playlist?");
|
|
|
|
if(clear) {
|
|
|
|
socket.emit("clearPlaylist");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#shuffleplaylist").click(function() {
|
|
|
|
var clear = confirm("Are you sure you want to shuffle the playlist?");
|
|
|
|
if(clear) {
|
|
|
|
socket.emit("shufflePlaylist");
|
|
|
|
}
|
|
|
|
});
|