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",
|
|
|
|
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-21 21:57:30 +00:00
|
|
|
execute: function() {
|
|
|
|
if(this.store.tiddlerExists(this.params.src)) {
|
2012-03-03 18:39:13 +00:00
|
|
|
var imageTree = this.store.parseTiddler(this.params.src).nodes,
|
2012-02-16 20:38:10 +00:00
|
|
|
cloneImage = [];
|
|
|
|
for(var t=0; t<imageTree.length; t++) {
|
|
|
|
cloneImage.push(imageTree[t].clone());
|
|
|
|
}
|
2012-02-21 21:57:30 +00:00
|
|
|
if(this.params.text) {
|
2012-02-16 20:38:10 +00:00
|
|
|
return [Renderer.ElementNode("div",{
|
2012-02-21 21:57:30 +00:00
|
|
|
alt: this.params.text,
|
|
|
|
title: this.params.text
|
2012-02-16 20:38:10 +00:00
|
|
|
},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",{
|
2012-04-18 07:52:12 +00:00
|
|
|
src: this.params.src,
|
2012-02-21 21:57:30 +00:00
|
|
|
alt: this.params.text,
|
|
|
|
title: this.params.text
|
2012-02-16 20:38:10 +00:00
|
|
|
})];
|
2012-01-15 14:37:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|