Add support for autosave

Causes the wiki to be autosaved whenever clicking “done” after editing
a tiddler. Only works with savers that support autosave. We should
probably make autosave configurable
print-window-tiddler
Jermolene 2014-02-04 21:21:01 +00:00
rodzic 4882f70557
commit 1d685df928
12 zmienionych plików z 44 dodań i 55 usunięć

Wyświetl plik

@ -16,10 +16,6 @@ var AndTidWiki = function(wiki) {
};
AndTidWiki.prototype.save = function(text,method,callback) {
// Bail out unless this is a save (rather than a download)
if(method !== "save") {
return false;
}
// Get the pathname of this document
var pathname = decodeURIComponent(document.location.toString());
// Strip the file://
@ -47,7 +43,8 @@ Information about this saver
*/
AndTidWiki.prototype.info = {
name: "andtidwiki",
priority: 1600
priority: 1600,
capabilities: ["save", "autosave"]
};
/*

Wyświetl plik

@ -46,7 +46,8 @@ Information about this saver
*/
DownloadSaver.prototype.info = {
name: "download",
priority: 100
priority: 100,
capabilities: ["save", "download"]
};
/*

Wyświetl plik

@ -22,10 +22,6 @@ var FSOSaver = function(wiki) {
};
FSOSaver.prototype.save = function(text,method,callback) {
// Bail out unless this is a save (rather than a download)
if(method !== "save") {
return false;
}
// Get the pathname of this document
var pathname = unescape(document.location.pathname);
// Test for a Windows path of the form /x:\blah...
@ -53,7 +49,8 @@ Information about this saver
*/
FSOSaver.prototype.info = {
name: "FSOSaver",
priority: 120
priority: 120,
capabilities: ["save", "autosave"]
};
/*

Wyświetl plik

@ -33,7 +33,8 @@ Information about this saver
*/
ManualDownloadSaver.prototype.info = {
name: "manualdownload",
priority: 0
priority: 0,
capabilities: ["save", "download"]
};
/*

Wyświetl plik

@ -36,7 +36,8 @@ Information about this saver
*/
MsDownloadSaver.prototype.info = {
name: "msdownload",
priority: 110
priority: 110,
capabilities: ["save", "download"]
};
/*

Wyświetl plik

@ -16,10 +16,6 @@ var TiddlyFoxSaver = function(wiki) {
};
TiddlyFoxSaver.prototype.save = function(text,method,callback) {
// Bail out unless this is a save (rather than a download)
if(method !== "save") {
return false;
}
var messageBox = document.getElementById("tiddlyfox-message-box");
if(messageBox) {
// Get the pathname of this document
@ -55,7 +51,8 @@ Information about this saver
*/
TiddlyFoxSaver.prototype.info = {
name: "tiddlyfox",
priority: 1500
priority: 1500,
capabilities: ["save", "autosave"]
};
/*

Wyświetl plik

@ -19,11 +19,7 @@ var TiddlyIESaver = function(wiki) {
};
TiddlyIESaver.prototype.save = function(text,method,callback) {
// Bail out unless this is a save (rather than a download)
if(method !== "save") {
return false;
}
// check existence of TiddlyIE BHO extension (note: only works after document is complete)
// Check existence of TiddlyIE BHO extension (note: only works after document is complete)
if(typeof(window.TiddlyIE) != "undefined") {
// Get the pathname of this document
var pathname = unescape(document.location.pathname);
@ -53,7 +49,8 @@ Information about this saver
*/
TiddlyIESaver.prototype.info = {
name: "tiddlyiesaver",
priority: 1500
priority: 1500,
capabilities: ["save"]
};
/*

Wyświetl plik

@ -16,10 +16,6 @@ var TWEditSaver = function(wiki) {
};
TWEditSaver.prototype.save = function(text,method,callback) {
// Bail out unless this is a save (rather than a download)
if(method !== "save") {
return false;
}
// Bail if we're not running under TWEdit
if(typeof DeviceInfo !== "object") {
return false;
@ -68,7 +64,8 @@ Information about this saver
*/
TWEditSaver.prototype.info = {
name: "twedit",
priority: 1600
priority: 1600,
capabilities: ["save", "autosave"]
};
/*

Wyświetl plik

@ -22,10 +22,6 @@ var UploadSaver = function(wiki) {
};
UploadSaver.prototype.save = function(text,method,callback) {
// Bail out unless this is a save (rather than a download)
if(method !== "save") {
return false;
}
// Get the various parameters we need
var backupDir = this.wiki.getTextReference("$:/UploadBackupDir") || ".",
username = this.wiki.getTextReference("$:/UploadName"),
@ -78,7 +74,8 @@ Information about this saver
*/
UploadSaver.prototype.info = {
name: "upload",
priority: 2000
priority: 2000,
capabilities: ["save", "autosave"]
};
/*

Wyświetl plik

@ -93,6 +93,13 @@ exports.startup = function() {
downloadType: "text/plain"
});
});
$tw.rootWidget.addEventListener("tw-auto-save-wiki",function(event) {
$tw.wiki.saveWiki({
method: "autosave",
template: event.param,
downloadType: "text/plain"
});
});
$tw.rootWidget.addEventListener("tw-download-file",function(event) {
$tw.wiki.saveWiki({
method: "download",

Wyświetl plik

@ -289,6 +289,8 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
if(draftTitle !== this.storyTitle) {
this.saveStoryList(storyList);
}
// Send a notification event
this.dispatchEvent({type: "tw-auto-save-wiki"});
}
}
}

Wyświetl plik

@ -904,19 +904,6 @@ exports.initSavers = function(moduleType) {
});
};
/*
Invoke the highest priority saver that successfully handles a method
*/
exports.callSaver = function(method /*, args */ ) {
for(var t=this.savers.length-1; t>=0; t--) {
var saver = this.savers[t];
if(saver[method].apply(saver,Array.prototype.slice.call(arguments,1))) {
return true;
}
}
return false;
};
/*
Save the wiki contents. Options are:
method: "save" or "download"
@ -927,15 +914,23 @@ exports.saveWiki = function(options) {
options = options || {};
var method = options.method || "save",
template = options.template || "$:/core/save/all",
downloadType = options.downloadType || "text/plain";
var text = this.renderTiddler(downloadType,template);
this.callSaver("save",text,method,function(err) {
if(err) {
alert("Error while saving:\n\n" + err);
} else {
$tw.notifier.display("$:/messages/Saved");
downloadType = options.downloadType || "text/plain",
text = this.renderTiddler(downloadType,template),
callback = function(err) {
if(err) {
alert("Error while saving:\n\n" + err);
} else {
$tw.notifier.display("$:/messages/Saved");
}
};
// Call the highest priority saver that supports this method
for(var t=this.savers.length-1; t>=0; t--) {
var saver = this.savers[t];
if(saver.info.capabilities.indexOf(method) !== -1 && saver.save(text,method,callback)) {
return true;
}
});
}
return false;
};
/*