From 149216ff7d5a4f62502f8b6dc6bb2c4f71657a0f Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 10 Oct 2012 22:46:59 +0100 Subject: [PATCH] Compute wikiname from document URL --- tw5dropbox/appwiki/plugins/dropbox-app.js | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tw5dropbox/appwiki/plugins/dropbox-app.js b/tw5dropbox/appwiki/plugins/dropbox-app.js index a2fe81ffa..86640d689 100644 --- a/tw5dropbox/appwiki/plugins/dropbox-app.js +++ b/tw5dropbox/appwiki/plugins/dropbox-app.js @@ -12,11 +12,28 @@ Startup the Dropbox wiki app /*global $tw: false */ "use strict"; +var titleWikiName = "$:/plugins/dropbox/WikiName"; + exports.startup = function() { - // Load tiddlers - $tw.plugins.dropbox.loadTiddlerFiles("/My TiddlyWiki/tiddlers",function() { - console.log("Loaded all tiddlers",$tw.wiki.tiddlers); - }); + // Check that we've been loaded from the dropbox + var url = (window.location.protocol + "//" + window.location.host + window.location.pathname), + wikiName; + if(url.indexOf($tw.plugins.dropbox.userInfo.publicAppUrl) === 0) { + var p = url.indexOf("/",$tw.plugins.dropbox.userInfo.publicAppUrl.length + 1); + if(p !== -1 && url.substr(p) === "/index.html") { + wikiName = decodeURIComponent(url.substring($tw.plugins.dropbox.userInfo.publicAppUrl.length + 1,p)); + } + } + if(wikiName) { + $tw.plugins.dropbox.wikiName = wikiName; + $tw.wiki.addTiddler({title: titleWikiName, text: $tw.plugins.dropbox.wikiName}); + // Load tiddlers + $tw.plugins.dropbox.loadTiddlerFiles("/" + $tw.plugins.dropbox.wikiName + "/tiddlers",function() { + console.log("Loaded all tiddlers",$tw.wiki.tiddlers); + }); + } else { + alert("This TiddlyWiki file must be in Dropbox"); + } }; })();