summaryrefslogtreecommitdiff
path: root/src/static/js/pad.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/static/js/pad.js')
-rw-r--r--src/static/js/pad.js114
1 files changed, 73 insertions, 41 deletions
diff --git a/src/static/js/pad.js b/src/static/js/pad.js
index 73fcd3d6..994d7845 100644
--- a/src/static/js/pad.js
+++ b/src/static/js/pad.js
@@ -51,6 +51,8 @@ var gritter = require('./gritter').gritter;
var hooks = require('./pluginfw/hooks');
+var receivedClientVars = false;
+
function createCookie(name, value, days, path){ /* Warning Internet Explorer doesn't use this it uses the one from pad_utils.js */
if (days)
{
@@ -160,6 +162,59 @@ function savePassword()
return false;
}
+function sendClearSessionInfo()
+{
+ var msg = {
+ "component": "pad",
+ "type": "CLEAR_SESSION_INFO",
+ "protocolVersion": 2
+ };
+
+ socket.json.send(msg);
+}
+
+function sendClientReady(isReconnect)
+{
+ var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);
+ padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
+
+ if(!isReconnect)
+ {
+ var titleArray = document.title.split('|');
+ var title = titleArray[titleArray.length - 1];
+ document.title = padId.replace(/_+/g, ' ') + " | " + title;
+ }
+
+ var token = readCookie("token");
+ if (token == null)
+ {
+ token = "t." + randomString();
+ createCookie("token", token, 60);
+ }
+
+ var sessionID = decodeURIComponent(readCookie("sessionID"));
+ var password = readCookie("password");
+
+ var msg = {
+ "component": "pad",
+ "type": "CLIENT_READY",
+ "padId": padId,
+ "sessionID": sessionID,
+ "password": password,
+ "token": token,
+ "protocolVersion": 2
+ };
+
+ //this is a reconnect, lets tell the server our revisionnumber
+ if(isReconnect == true)
+ {
+ msg.client_rev=pad.collabClient.getCurrentRevisionNumber();
+ msg.reconnect=true;
+ }
+
+ socket.json.send(msg);
+}
+
function handshake()
{
var loc = document.location;
@@ -176,44 +231,6 @@ function handshake()
'sync disconnect on unload' : false
});
- function sendClientReady(isReconnect)
- {
- var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);
- padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
-
- if(!isReconnect)
- document.title = padId.replace(/_+/g, ' ') + " | " + document.title;
-
- var token = readCookie("token");
- if (token == null)
- {
- token = "t." + randomString();
- createCookie("token", token, 60);
- }
-
- var sessionID = decodeURIComponent(readCookie("sessionID"));
- var password = readCookie("password");
-
- var msg = {
- "component": "pad",
- "type": "CLIENT_READY",
- "padId": padId,
- "sessionID": sessionID,
- "password": password,
- "token": token,
- "protocolVersion": 2
- };
-
- //this is a reconnect, lets tell the server our revisionnumber
- if(isReconnect == true)
- {
- msg.client_rev=pad.collabClient.getCurrentRevisionNumber();
- msg.reconnect=true;
- }
-
- socket.json.send(msg);
- };
-
var disconnectTimeout;
socket.once('connect', function () {
@@ -228,7 +245,7 @@ function handshake()
}
pad.collabClient.setChannelState("CONNECTED");
- sendClientReady(true);
+ pad.sendClientReady(true);
});
socket.on('disconnect', function (reason) {
@@ -246,7 +263,6 @@ function handshake()
}
});
- var receivedClientVars = false;
var initalized = false;
socket.on('message', function(obj)
@@ -286,7 +302,7 @@ function handshake()
}
//if we haven't recieved the clientVars yet, then this message should it be
- else if (!receivedClientVars)
+ else if (!receivedClientVars && obj.type == "CLIENT_VARS")
{
//log the message
if (window.console) console.log(obj);
@@ -426,6 +442,22 @@ var pad = {
{
return pad.myUserInfo.name;
},
+ sendClientReady: function(isReconnect)
+ {
+ sendClientReady(isReconnect);
+ },
+ switchToPad: function(padId)
+ {
+ var options = document.location.href.split('?')[1];
+ if(options != null)
+ window.history.pushState("", "", "/p/" + padId + '?' + options);
+ else
+ window.history.pushState("", "", "/p/" + padId);
+
+ sendClearSessionInfo();
+ receivedClientVars = false;
+ sendClientReady(false);
+ },
sendClientMessage: function(msg)
{
pad.collabClient.sendClientMessage(msg);