kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Add support for downloading files
We were re-using the `tw-save-wiki` message both for saving the current wiki and downloading a new wiki. Now we’ll use the separate `tw-download-file` message for downloading. Fixes #236print-window-tiddler
rodzic
7175f1cbf1
commit
0956ae10a0
|
@ -15,7 +15,11 @@ Handles saving changes via the AndTidWiki Android app
|
||||||
var AndTidWiki = function(wiki) {
|
var AndTidWiki = function(wiki) {
|
||||||
};
|
};
|
||||||
|
|
||||||
AndTidWiki.prototype.save = function(text,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://
|
||||||
|
|
|
@ -18,7 +18,7 @@ Select the appropriate saver module and set it up
|
||||||
var DownloadSaver = function(wiki) {
|
var DownloadSaver = function(wiki) {
|
||||||
};
|
};
|
||||||
|
|
||||||
DownloadSaver.prototype.save = function(text) {
|
DownloadSaver.prototype.save = function(text,method,callback) {
|
||||||
// Get the current filename
|
// Get the current filename
|
||||||
var filename = "tiddlywiki.html",
|
var filename = "tiddlywiki.html",
|
||||||
p = document.location.pathname.lastIndexOf("/");
|
p = document.location.pathname.lastIndexOf("/");
|
||||||
|
|
|
@ -21,7 +21,7 @@ Select the appropriate saver module and set it up
|
||||||
var ManualDownloadSaver = function(wiki) {
|
var ManualDownloadSaver = function(wiki) {
|
||||||
};
|
};
|
||||||
|
|
||||||
ManualDownloadSaver.prototype.save = function(text) {
|
ManualDownloadSaver.prototype.save = function(text,method,callback) {
|
||||||
$tw.modal.display(downloadInstructionsTitle,{
|
$tw.modal.display(downloadInstructionsTitle,{
|
||||||
downloadLink: "data:text/html," + encodeURIComponent(text)
|
downloadLink: "data:text/html," + encodeURIComponent(text)
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,7 @@ Select the appropriate saver module and set it up
|
||||||
var MsDownloadSaver = function(wiki) {
|
var MsDownloadSaver = function(wiki) {
|
||||||
};
|
};
|
||||||
|
|
||||||
MsDownloadSaver.prototype.save = function(text) {
|
MsDownloadSaver.prototype.save = function(text,method,callback) {
|
||||||
// Get the current filename
|
// Get the current filename
|
||||||
var filename = "tiddlywiki.html",
|
var filename = "tiddlywiki.html",
|
||||||
p = document.location.pathname.lastIndexOf("/");
|
p = document.location.pathname.lastIndexOf("/");
|
||||||
|
|
|
@ -15,7 +15,11 @@ Handles saving changes via the TiddlyFox file extension
|
||||||
var TiddlyFoxSaver = function(wiki) {
|
var TiddlyFoxSaver = function(wiki) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TiddlyFoxSaver.prototype.save = function(text,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
|
||||||
|
|
|
@ -15,7 +15,11 @@ Handles saving changes via the TWEdit iOS app
|
||||||
var TWEditSaver = function(wiki) {
|
var TWEditSaver = function(wiki) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TWEditSaver.prototype.save = function(text,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;
|
||||||
|
|
|
@ -21,7 +21,11 @@ var UploadSaver = function(wiki) {
|
||||||
this.wiki = wiki;
|
this.wiki = wiki;
|
||||||
};
|
};
|
||||||
|
|
||||||
UploadSaver.prototype.save = function(text,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 = ".",
|
var backupDir = ".",
|
||||||
username = this.wiki.getTextReference("$:/UploadName"),
|
username = this.wiki.getTextReference("$:/UploadName"),
|
||||||
|
|
|
@ -89,6 +89,13 @@ exports.startup = function() {
|
||||||
downloadType: "text/plain"
|
downloadType: "text/plain"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
$tw.rootWidget.addEventListener("tw-download-file",function(event) {
|
||||||
|
$tw.wiki.saveWiki({
|
||||||
|
method: "download",
|
||||||
|
template: event.param,
|
||||||
|
downloadType: "text/plain"
|
||||||
|
});
|
||||||
|
});
|
||||||
// Install the crypto event handlers
|
// Install the crypto event handlers
|
||||||
$tw.rootWidget.addEventListener("tw-set-password",function(event) {
|
$tw.rootWidget.addEventListener("tw-set-password",function(event) {
|
||||||
$tw.passwordPrompt.createPrompt({
|
$tw.passwordPrompt.createPrompt({
|
||||||
|
|
|
@ -866,15 +866,17 @@ exports.callSaver = function(method /*, args */ ) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Save the wiki contents. Options are:
|
Save the wiki contents. Options are:
|
||||||
|
method: "save" or "download"
|
||||||
template: the tiddler containing the template to save
|
template: the tiddler containing the template to save
|
||||||
downloadType: the content type for the saved file
|
downloadType: the content type for the saved file
|
||||||
*/
|
*/
|
||||||
exports.saveWiki = function(options) {
|
exports.saveWiki = function(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var template = options.template || "$:/core/save/all",
|
var method = options.method || "save",
|
||||||
|
template = options.template || "$:/core/save/all",
|
||||||
downloadType = options.downloadType || "text/plain";
|
downloadType = options.downloadType || "text/plain";
|
||||||
var text = this.renderTiddler(downloadType,template);
|
var text = this.renderTiddler(downloadType,template);
|
||||||
this.callSaver("save",text,function(err) {
|
this.callSaver("save",text,method,function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
alert("Error while saving:\n\n" + err);
|
alert("Error while saving:\n\n" + err);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,8 +7,8 @@ title: Download
|
||||||
|
|
||||||
! Download Single File Editions
|
! Download Single File Editions
|
||||||
|
|
||||||
|<$button message="tw-save-wiki" param="$:/editions/tw5.com/save-empty" class="btn-big-green">Save Empty {{$:/core/images/save-button}}</$button>|Get started with an empty wiki |
|
|<$button message="tw-download-file" param="$:/editions/tw5.com/save-empty" class="btn-big-green">Download Empty {{$:/core/images/save-button}}</$button>|Get started with an empty wiki |
|
||||||
|<$button message="tw-save-wiki" param="$:/core/save/all" class="btn-big-green">Save Full {{$:/core/images/save-button}}</$button>|Download a full copy of this site, including all the documentation |
|
|<$button message="tw-download-file" param="$:/core/save/all" class="btn-big-green">Download Full {{$:/core/images/save-button}}</$button>|Download a full copy of this site, including all the documentation |
|
||||||
|
|
||||||
! Download Node.js Edition
|
! Download Node.js Edition
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue