/* 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. */ /* So, it turns out that $.post causes Firefox to use a GET request on cross-site requests. What the hell? I'd understand if they just made it error instead, but why give me chicken tenders if I ordered a cheeseburger and act like everything's peachy? */ function postJSON(url, data, callback) { $.ajax(url, { method: "POST", crossDomain: true, data: data, success: function (data) { try { data = data.substring(data.indexOf("{")); data = data.substring(0, data.lastIndexOf("}") + 1); data = JSON.parse(data); callback(data); } catch(e) { return; } }, dataType: "text" }); } var uname = readCookie("cytube_uname") || ""; var session = readCookie("cytube_session") || ""; var loggedin = false; if(uname && session) { var data = { name: uname, session: session }; postJSON(WEB_URL + "/api/login?callback=?", data, function (data) { console.log(data); if(data.success) onLogin(); }); } function onLogin() { $("#cpwusername").val(uname); $("#ceusername").val(uname); $("#accountnav li")[0].innerHTML = "Logged in as " + uname; $("#register").hide(); loggedin = true; $("#login").text("Logout"); createCookie("cytube_uname", uname, 7); createCookie("cytube_session", session, 7); } function makeTabCallback(tabid, paneid) { return function() { $("#accountnav li").each(function() { $(this).removeClass("active"); }); $(tabid).parent().addClass("active"); $(".span7").each(function() { $(this).css("display", "none"); }); $(paneid).css("display", ""); }; } $("#register").click(makeTabCallback("#register", "#registerpane")); $("#pwchange").click(makeTabCallback("#pwchange", "#changepwpane")); $("#pwreset").click(makeTabCallback("#pwreset", "#pwresetpane")); $("#email").click(makeTabCallback("#email", "#changeemailpane")); $("#profile").click(makeTabCallback("#profile", "#profilepane")); $("#profile").click(function() { if(uname != "") { $.getJSON(WEB_URL+"/api/users/"+uname+"/profile?callback=?", function (data) { if(data.success) { $("#profiletext").val(data.profile_text); $("#profileimg").val(data.profile_image); } else { $("
").addClass("alert alert-error") .text("Failed to retrieve profile: " + data.error) .insertBefore($("#profilepane form")); } }); } }); $("#channels").click(makeTabCallback("#channels", "#channelspane")); $("#channels").click(function () { if(!loggedin) { var error = $("
").addClass("alert alert-error") .text("You must be logged in to view this page") .insertBefore($("#channellist")); $("