2012-01-15 14:37:49 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/image.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
2012-02-16 20:38:10 +00:00
|
|
|
var Renderer = require("../Renderer.js").Renderer;
|
2012-01-15 14:37:49 +00:00
|
|
|
|
|
|
|
exports.macro = {
|
|
|
|
name: "image",
|
|
|
|
types: ["text/html","text/plain"],
|
|
|
|
params: {
|
2012-02-17 17:32:32 +00:00
|
|
|
src: {byName: "default", type: "tiddler"},
|
|
|
|
text: {byName: true, type: "text"},
|
|
|
|
alignment: {byName: true, type: "text"}
|
2012-01-15 14:37:49 +00:00
|
|
|
},
|
2012-02-16 20:38:10 +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)];
|
2012-01-16 08:58:51 +00:00
|
|
|
} else {
|
2012-02-16 20:38:10 +00:00
|
|
|
return cloneImage;
|
2012-01-16 08:58:51 +00:00
|
|
|
}
|
2012-02-16 20:38:10 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|