mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-08 06:43:49 +00:00
Added the image macro
This commit is contained in:
parent
4df13a3e24
commit
606374e563
@ -89,6 +89,7 @@ var App = function() {
|
|||||||
}
|
}
|
||||||
// Bit of a hack to set up the macros
|
// Bit of a hack to set up the macros
|
||||||
this.store.installMacro(require("./macros/echo.js").macro);
|
this.store.installMacro(require("./macros/echo.js").macro);
|
||||||
|
this.store.installMacro(require("./macros/image.js").macro);
|
||||||
this.store.installMacro(require("./macros/info.js").macro);
|
this.store.installMacro(require("./macros/info.js").macro);
|
||||||
this.store.installMacro(require("./macros/link.js").macro);
|
this.store.installMacro(require("./macros/link.js").macro);
|
||||||
this.store.installMacro(require("./macros/list.js").macro);
|
this.store.installMacro(require("./macros/list.js").macro);
|
||||||
|
22
js/Utils.js
22
js/Utils.js
@ -253,18 +253,20 @@ utils.stitchElement = function(element,attributes,options) {
|
|||||||
if(attributes) {
|
if(attributes) {
|
||||||
for(var a in attributes) {
|
for(var a in attributes) {
|
||||||
var v = attributes[a];
|
var v = attributes[a];
|
||||||
if(typeof v === "object") {
|
if(v !== undefined) {
|
||||||
var s = [];
|
if(typeof v === "object") {
|
||||||
for(var t in v) {
|
var s = [];
|
||||||
s.push(t + ":" + v[t] + ";");
|
for(var t in v) {
|
||||||
|
s.push(t + ":" + v[t] + ";");
|
||||||
|
}
|
||||||
|
v = s.join("");
|
||||||
}
|
}
|
||||||
v = s.join("");
|
output.push(" ");
|
||||||
|
output.push(a);
|
||||||
|
output.push("='");
|
||||||
|
output.push(utils.htmlEncode(v));
|
||||||
|
output.push("'");
|
||||||
}
|
}
|
||||||
output.push(" ");
|
|
||||||
output.push(a);
|
|
||||||
output.push("='");
|
|
||||||
output.push(utils.htmlEncode(v));
|
|
||||||
output.push("'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(options.insertAfterAttributes) {
|
if(options.insertAfterAttributes) {
|
||||||
|
@ -362,7 +362,7 @@ WikiStore.prototype.renderMacro = function(macroName,targetType,tiddler,params)
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Refresh a DOM node so that it reflects the current state of the store
|
Refresh a DOM node so that it reflects the current state of the store
|
||||||
|
34
js/macros/image.js
Normal file
34
js/macros/image.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*\
|
||||||
|
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}
|
||||||
|
},
|
||||||
|
handler: function(type,tiddler,store,params) {
|
||||||
|
if(type === "text/html") {
|
||||||
|
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 : params.src;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -1,3 +1,5 @@
|
|||||||
title: ThirdTiddler
|
title: ThirdTiddler
|
||||||
|
|
||||||
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]] and a transclusion <<tiddler [[Fourth Tiddler]] with:Stringy>>
|
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]] and a transclusion <<tiddler [[Fourth Tiddler]] with:Stringy>>
|
||||||
|
|
||||||
|
[img[http://placehold.it/350x150]]
|
||||||
|
@ -29,6 +29,7 @@ jsmodule: ../js/StoryNavigator.js
|
|||||||
jsmodule: ../js/App.js
|
jsmodule: ../js/App.js
|
||||||
|
|
||||||
jsmodule: ../js/macros/echo.js
|
jsmodule: ../js/macros/echo.js
|
||||||
|
jsmodule: ../js/macros/image.js
|
||||||
jsmodule: ../js/macros/info.js
|
jsmodule: ../js/macros/info.js
|
||||||
jsmodule: ../js/macros/link.js
|
jsmodule: ../js/macros/link.js
|
||||||
jsmodule: ../js/macros/list.js
|
jsmodule: ../js/macros/list.js
|
||||||
|
Loading…
x
Reference in New Issue
Block a user