mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-09-02 10:58:01 +00:00
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
This commit is contained in:
@@ -16,10 +16,6 @@ var AndTidWiki = function(wiki) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
AndTidWiki.prototype.save = function(text,method,callback) {
|
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
|
// Get the pathname of this document
|
||||||
var pathname = decodeURIComponent(document.location.toString());
|
var pathname = decodeURIComponent(document.location.toString());
|
||||||
// Strip the file://
|
// Strip the file://
|
||||||
@@ -47,7 +43,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
AndTidWiki.prototype.info = {
|
AndTidWiki.prototype.info = {
|
||||||
name: "andtidwiki",
|
name: "andtidwiki",
|
||||||
priority: 1600
|
priority: 1600,
|
||||||
|
capabilities: ["save", "autosave"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -46,7 +46,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
DownloadSaver.prototype.info = {
|
DownloadSaver.prototype.info = {
|
||||||
name: "download",
|
name: "download",
|
||||||
priority: 100
|
priority: 100,
|
||||||
|
capabilities: ["save", "download"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -22,10 +22,6 @@ var FSOSaver = function(wiki) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
FSOSaver.prototype.save = function(text,method,callback) {
|
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
|
// Get the pathname of this document
|
||||||
var pathname = unescape(document.location.pathname);
|
var pathname = unescape(document.location.pathname);
|
||||||
// Test for a Windows path of the form /x:\blah...
|
// Test for a Windows path of the form /x:\blah...
|
||||||
@@ -53,7 +49,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
FSOSaver.prototype.info = {
|
FSOSaver.prototype.info = {
|
||||||
name: "FSOSaver",
|
name: "FSOSaver",
|
||||||
priority: 120
|
priority: 120,
|
||||||
|
capabilities: ["save", "autosave"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -33,7 +33,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
ManualDownloadSaver.prototype.info = {
|
ManualDownloadSaver.prototype.info = {
|
||||||
name: "manualdownload",
|
name: "manualdownload",
|
||||||
priority: 0
|
priority: 0,
|
||||||
|
capabilities: ["save", "download"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -36,7 +36,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
MsDownloadSaver.prototype.info = {
|
MsDownloadSaver.prototype.info = {
|
||||||
name: "msdownload",
|
name: "msdownload",
|
||||||
priority: 110
|
priority: 110,
|
||||||
|
capabilities: ["save", "download"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -16,10 +16,6 @@ var TiddlyFoxSaver = function(wiki) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TiddlyFoxSaver.prototype.save = function(text,method,callback) {
|
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");
|
var messageBox = document.getElementById("tiddlyfox-message-box");
|
||||||
if(messageBox) {
|
if(messageBox) {
|
||||||
// Get the pathname of this document
|
// Get the pathname of this document
|
||||||
@@ -55,7 +51,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
TiddlyFoxSaver.prototype.info = {
|
TiddlyFoxSaver.prototype.info = {
|
||||||
name: "tiddlyfox",
|
name: "tiddlyfox",
|
||||||
priority: 1500
|
priority: 1500,
|
||||||
|
capabilities: ["save", "autosave"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -19,11 +19,7 @@ var TiddlyIESaver = function(wiki) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TiddlyIESaver.prototype.save = function(text,method,callback) {
|
TiddlyIESaver.prototype.save = function(text,method,callback) {
|
||||||
// Bail out unless this is a save (rather than a download)
|
// Check existence of TiddlyIE BHO extension (note: only works after document is complete)
|
||||||
if(method !== "save") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// check existence of TiddlyIE BHO extension (note: only works after document is complete)
|
|
||||||
if(typeof(window.TiddlyIE) != "undefined") {
|
if(typeof(window.TiddlyIE) != "undefined") {
|
||||||
// Get the pathname of this document
|
// Get the pathname of this document
|
||||||
var pathname = unescape(document.location.pathname);
|
var pathname = unescape(document.location.pathname);
|
||||||
@@ -53,7 +49,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
TiddlyIESaver.prototype.info = {
|
TiddlyIESaver.prototype.info = {
|
||||||
name: "tiddlyiesaver",
|
name: "tiddlyiesaver",
|
||||||
priority: 1500
|
priority: 1500,
|
||||||
|
capabilities: ["save"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -16,10 +16,6 @@ var TWEditSaver = function(wiki) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TWEditSaver.prototype.save = function(text,method,callback) {
|
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
|
// Bail if we're not running under TWEdit
|
||||||
if(typeof DeviceInfo !== "object") {
|
if(typeof DeviceInfo !== "object") {
|
||||||
return false;
|
return false;
|
||||||
@@ -68,7 +64,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
TWEditSaver.prototype.info = {
|
TWEditSaver.prototype.info = {
|
||||||
name: "twedit",
|
name: "twedit",
|
||||||
priority: 1600
|
priority: 1600,
|
||||||
|
capabilities: ["save", "autosave"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -22,10 +22,6 @@ var UploadSaver = function(wiki) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
UploadSaver.prototype.save = function(text,method,callback) {
|
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
|
// Get the various parameters we need
|
||||||
var backupDir = this.wiki.getTextReference("$:/UploadBackupDir") || ".",
|
var backupDir = this.wiki.getTextReference("$:/UploadBackupDir") || ".",
|
||||||
username = this.wiki.getTextReference("$:/UploadName"),
|
username = this.wiki.getTextReference("$:/UploadName"),
|
||||||
@@ -78,7 +74,8 @@ Information about this saver
|
|||||||
*/
|
*/
|
||||||
UploadSaver.prototype.info = {
|
UploadSaver.prototype.info = {
|
||||||
name: "upload",
|
name: "upload",
|
||||||
priority: 2000
|
priority: 2000,
|
||||||
|
capabilities: ["save", "autosave"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -93,6 +93,13 @@ exports.startup = function() {
|
|||||||
downloadType: "text/plain"
|
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.rootWidget.addEventListener("tw-download-file",function(event) {
|
||||||
$tw.wiki.saveWiki({
|
$tw.wiki.saveWiki({
|
||||||
method: "download",
|
method: "download",
|
||||||
|
@@ -289,6 +289,8 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
|
|||||||
if(draftTitle !== this.storyTitle) {
|
if(draftTitle !== this.storyTitle) {
|
||||||
this.saveStoryList(storyList);
|
this.saveStoryList(storyList);
|
||||||
}
|
}
|
||||||
|
// Send a notification event
|
||||||
|
this.dispatchEvent({type: "tw-auto-save-wiki"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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:
|
Save the wiki contents. Options are:
|
||||||
method: "save" or "download"
|
method: "save" or "download"
|
||||||
@@ -927,15 +914,23 @@ exports.saveWiki = function(options) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
var method = options.method || "save",
|
var method = options.method || "save",
|
||||||
template = options.template || "$:/core/save/all",
|
template = options.template || "$:/core/save/all",
|
||||||
downloadType = options.downloadType || "text/plain";
|
downloadType = options.downloadType || "text/plain",
|
||||||
var text = this.renderTiddler(downloadType,template);
|
text = this.renderTiddler(downloadType,template),
|
||||||
this.callSaver("save",text,method,function(err) {
|
callback = function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
alert("Error while saving:\n\n" + err);
|
alert("Error while saving:\n\n" + err);
|
||||||
} else {
|
} else {
|
||||||
$tw.notifier.display("$:/messages/Saved");
|
$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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user