1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 17:40:29 +00:00

Refactor andtidwiki.js (The saver for Android apps including AndTidWiki, Tiddloid and Tiddloid Lite) (#4276)

* Create tiddloid.js

* Update andtidwiki.js

* Delete tiddloid.js

* Update andtidwiki.js

* Update andtidwiki.js

* Update andtidwiki.js

* Update andtidwiki.js

* Update andtidwiki.js

* Update andtidwiki.js
This commit is contained in:
donmor 2019-11-20 17:45:42 +08:00 committed by Jeremy Ruston
parent 8f3da69f81
commit 7b66df688a

View File

@ -15,7 +15,32 @@ Handles saving changes via the AndTidWiki Android app
var AndTidWiki = function(wiki) { var AndTidWiki = function(wiki) {
}; };
AndTidWiki.prototype.save = function(text,method,callback) { AndTidWiki.prototype.save = function(text,method,callback,options) {
var filename = options && options.variables ? options.variables.filename : null;
if (method === "download") {
// Support download
if (window.twi.saveDownload) {
try {
window.twi.saveDownload(text,filename);
} catch(err) {
if (err.message === "Method not found") {
window.twi.saveDownload(text);
}
}
} else {
var link = document.createElement("a");
link.setAttribute("href","data:text/plain," + encodeURIComponent(text));
if (filename) {
link.setAttribute("download",filename);
}
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
} else if (window.twi.saveWiki) {
// Direct save in Tiddloid
window.twi.saveWiki(text);
} else {
// Get the pathname of this document // Get the pathname of this document
var pathname = decodeURIComponent(document.location.toString().split("#")[0]); var pathname = decodeURIComponent(document.location.toString().split("#")[0]);
// Strip the file:// // Strip the file://
@ -33,6 +58,7 @@ AndTidWiki.prototype.save = function(text,method,callback) {
} }
// Save the file // Save the file
window.twi.saveFile(pathname,text); window.twi.saveFile(pathname,text);
}
// Call the callback // Call the callback
callback(null); callback(null);
return true; return true;
@ -44,7 +70,7 @@ Information about this saver
AndTidWiki.prototype.info = { AndTidWiki.prototype.info = {
name: "andtidwiki", name: "andtidwiki",
priority: 1600, priority: 1600,
capabilities: ["save", "autosave"] capabilities: ["save", "autosave", "download"]
}; };
/* /*