mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-22 23:16:53 +00:00
Remove the obsolete element stitching functions
This commit is contained in:
parent
00774c1a48
commit
2cb337706d
153
js/Utils.js
153
js/Utils.js
@ -238,159 +238,6 @@ utils.stringify = function(s) {
|
||||
.replace(/[\x80-\uFFFF]/g, utils.escape); // non-ASCII characters
|
||||
};
|
||||
|
||||
// Creates an HTML element string from these arguments:
|
||||
// element: element name
|
||||
// attributes: hashmap of element attributes to add
|
||||
// options: hashmap of options
|
||||
// The attributes hashmap can contain strings or arrays of strings, which
|
||||
// are processed to attr="name1:value1;name2:value2;"
|
||||
// The options include:
|
||||
// content: a string to include as content in the element (also generates closing tag)
|
||||
// classes: an array of classnames to apply to the element
|
||||
// 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
|
||||
utils.stitchElement = function(element,attributes,options) {
|
||||
var output = [];
|
||||
options = options || {};
|
||||
output.push("<",element);
|
||||
if(attributes) {
|
||||
for(var a in attributes) {
|
||||
var v = attributes[a];
|
||||
if(v !== undefined) {
|
||||
if(typeof v === "object") {
|
||||
var s = [];
|
||||
for(var t in v) {
|
||||
s.push(t + ":" + v[t] + ";");
|
||||
}
|
||||
v = s.join("");
|
||||
}
|
||||
output.push(" ");
|
||||
output.push(a);
|
||||
output.push("='");
|
||||
output.push(utils.htmlEncode(v));
|
||||
output.push("'");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(options.insertAfterAttributes) {
|
||||
output.push(options.insertAfterAttributes);
|
||||
}
|
||||
if(options.classes) {
|
||||
output.push(" class='",options.classes.join(" "),"'");
|
||||
}
|
||||
output.push(">");
|
||||
if("content" in options) {
|
||||
output.push(options.content);
|
||||
output.push("</",element,">");
|
||||
}
|
||||
return output.join("");
|
||||
};
|
||||
|
||||
utils.stitchSlider = function(type,label,tooltip,body) {
|
||||
if(type === "text/html") {
|
||||
var labelAttrs = {};
|
||||
if(tooltip) {
|
||||
labelAttrs.alt = tooltip;
|
||||
labelAttrs.title = tooltip;
|
||||
}
|
||||
var labelNode = utils.stitchElement("a",labelAttrs,{
|
||||
content: label,
|
||||
classes: ["tw-slider-label"]
|
||||
}),
|
||||
bodyNode = utils.stitchElement("div",{
|
||||
style: {
|
||||
display: "none"
|
||||
}
|
||||
},{
|
||||
content: body,
|
||||
classes: ["tw-slider-body"]
|
||||
});
|
||||
return utils.stitchElement("div",null,{
|
||||
content: labelNode + bodyNode,
|
||||
classes: ["tw-slider"]
|
||||
});
|
||||
} else if(type === "text/plain") {
|
||||
return label + "\n" + body;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Render an object and its children to a specified MIME type
|
||||
type: target MIME type
|
||||
node: object to render
|
||||
customTemplates: optionally, an array of custom template functions
|
||||
|
||||
Arguments for the custom template functions:
|
||||
output: an array to which output strings should be pushed
|
||||
type: target MIME type
|
||||
node: the node to be examined/rendered
|
||||
|
||||
The custom template function should push the string rendering of the node to the output array, and return true, or just return false if it cannot render the node.
|
||||
*/
|
||||
utils.renderObject = function(output,type,node,customTemplates) {
|
||||
var renderNodeHtml,
|
||||
renderArrayHtml = function(output,tree) {
|
||||
output.push(utils.stitchElement("ul",null,{classes: ["treeArray"]}));
|
||||
for(var t=0; t<tree.length; t++) {
|
||||
output.push(utils.stitchElement("li",null,{classes: ["treeArrayMember"]}));
|
||||
renderNodeHtml(output,tree[t]);
|
||||
output.push("</li>");
|
||||
}
|
||||
output.push("</ul>");
|
||||
},
|
||||
renderFieldHtml = function(output,name,value) {
|
||||
output.push(utils.stitchElement("li",null,{classes: ["treeNodeField"]}));
|
||||
if(typeof value === "object") {
|
||||
output.push(utils.stitchElement("span",null,{
|
||||
classes: ["label"],
|
||||
content: utils.htmlEncode(name)
|
||||
}));
|
||||
renderNodeHtml(output,value);
|
||||
} else {
|
||||
output.push(utils.stitchElement("span",null,{
|
||||
classes: ["splitLabel"],
|
||||
content: utils.stitchElement("span",null,{
|
||||
classes: ["splitLabelLeft"],
|
||||
content: utils.htmlEncode(name)
|
||||
}) + utils.stitchElement("span",null,{
|
||||
classes: ["splitLabelRight"],
|
||||
content: utils.htmlEncode(value)
|
||||
})
|
||||
}));
|
||||
}
|
||||
output.push("</li>");
|
||||
};
|
||||
renderNodeHtml = function(output,node) {
|
||||
if(node instanceof Array) {
|
||||
renderArrayHtml(output,node);
|
||||
} else if (typeof node === "string") {
|
||||
output.push(utils.stitchElement("span",null,{
|
||||
classes: ["treeNode","label"],
|
||||
content: utils.htmlEncode(node)
|
||||
}));
|
||||
} else {
|
||||
var custom = false;
|
||||
for(var t=0; t<customTemplates.length; t++) {
|
||||
if(!custom && customTemplates[t](output,type,node)) {
|
||||
custom = true;
|
||||
}
|
||||
}
|
||||
if(!custom) {
|
||||
output.push(utils.stitchElement("ul",null,{classes: ["treeNode"]}));
|
||||
for(var f in node) {
|
||||
renderFieldHtml(output,f,node[f]);
|
||||
}
|
||||
output.push("</ul>");
|
||||
}
|
||||
}
|
||||
};
|
||||
if(type === "text/html") {
|
||||
renderNodeHtml(output,node);
|
||||
}
|
||||
};
|
||||
|
||||
utils.nextTick = function(fn) {
|
||||
/*global window: false */
|
||||
if(typeof window !== "undefined") {
|
||||
|
Loading…
Reference in New Issue
Block a user