diff --git a/js/Utils.js b/js/Utils.js index 0f8754337..7d3cd09f9 100755 --- a/js/Utils.js +++ b/js/Utils.js @@ -286,6 +286,71 @@ utils.stitchElement = function(element,attributes,options) { return output.join(""); }; +/* +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 renderArrayHtml = function(output,tree) { + output.push(utils.stitchElement("ul",null,{classNames: ["treeArray"]})); + for(var t=0; t"); + } + output.push(""); + }, + renderFieldHtml = function(output,name,value) { + output.push(utils.stitchElement("li",null,{classNames: ["treeNodeField"]})); + output.push(utils.stitchElement("span",null,{ + content: utils.htmlEncode(name), + classNames: ["treeNodeFieldName"] + })); + if (value instanceof Array) { + renderArrayHtml(output,value); + } else if(typeof value === "object") { + renderNodeHtml(output,value); + } else { + output.push(utils.stitchElement("span",null,{ + content: utils.htmlEncode(value), + classNames: ["treeNodeFieldValue"] + })); + } + output.push("") + }, + renderNodeHtml = function(output,node) { + if(node instanceof Array) { + renderArrayHtml(output,node); + } else { + output.push(utils.stitchElement("ul",null,{classNames: ["treeNode"]})); + 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") {