Began adding support for passing parameters via the URL and removed a location redirect that was no longer needed

This commit is contained in:
John McLear 2011-08-12 16:00:09 +01:00
parent a5b84f1b6e
commit fb593c1d5c
1 changed files with 37 additions and 11 deletions

View File

@ -20,18 +20,9 @@ var socket;
$(document).ready(function() $(document).ready(function()
{ {
//test if the url is proper, means without any ? or # that doesn't belong to a url
//if it isn't proper, clean the url a do a redirect
var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);
var expectedURL = document.location.href.substring(0,document.location.href.lastIndexOf("/") ) + "/" + padId;
if(expectedURL != document.location.href)
{
document.location = expectedURL;
}
//start the costum js //start the costum js
if(typeof costumStart == "function") costumStart(); if(typeof costumStart == "function") costumStart();
getParams();
handshake(); handshake();
}); });
@ -78,6 +69,42 @@ function randomString()
return "t." + randomstring; return "t." + randomstring;
} }
function getParams()
{
var showControls = getUrlVars()["showControls"];
var showChat = getUrlVars()["showChat"];
var userName = getUrlVars()["userName"];
if(showControls)
{
if(showControls == "false")
{
$('#editbar').hide();
$('#editorcontainer').css({"top":"0px"});
}
}
if(showChat)
{
if(showChat == "false"){$('#chaticon').hide();}
//cake
}
}
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
function handshake() function handshake()
{ {
var loc = document.location; var loc = document.location;
@ -95,7 +122,6 @@ function handshake()
socket.once('connect', function() socket.once('connect', function()
{ {
var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1); var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);
document.title = document.title + " | " + padId; document.title = document.title + " | " + padId;
var token = readCookie("token"); var token = readCookie("token");