mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-30 13:02:53 +00:00
![Jeremy Ruston](/assets/img/avatar_default.png)
Now there is now longer a dummy DOM element corresponding to the macro itself. Instead, macros must create a single element child. This allows us to more easily fit Bootstrap's requirements for HTML layout (eg, that problem with links in navbars not being recognised). The refactoring isn't complete, there are still a few bugs to chase down
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
/*\
|
|
title: $:/core/modules/macros/download.js
|
|
type: application/javascript
|
|
module-type: macro
|
|
|
|
Download 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) {
|
|
if(event.type === "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/templates/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 + "\""));
|
|
}
|
|
if(this.classes) {
|
|
attributes["class"] = this.classes.slice(0);
|
|
}
|
|
return $tw.Tree.Element("button",attributes,content);
|
|
};
|
|
|
|
})();
|