From fb593c1d5c16957109b5f3e521857fad000776bb Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 12 Aug 2011 16:00:09 +0100 Subject: [PATCH 1/3] Began adding support for passing parameters via the URL and removed a location redirect that was no longer needed --- static/js/pad2.js | 48 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/static/js/pad2.js b/static/js/pad2.js index f442607d7..1dd490497 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -20,18 +20,9 @@ var socket; $(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 if(typeof costumStart == "function") costumStart(); - + getParams(); handshake(); }); @@ -78,6 +69,42 @@ function 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() { var loc = document.location; @@ -95,7 +122,6 @@ function handshake() socket.once('connect', function() { var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1); - document.title = document.title + " | " + padId; var token = readCookie("token"); From 8db0c12bbe7cbe0fada49c31bd200cf8daafd524 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 13 Aug 2011 18:37:44 +0100 Subject: [PATCH 2/3] Add support for removing line numbers using the jQuery API and stopped it publishing that change back if the param is set --- static/js/pad2.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/static/js/pad2.js b/static/js/pad2.js index 1dd490497..1364b5e7a 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -17,6 +17,7 @@ /* global $, window */ var socket; +var LineNumbersDisabled = false; $(document).ready(function() { @@ -74,6 +75,7 @@ function getParams() var showControls = getUrlVars()["showControls"]; var showChat = getUrlVars()["showChat"]; var userName = getUrlVars()["userName"]; + var showLineNumbers = getUrlVars()["showLineNumbers"]; if(showControls) { if(showControls == "false") @@ -85,11 +87,20 @@ function getParams() if(showChat) { - if(showChat == "false"){$('#chaticon').hide();} - -//cake + if(showChat == "false") + { + $('#chaticon').hide(); + } } + if(showLineNumbers) + { + if(showLineNumbers == "false") + { + // pad.changeViewOption('showLineNumbers', false); + LineNumbersDisabled = true; + } + } } function getUrlVars() @@ -138,7 +149,6 @@ function handshake() "token": token, "protocolVersion": 2 }; - socket.json.send(msg); }); @@ -159,8 +169,12 @@ function handshake() clientVars.collab_client_vars.clientAgent = "Anonymous"; pad.init(); - initalized = true; + if (LineNumbersDisabled == true) + { + // cake + pad.changeViewOption('showLineNumbers', false); $ + } } //This handles every Message after the clientVars else @@ -374,12 +388,15 @@ var pad = { }; options.view[key] = value; pad.handleOptionsChange(options); - pad.collabClient.sendClientMessage( + if (key != "showLineNumbers") { - type: 'padoptions', - options: options, - changedBy: pad.myUserInfo.name || "unnamed" - }); + pad.collabClient.sendClientMessage( + { + type: 'padoptions', + options: options, + changedBy: pad.myUserInfo.name || "unnamed" + }); + } }, handleOptionsChange: function(opts) { From 7f288896601f5be5d623ebaf8faa1ee1d7780abc Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 13 Aug 2011 18:38:00 +0100 Subject: [PATCH 3/3] Removed my cake commit that I used as a placemarker --- static/js/pad2.js | 1 - 1 file changed, 1 deletion(-) diff --git a/static/js/pad2.js b/static/js/pad2.js index 1364b5e7a..5705218d8 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -172,7 +172,6 @@ function handshake() initalized = true; if (LineNumbersDisabled == true) { - // cake pad.changeViewOption('showLineNumbers', false); $ } }