1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-28 12:29:56 +00:00
TiddlyWiki5/js/macros/image.js
2012-01-30 20:04:47 +00:00

49 lines
1014 B
JavaScript

/*\
title: js/macros/image.js
\*/
(function(){
/*jslint node: true */
"use strict";
var utils = require("../Utils.js");
exports.macro = {
name: "image",
types: ["text/html","text/plain"],
params: {
src: {byName: "default", type: "tiddler", optional: false},
text: {byName: true, type: "text", optional: true},
alignment: {byName: true, type: "text", optional: true}
},
render: function(type,tiddler,store,params) {
if(type === "text/html") {
if(store.tiddlerExists(params.src)) {
if(params.text) {
return utils.stitchElement("div",{
alt: params.text,
title: params.text
},{
content: store.renderTiddler(type,params.src)
});
} else {
return store.renderTiddler(type,params.src);
}
} else {
return utils.stitchElement("img",{
href: params.src,
alt: params.text,
title: params.text
},{
selfClosing: true
});
}
} else if (type === "text/plain") {
return params.text ? params.text : "";
}
}
};
})();