2012-04-30 11:23:03 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/macros/image.js
|
2012-04-30 11:23:03 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: macro
|
|
|
|
|
2012-05-19 17:23:14 +00:00
|
|
|
Image macro for displaying images
|
|
|
|
|
2012-04-30 11:23:03 +00:00
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
2012-05-04 17:49:04 +00:00
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
2012-04-30 11:23:03 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.info = {
|
|
|
|
name: "image",
|
|
|
|
params: {
|
|
|
|
src: {byName: "default", type: "tiddler"},
|
|
|
|
text: {byName: true, type: "text"},
|
2012-06-10 17:09:15 +00:00
|
|
|
alignment: {byName: true, type: "text"},
|
|
|
|
width: {byName: true, type: "text"},
|
|
|
|
height: {byName: true, type: "text"}
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.executeMacro = function() {
|
|
|
|
if(this.wiki.tiddlerExists(this.params.src)) {
|
|
|
|
var imageTree = this.wiki.parseTiddler(this.params.src).tree,
|
2012-06-09 17:36:32 +00:00
|
|
|
cloneImage = imageTree[0].clone();
|
2012-06-10 17:09:15 +00:00
|
|
|
if(this.hasParameter("width")) {
|
|
|
|
cloneImage.attributes.width = this.params.width;
|
|
|
|
}
|
|
|
|
if(this.hasParameter("height")) {
|
|
|
|
cloneImage.attributes.height = this.params.height;
|
|
|
|
}
|
2012-04-30 11:23:03 +00:00
|
|
|
if(this.params.text) {
|
2012-06-09 17:36:32 +00:00
|
|
|
return $tw.Tree.Element("div",{
|
2012-04-30 11:23:03 +00:00
|
|
|
alt: this.params.text,
|
|
|
|
title: this.params.text
|
2012-06-09 17:36:32 +00:00
|
|
|
},[cloneImage]);
|
2012-04-30 11:23:03 +00:00
|
|
|
} else {
|
|
|
|
return cloneImage;
|
|
|
|
}
|
|
|
|
} else {
|
2012-06-09 17:36:32 +00:00
|
|
|
return $tw.Tree.Element("img",{
|
2012-04-30 11:23:03 +00:00
|
|
|
src: this.params.src,
|
|
|
|
alt: this.params.text,
|
2012-06-10 17:09:15 +00:00
|
|
|
width: this.params.width,
|
|
|
|
height: this.params.height,
|
2012-04-30 11:23:03 +00:00
|
|
|
title: this.params.text
|
2012-06-09 17:36:32 +00:00
|
|
|
});
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|