2012-10-10 20:59:25 +00:00
|
|
|
/*\
|
2012-11-13 18:42:50 +00:00
|
|
|
title: $:/plugins/tiddlywiki/dropbox-app/dropbox-app.js
|
2012-10-10 20:59:25 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: dropbox-startup
|
|
|
|
|
|
|
|
Startup the Dropbox wiki app
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2012-10-13 23:21:44 +00:00
|
|
|
exports.startup = function(loggedIn) {
|
|
|
|
// Load any tiddlers embedded in the index file
|
|
|
|
var index = $tw.wiki.getTiddlerData($tw.plugins.dropbox.titleTiddlerIndex);
|
|
|
|
if(index) {
|
|
|
|
$tw.wiki.addTiddlers(index.tiddlers);
|
|
|
|
$tw.wiki.addTiddlers(index.shadows,true);
|
|
|
|
$tw.plugins.dropbox.fileInfo = index.fileInfo;
|
2012-10-10 21:46:59 +00:00
|
|
|
}
|
2012-10-13 23:21:44 +00:00
|
|
|
if(loggedIn) {
|
|
|
|
// Figure out the wiki name
|
|
|
|
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));
|
2012-10-13 18:51:01 +00:00
|
|
|
}
|
2012-10-13 23:21:44 +00:00
|
|
|
}
|
|
|
|
if(wikiName) {
|
|
|
|
// Save the wiki name for later
|
|
|
|
$tw.plugins.dropbox.wikiName = wikiName;
|
|
|
|
$tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleWikiName, text: $tw.plugins.dropbox.wikiName},true);
|
|
|
|
// Check for later versions of files on Dropbox
|
|
|
|
$tw.plugins.dropbox.refreshTiddlerFiles("/" + $tw.plugins.dropbox.wikiName + "/tiddlers",function(hadChanges) {
|
|
|
|
// Save the tiddler index if we had changes
|
|
|
|
if(hadChanges) {
|
|
|
|
$tw.plugins.dropbox.saveTiddlerIndex("/" + $tw.plugins.dropbox.wikiName + "/index.html",function(error) {
|
|
|
|
console.log("Saved tiddler index");
|
2012-11-11 14:13:08 +00:00
|
|
|
// Sync any subsequent tiddler changes
|
|
|
|
$tw.plugins.dropbox.setupSyncer($tw.wiki);
|
2012-10-13 23:21:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
alert("This TiddlyWiki file must be in Dropbox");
|
|
|
|
}
|
2012-10-10 21:46:59 +00:00
|
|
|
}
|
2012-10-10 20:59:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|