1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-19 08:14:50 +00:00
TiddlyWiki5/archive/js/macros/command.js

40 lines
920 B
JavaScript
Raw Normal View History

/*\
title: js/macros/command.js
\*/
(function(){
2012-03-30 12:47:54 +00:00
/*jslint node: true, browser: true */
"use strict";
var Renderer = require("../Renderer.js").Renderer;
exports.macro = {
name: "command",
params: {
name: {byName: "default", type: "text"},
label: {byName: true, type: "text"},
"class": {byName: true, type: "text"}
},
events: {
"click": function(event) {
var commandEvent = document.createEvent("Event");
commandEvent.initEvent("tw-" + this.params.name,true,true);
commandEvent.tiddlerTitle = this.tiddlerTitle;
commandEvent.commandOrigin = this;
event.target.dispatchEvent(commandEvent);
event.preventDefault();
return false;
}
},
execute: function() {
var attributes = {};
if(this.hasParameter("class")) {
2012-03-30 12:47:54 +00:00
attributes["class"] = this.params["class"].split(" ");
}
2012-03-30 12:47:54 +00:00
return [Renderer.ElementNode("button",attributes,[Renderer.TextNode(this.params.label)])];
}
};
})();