From b5ec80d02f2745d84f079a32eef031c421353ba3 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Thu, 6 Jun 2013 23:13:24 -0400 Subject: [PATCH] Continue working on rewriting stuff --- www/assets/js/data.js | 72 +++++++++++++++++++++++ www/assets/js/ui.js | 130 +++++++++++++++++++++++++++++++++++++++++- www/channel-new.html | 3 + 3 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 www/assets/js/data.js diff --git a/www/assets/js/data.js b/www/assets/js/data.js new file mode 100644 index 00000000..cb639879 --- /dev/null +++ b/www/assets/js/data.js @@ -0,0 +1,72 @@ +var CLIENT = { + rank: -1, + name: "", + logged_in: false, + profile: { + image: "", + text: "" + } +}; + +var CHANNEL = { + opts: {}, + openqueue: false, + perms: {}, +}; + +var PLAYER = false; +var VWIDTH = $("#ytapiplayer").parent().css("width").replace("px", ""); +var VHEIGHT = ""+parseInt(parseInt(VWIDTH) * 9 / 16); +var POSITION = -1; +var socket; +var IGNORED = []; +var CHATHIST = []; +var CHATHISTIDX = 0; +var SCROLLCHAT = true; +var LASTCHATNAME = ""; +var LASTCHATTIME = 0; +var FOCUSED = true; +var PAGETITLE = "CyTube"; +var TITLE_BLINK; +var KICKED = false; +var NAME = readCookie("cytube_uname"); +var SESSION = readCookie("cytube_session"); + +function getOrDefault(k, def) { + var v = localStorage.getItem(k); + if(v === null) + return def; + if(v === "true") + return true; + if(v === "false") + return false; + if(v.match(/[0-9]+/)) + return parseInt(v); + if(v.match(/[0-9\.]+/)) + return parseFloat(v); + return v; +} + +var USEROPTS = { + theme : getOrDefault("theme", "default"), + css : getOrDefault("css", ""), + layout : getOrDefault("layout", "default"), + synch : getOrDefault("synch", true), + hidevid : getOrDefault("hidevid", false), + show_timestamps : getOrDefault("show_timestamps", true), + modhat : getOrDefault("modhat", false), + blink_title : getOrDefault("blink_title", false), + sync_accuracy : getOrDefault("sync_accuracy", 2), + chatbtn : getOrDefault("chatbtn", false), + altsocket : getOrDefault("altsocket", false) +}; + +var Rank = { + Guest: 0, + Member: 1, + Leader: 1.5, + Moderator: 2, + Admin: 3, + Owner: 10, + Siteadmin: 255 +}; diff --git a/www/assets/js/ui.js b/www/assets/js/ui.js index abd7f926..85e22322 100644 --- a/www/assets/js/ui.js +++ b/www/assets/js/ui.js @@ -14,8 +14,136 @@ function generateToggle(chevron, div) { }); } - +/* setup show/hide toggles */ generateToggle("#usercountwrap", "#userlist"); generateToggle("#librarytoggle", "#librarywrap"); generateToggle("#userpltoggle", "#userplaylistwrap"); generateToggle("#playlisttoggle", "#playlist_controls"); + +/* navbar stuff */ +$("#optlink").click(showOptionsMenu); +$("#guestlogin").click(function() { + socket && socket.emit("login", { + name: $("#guestname").val(), + }); +}); +$("#login").click(showLoginMenu); +$("#logout").click(function() { + eraseCookie("cytube_name"); + eraseCookie("cytube_session"); + document.ocation.reload(true); +}); + +/* chatbox */ +$("#chatline").keyDown(function(ev) { + 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 */ diff --git a/www/channel-new.html b/www/channel-new.html index d21a0dff..2676726b 100644 --- a/www/channel-new.html +++ b/www/channel-new.html @@ -89,6 +89,8 @@
+ +
@@ -167,6 +169,7 @@ +