(json, indent, dont_indent, show_level, max_string, sort_objects)
| 88 | return a; }; |
| 89 | |
| 90 | function _renderjson(json, indent, dont_indent, show_level, max_string, sort_objects) { |
| 91 | var my_indent = dont_indent ? "" : indent; |
| 92 | |
| 93 | var disclosure = function(open, placeholder, close, type, builder) { |
| 94 | var content; |
| 95 | var empty = span(type); |
| 96 | var show = function() { if (!content) append(empty.parentNode, |
| 97 | content = prepend(builder(), |
| 98 | A(renderjson.hide, "disclosure", |
| 99 | function() { content.style.display="none"; |
| 100 | empty.style.display="inline"; } ))); |
| 101 | content.style.display="inline"; |
| 102 | empty.style.display="none"; }; |
| 103 | append(empty, |
| 104 | A(renderjson.show, "disclosure", show), |
| 105 | themetext(type+ " syntax", open), |
| 106 | A(placeholder, null, show), |
| 107 | themetext(type+ " syntax", close)); |
| 108 | |
| 109 | var el = append(span(), text(my_indent.slice(0,-1)), empty); |
| 110 | if (show_level > 0) |
| 111 | show(); |
| 112 | return el; |
| 113 | }; |
| 114 | |
| 115 | if (json === null) return themetext(null, my_indent, "keyword", "null"); |
| 116 | if (json === void 0) return themetext(null, my_indent, "keyword", "undefined"); |
| 117 | |
| 118 | if (typeof(json) == "string" && json.length > max_string) |
| 119 | return disclosure('"', json.substr(0,max_string)+" ...", '"', "string", function () { |
| 120 | return append(span("string"), themetext(null, my_indent, "string", JSON.stringify(json))); |
| 121 | }); |
| 122 | |
| 123 | if (typeof(json) != "object") // Strings, numbers and bools |
| 124 | return themetext(null, my_indent, typeof(json), JSON.stringify(json)); |
| 125 | |
| 126 | if (json.constructor == Array) { |
| 127 | if (json.length == 0) return themetext(null, my_indent, "array syntax", "[]"); |
| 128 | |
| 129 | return disclosure("[", " ... ", "]", "array", function () { |
| 130 | var as = append(span("array"), themetext("array syntax", "[", null, "\n")); |
| 131 | for (var i=0; i<json.length; i++) |
| 132 | append(as, |
| 133 | _renderjson(json[i], indent+" ", false, show_level-1, max_string, sort_objects), |
| 134 | i != json.length-1 ? themetext("syntax", ",") : [], |
| 135 | text("\n")); |
| 136 | append(as, themetext(null, indent, "array syntax", "]")); |
| 137 | return as; |
| 138 | }); |
| 139 | } |
| 140 | |
| 141 | // object |
| 142 | if (isempty(json)) |
| 143 | return themetext(null, my_indent, "object syntax", "{}"); |
| 144 | |
| 145 | return disclosure("{", "...", "}", "object", function () { |
| 146 | var os = append(span("object"), themetext("object syntax", "{", null, "\n")); |
| 147 | for (var k in json) var last = k; |
no test coverage detected