1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-24 04:44:23 +00:00
TiddlyWiki5/js/macros/command.js
2012-03-30 13:47:54 +01:00

40 lines
920 B
JavaScript

/*\
title: js/macros/command.js
\*/
(function(){
/*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")) {
attributes["class"] = this.params["class"].split(" ");
}
return [Renderer.ElementNode("button",attributes,[Renderer.TextNode(this.params.label)])];
}
};
})();