diff --git a/js/Utils.js b/js/Utils.js index 308616ca7..7b0f6262a 100755 --- a/js/Utils.js +++ b/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
-// 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(""); - } - 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"); - } - output.push(""); - }, - 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(""); - }; - 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"); - } - } - }; - if(type === "text/html") { - renderNodeHtml(output,node); - } -}; - utils.nextTick = function(fn) { /*global window: false */ if(typeof window !== "undefined") {