mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-23 14:30:02 +00:00
Switched stitchElement parameter from className to classes
It's shorter, and looks better
This commit is contained in:
parent
f4d530a114
commit
56e701b326
30
js/Utils.js
30
js/Utils.js
@ -246,7 +246,7 @@ utils.stringify = function(s) {
|
|||||||
// are processed to attr="name1:value1;name2:value2;"
|
// are processed to attr="name1:value1;name2:value2;"
|
||||||
// The options include:
|
// The options include:
|
||||||
// content: a string to include as content in the element (also generates closing tag)
|
// content: a string to include as content in the element (also generates closing tag)
|
||||||
// classNames: an array of classnames to apply to the element
|
// classes: an array of classnames to apply to the element
|
||||||
// selfClosing: causes the element to be rendered with a trailing /, as in <br />
|
// selfClosing: causes the element to be rendered with a trailing /, as in <br />
|
||||||
// insertAfterAttributes: a string to insert after the attribute section of the element
|
// insertAfterAttributes: a string to insert after the attribute section of the element
|
||||||
utils.stitchElement = function(element,attributes,options) {
|
utils.stitchElement = function(element,attributes,options) {
|
||||||
@ -275,8 +275,8 @@ utils.stitchElement = function(element,attributes,options) {
|
|||||||
if(options.insertAfterAttributes) {
|
if(options.insertAfterAttributes) {
|
||||||
output.push(options.insertAfterAttributes);
|
output.push(options.insertAfterAttributes);
|
||||||
}
|
}
|
||||||
if(options.classNames) {
|
if(options.classes) {
|
||||||
output.push(" class='",options.classNames.join(" "),"'");
|
output.push(" class='",options.classes.join(" "),"'");
|
||||||
}
|
}
|
||||||
output.push(">");
|
output.push(">");
|
||||||
if("content" in options) {
|
if("content" in options) {
|
||||||
@ -295,7 +295,7 @@ utils.stitchSlider = function(type,label,tooltip,body) {
|
|||||||
}
|
}
|
||||||
var labelNode = utils.stitchElement("a",labelAttrs,{
|
var labelNode = utils.stitchElement("a",labelAttrs,{
|
||||||
content: label,
|
content: label,
|
||||||
classNames: ["tw-slider-label"]
|
classes: ["tw-slider-label"]
|
||||||
}),
|
}),
|
||||||
bodyNode = utils.stitchElement("div",{
|
bodyNode = utils.stitchElement("div",{
|
||||||
style: {
|
style: {
|
||||||
@ -303,11 +303,11 @@ utils.stitchSlider = function(type,label,tooltip,body) {
|
|||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
content: body,
|
content: body,
|
||||||
classNames: ["tw-slider-body"]
|
classes: ["tw-slider-body"]
|
||||||
});
|
});
|
||||||
return utils.stitchElement("div",null,{
|
return utils.stitchElement("div",null,{
|
||||||
content: labelNode + bodyNode,
|
content: labelNode + bodyNode,
|
||||||
classNames: ["tw-slider"]
|
classes: ["tw-slider"]
|
||||||
});
|
});
|
||||||
} else if(type === "text/plain") {
|
} else if(type === "text/plain") {
|
||||||
return label + "\n" + body;
|
return label + "\n" + body;
|
||||||
@ -332,30 +332,30 @@ The custom template function should push the string rendering of the node to the
|
|||||||
utils.renderObject = function(output,type,node,customTemplates) {
|
utils.renderObject = function(output,type,node,customTemplates) {
|
||||||
var renderNodeHtml,
|
var renderNodeHtml,
|
||||||
renderArrayHtml = function(output,tree) {
|
renderArrayHtml = function(output,tree) {
|
||||||
output.push(utils.stitchElement("ul",null,{classNames: ["treeArray"]}));
|
output.push(utils.stitchElement("ul",null,{classes: ["treeArray"]}));
|
||||||
for(var t=0; t<tree.length; t++) {
|
for(var t=0; t<tree.length; t++) {
|
||||||
output.push(utils.stitchElement("li",null,{classNames: ["treeArrayMember"]}));
|
output.push(utils.stitchElement("li",null,{classes: ["treeArrayMember"]}));
|
||||||
renderNodeHtml(output,tree[t]);
|
renderNodeHtml(output,tree[t]);
|
||||||
output.push("</li>");
|
output.push("</li>");
|
||||||
}
|
}
|
||||||
output.push("</ul>");
|
output.push("</ul>");
|
||||||
},
|
},
|
||||||
renderFieldHtml = function(output,name,value) {
|
renderFieldHtml = function(output,name,value) {
|
||||||
output.push(utils.stitchElement("li",null,{classNames: ["treeNodeField"]}));
|
output.push(utils.stitchElement("li",null,{classes: ["treeNodeField"]}));
|
||||||
if(typeof value === "object") {
|
if(typeof value === "object") {
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
classNames: ["label"],
|
classes: ["label"],
|
||||||
content: utils.htmlEncode(name)
|
content: utils.htmlEncode(name)
|
||||||
}));
|
}));
|
||||||
renderNodeHtml(output,value);
|
renderNodeHtml(output,value);
|
||||||
} else {
|
} else {
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
classNames: ["splitLabel"],
|
classes: ["splitLabel"],
|
||||||
content: utils.stitchElement("span",null,{
|
content: utils.stitchElement("span",null,{
|
||||||
classNames: ["splitLabelLeft"],
|
classes: ["splitLabelLeft"],
|
||||||
content: utils.htmlEncode(name)
|
content: utils.htmlEncode(name)
|
||||||
}) + utils.stitchElement("span",null,{
|
}) + utils.stitchElement("span",null,{
|
||||||
classNames: ["splitLabelRight"],
|
classes: ["splitLabelRight"],
|
||||||
content: utils.htmlEncode(value)
|
content: utils.htmlEncode(value)
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
@ -367,7 +367,7 @@ utils.renderObject = function(output,type,node,customTemplates) {
|
|||||||
renderArrayHtml(output,node);
|
renderArrayHtml(output,node);
|
||||||
} else if (typeof node === "string") {
|
} else if (typeof node === "string") {
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
classNames: ["treeNode","label"],
|
classes: ["treeNode","label"],
|
||||||
content: utils.htmlEncode(node)
|
content: utils.htmlEncode(node)
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
@ -378,7 +378,7 @@ utils.renderObject = function(output,type,node,customTemplates) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!custom) {
|
if(!custom) {
|
||||||
output.push(utils.stitchElement("ul",null,{classNames: ["treeNode"]}));
|
output.push(utils.stitchElement("ul",null,{classes: ["treeNode"]}));
|
||||||
for(var f in node) {
|
for(var f in node) {
|
||||||
renderFieldHtml(output,f,node[f]);
|
renderFieldHtml(output,f,node[f]);
|
||||||
}
|
}
|
||||||
|
@ -288,14 +288,14 @@ WikiTextParseTree.prototype.toString = function(type) {
|
|||||||
function(output,type,node) { // Text nodes
|
function(output,type,node) { // Text nodes
|
||||||
if(node.type === "text") {
|
if(node.type === "text") {
|
||||||
output.push(utils.stitchElement("div",null,
|
output.push(utils.stitchElement("div",null,
|
||||||
{classNames: ["treeNode","splitLabel"]}));
|
{classes: ["treeNode","splitLabel"]}));
|
||||||
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "text"},{
|
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "text"},{
|
||||||
content: node.type,
|
content: node.type,
|
||||||
classNames: ["splitLabelLeft"]
|
classes: ["splitLabelLeft"]
|
||||||
}));
|
}));
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
content: utils.htmlEncode(node.value).replace(/\n/g,"<br>"),
|
content: utils.htmlEncode(node.value).replace(/\n/g,"<br>"),
|
||||||
classNames: ["splitLabelRight"]
|
classes: ["splitLabelRight"]
|
||||||
}));
|
}));
|
||||||
output.push("</div>");
|
output.push("</div>");
|
||||||
return true;
|
return true;
|
||||||
@ -307,15 +307,15 @@ WikiTextParseTree.prototype.toString = function(type) {
|
|||||||
output.push(utils.stitchElement("span",
|
output.push(utils.stitchElement("span",
|
||||||
{"data-tw-treenode-type": "macro"},{
|
{"data-tw-treenode-type": "macro"},{
|
||||||
content: utils.htmlEncode(node.name),
|
content: utils.htmlEncode(node.name),
|
||||||
classNames: ["treeNode","label"]
|
classes: ["treeNode","label"]
|
||||||
}));
|
}));
|
||||||
for(var f in node.params) {
|
for(var f in node.params) {
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
classNames: ["splitLabel"]
|
classes: ["splitLabel"]
|
||||||
}));
|
}));
|
||||||
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "param"},{
|
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "param"},{
|
||||||
content: utils.htmlEncode(f),
|
content: utils.htmlEncode(f),
|
||||||
classNames: ["splitLabelLeft"]
|
classes: ["splitLabelLeft"]
|
||||||
}));
|
}));
|
||||||
var v = node.params[f].value;
|
var v = node.params[f].value;
|
||||||
if(node.params[f].type === "string") {
|
if(node.params[f].type === "string") {
|
||||||
@ -325,19 +325,19 @@ WikiTextParseTree.prototype.toString = function(type) {
|
|||||||
}
|
}
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
content: utils.htmlEncode(v),
|
content: utils.htmlEncode(v),
|
||||||
classNames: ["splitLabelRight"]
|
classes: ["splitLabelRight"]
|
||||||
}));
|
}));
|
||||||
output.push("</span>");
|
output.push("</span>");
|
||||||
}
|
}
|
||||||
output.push(utils.stitchElement("span",null,
|
output.push(utils.stitchElement("span",null,
|
||||||
{classNames: ["treeNode","splitLabel"]}));
|
{classes: ["treeNode","splitLabel"]}));
|
||||||
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepDependencies"},{
|
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepDependencies"},{
|
||||||
content: "dependencies",
|
content: "dependencies",
|
||||||
classNames: ["splitLabelLeft"]
|
classes: ["splitLabelLeft"]
|
||||||
}));
|
}));
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
content: utils.htmlEncode(node.dependencies === null ? "*" : node.dependencies.join(", ")),
|
content: utils.htmlEncode(node.dependencies === null ? "*" : node.dependencies.join(", ")),
|
||||||
classNames: ["splitLabelRight"]
|
classes: ["splitLabelRight"]
|
||||||
}));
|
}));
|
||||||
output.push("</span>");
|
output.push("</span>");
|
||||||
if(node.children) {
|
if(node.children) {
|
||||||
@ -352,11 +352,11 @@ WikiTextParseTree.prototype.toString = function(type) {
|
|||||||
output.push(utils.stitchElement("span",
|
output.push(utils.stitchElement("span",
|
||||||
{"data-tw-treenode-type": "html"},{
|
{"data-tw-treenode-type": "html"},{
|
||||||
content: node.type,
|
content: node.type,
|
||||||
classNames: ["treeNode","label"]
|
classes: ["treeNode","label"]
|
||||||
}));
|
}));
|
||||||
for(var f in node.attributes) {
|
for(var f in node.attributes) {
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
classNames: ["treeNode"]
|
classes: ["treeNode"]
|
||||||
}));
|
}));
|
||||||
var v = node.attributes[f];
|
var v = node.attributes[f];
|
||||||
if(typeof v === "string") {
|
if(typeof v === "string") {
|
||||||
@ -366,18 +366,18 @@ WikiTextParseTree.prototype.toString = function(type) {
|
|||||||
}
|
}
|
||||||
if(typeof v === "object") {
|
if(typeof v === "object") {
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
classNames: ["label"],
|
classes: ["label"],
|
||||||
content: utils.htmlEncode(f)
|
content: utils.htmlEncode(f)
|
||||||
}));
|
}));
|
||||||
utils.renderObject(output,type,v);
|
utils.renderObject(output,type,v);
|
||||||
} else {
|
} else {
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
classNames: ["splitLabel"],
|
classes: ["splitLabel"],
|
||||||
content: utils.stitchElement("span",null,{
|
content: utils.stitchElement("span",null,{
|
||||||
classNames: ["splitLabelLeft"],
|
classes: ["splitLabelLeft"],
|
||||||
content: utils.htmlEncode(f)
|
content: utils.htmlEncode(f)
|
||||||
}) + utils.stitchElement("span",null,{
|
}) + utils.stitchElement("span",null,{
|
||||||
classNames: ["splitLabelRight"],
|
classes: ["splitLabelRight"],
|
||||||
content: utils.htmlEncode(v)
|
content: utils.htmlEncode(v)
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
@ -37,28 +37,28 @@ WikiTextRenderer.prototype.toString = function(type) {
|
|||||||
output.push(utils.stitchElement("span",
|
output.push(utils.stitchElement("span",
|
||||||
{"data-tw-treenode-type": "renderStep"},{
|
{"data-tw-treenode-type": "renderStep"},{
|
||||||
content: node.step.toString(),
|
content: node.step.toString(),
|
||||||
classNames: ["treeNode","label"]
|
classes: ["treeNode","label"]
|
||||||
}));
|
}));
|
||||||
output.push(utils.stitchElement("span",null,
|
output.push(utils.stitchElement("span",null,
|
||||||
{classNames: ["treeNode","splitLabel"]}));
|
{classes: ["treeNode","splitLabel"]}));
|
||||||
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepDependencies"},{
|
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepDependencies"},{
|
||||||
content: "dependencies",
|
content: "dependencies",
|
||||||
classNames: ["splitLabelLeft"]
|
classes: ["splitLabelLeft"]
|
||||||
}));
|
}));
|
||||||
output.push(utils.stitchElement("span",null,{
|
output.push(utils.stitchElement("span",null,{
|
||||||
content: utils.htmlEncode(node.dependencies === null ? "*" : node.dependencies.join(", ")),
|
content: utils.htmlEncode(node.dependencies === null ? "*" : node.dependencies.join(", ")),
|
||||||
classNames: ["splitLabelRight"]
|
classes: ["splitLabelRight"]
|
||||||
}));
|
}));
|
||||||
output.push("</span>");
|
output.push("</span>");
|
||||||
output.push(utils.stitchElement("span",null,
|
output.push(utils.stitchElement("span",null,
|
||||||
{classNames: ["treeNode","splitLabel"]}));
|
{classes: ["treeNode","splitLabel"]}));
|
||||||
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepHandler"},{
|
output.push(utils.stitchElement("span",{"data-tw-treenode-type": "renderStepHandler"},{
|
||||||
content: "handler",
|
content: "handler",
|
||||||
classNames: ["splitLabelLeft"]
|
classes: ["splitLabelLeft"]
|
||||||
}));
|
}));
|
||||||
output.push(utils.stitchElement("code",null,{
|
output.push(utils.stitchElement("code",null,{
|
||||||
content: utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"),
|
content: utils.htmlEncode(node.handler.toString()).replace(/\n/g,"<br>"),
|
||||||
classNames: ["splitLabelRight"]
|
classes: ["splitLabelRight"]
|
||||||
}));
|
}));
|
||||||
output.push("</span>");
|
output.push("</span>");
|
||||||
return true;
|
return true;
|
||||||
|
@ -22,7 +22,7 @@ exports.macro = {
|
|||||||
href: params.target
|
href: params.target
|
||||||
},{
|
},{
|
||||||
content: content,
|
content: content,
|
||||||
classNames: store.adjustClassesForLink([],params.target)
|
classes: store.adjustClassesForLink([],params.target)
|
||||||
});
|
});
|
||||||
} else if (type === "text/plain") {
|
} else if (type === "text/plain") {
|
||||||
return content;
|
return content;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user