mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-24 00:50:28 +00:00
Added a download macro
This enables us to save changes by cooking a new tiddlywiki and forcing a download of it
This commit is contained in:
parent
cce472789d
commit
bac2c0ec07
52
core/modules/macros/download.js
Normal file
52
core/modules/macros/download.js
Normal file
@ -0,0 +1,52 @@
|
||||
/*\
|
||||
title: $:/core/modules/macros/download.js
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "download",
|
||||
params: {
|
||||
title: {byName: "default", type: "text"},
|
||||
type: {byName: true, type: "text"},
|
||||
"filename": {byName: true, type: "text"},
|
||||
"label": {byName: true, type: "text"}
|
||||
},
|
||||
events: ["click"]
|
||||
};
|
||||
|
||||
exports.handleEvent = function(event) {
|
||||
switch(event.type) {
|
||||
case "click":
|
||||
var text = this.wiki.renderTiddler(this.downloadType,this.downloadTitle),
|
||||
link = document.createElement("a");
|
||||
link.setAttribute("download",this.downloadFilename);
|
||||
link.setAttribute("href","data:" + this.downloadType + "," + encodeURIComponent(text));
|
||||
link.click();
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.executeMacro = function() {
|
||||
this.downloadTitle = this.params.title || "$:/core/tiddlywiki5.template.html";
|
||||
this.downloadType = this.params.type || "text/plain";
|
||||
this.downloadFilename = this.params.filename || this.downloadTitle;
|
||||
var attributes = {},
|
||||
content = [];
|
||||
if(this.hasParameter("label")) {
|
||||
content.push($tw.Tree.Text(this.params.label));
|
||||
} else {
|
||||
content.push($tw.Tree.Text("Download \"" + this.downloadFilename + "\""));
|
||||
}
|
||||
return [$tw.Tree.Element("button",attributes,content)];
|
||||
};
|
||||
|
||||
})();
|
@ -2,7 +2,10 @@ title: Introduction
|
||||
|
||||
TiddlyWiki5 gains new capabilities through a [[completely rebuilt architecture|TiddlyWikiArchitecture]] using the latest features of HTML5 and node.js. It runs natively under node.js, and can also use its own components to construct a version of itself that works entirely within the browser, just as TiddlyWiki has always done.
|
||||
|
||||
TiddlyWiki5 also functions as the build system for earlier versions of TiddlyWiki, replacing the elderly Cook and Ginsu tools (see https://github.com/TiddlyWiki/cooker for details). See the CommandLineInterface for details.
|
||||
You can modify this wiki, and then download a copy by clicking this button:
|
||||
<<download filename:"TiddlyWiki.html" label:"Save Changes">>
|
||||
|
||||
You can download a static copy of the tiddlers that are currently displayed in this wiki by clicking this button: <<download title:"$:/core/static.template.html" filename:"Story.html" label:"Static Wiki">>
|
||||
|
||||
{{alert alert-error{
|
||||
Try out the prototype touch features:
|
||||
@ -14,7 +17,6 @@ Learning more about TiddlyWiki5:
|
||||
* Some very rough UserInterfaceSketches showing where it is heading
|
||||
|
||||
Some useful tiddlers for feature testing:
|
||||
* ClockTiddler showing automatic refreshing of tiddlers
|
||||
* ImageTests showing different ways of embedding images
|
||||
* SampleData showing how JSON tiddlers are handled
|
||||
* SampleJavaScript and SampleJavaScriptWithError showing how JavaScript code is displayed
|
||||
|
Loading…
Reference in New Issue
Block a user