TiddlyWiki5/js/macros/image.js

46 wiersze
1.0 KiB
JavaScript
Czysty Zwykły widok Historia

2012-01-15 14:37:49 +00:00
/*\
title: js/macros/image.js
\*/
(function(){
/*jslint node: true */
"use strict";
var Renderer = require("../Renderer.js").Renderer;
2012-01-15 14:37:49 +00:00
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}
2012-01-15 14:37:49 +00:00
},
execute: function(macroNode,tiddler,store) {
if(store.tiddlerExists(macroNode.params.src)) {
var imageTree = store.parseTiddler(macroNode.params.src).tree,
cloneImage = [];
for(var t=0; t<imageTree.length; t++) {
cloneImage.push(imageTree[t].clone());
}
if(macroNode.params.text) {
return [Renderer.ElementNode("div",{
alt: macroNode.params.text,
title: macroNode.params.text
},cloneImage)];
} else {
return cloneImage;
}
} else {
return [Renderer.ElementNode("img",{
href: macroNode.params.src,
alt: macroNode.params.text,
title: macroNode.params.text
})];
2012-01-15 14:37:49 +00:00
}
}
};
})();