1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-10 07:43:49 +00:00

If host and recipe are missing from connection then infer them from the page environment

This commit is contained in:
Jeremy Ruston 2012-11-20 16:31:25 +00:00
parent 7df29453e0
commit 3087c2001c

View File

@ -55,13 +55,13 @@ TiddlyWebSyncer.prototype.addConnection = function(connection) {
if(this.connection) { if(this.connection) {
return new Error("TiddlyWebSyncer can only handle a single connection"); return new Error("TiddlyWebSyncer can only handle a single connection");
} }
// Check the connection has its constituent parts // If we don't have a host then substitute the host of the page
if(!connection.host || !connection.recipe) { if(!connection.host) {
return new Error("Missing connection data"); connection.host = document.location.protocol + "//" + document.location.host + "/";
} }
// Mark us as not logged in // Mark us as not logged in
this.wiki.addTiddler({title: TiddlyWebSyncer.titleIsLoggedIn,text: "no"}); this.wiki.addTiddler({title: TiddlyWebSyncer.titleIsLoggedIn,text: "no"});
// Save and return the connection object // Save the connection object
this.connection = connection; this.connection = connection;
// Listen out for changes to tiddlers // Listen out for changes to tiddlers
this.wiki.addEventListener("",function(changes) { this.wiki.addEventListener("",function(changes) {
@ -124,6 +124,10 @@ TiddlyWebSyncer.prototype.getStatus = function(callback) {
} catch (e) { } catch (e) {
} }
if(json) { if(json) {
// Use the recipe if we don't already have one
if(!self.connection.recipe) {
self.connection.recipe = json.space.recipe;
}
// Check if we're logged in // Check if we're logged in
isLoggedIn = json.username !== "GUEST"; isLoggedIn = json.username !== "GUEST";
// Set the various status tiddlers // Set the various status tiddlers