From a58246859370c52b5209fe94a043bdcc7f8b7001 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Mon, 12 Jan 2009 21:06:35 +0000 Subject: Add syntax highlighting of JSON code in Futon. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@733897 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/browse.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'share/www/script/browse.js') diff --git a/share/www/script/browse.js b/share/www/script/browse.js index 5ee3e3cd..c27f48ef 100644 --- a/share/www/script/browse.js +++ b/share/www/script/browse.js @@ -59,7 +59,7 @@ function CouchIndexPage() { $.couch.db(dbName).info({ success: function(info) { $("#databases tbody.content tr:eq(" + idx + ")") - .find("td.size").text(prettyPrintSize(info.disk_size)).end() + .find("td.size").text($.futon.formatSize(info.disk_size)).end() .find("td.count").text(info.doc_count).end() .find("td.seq").text(info.update_seq); if (idx == dbsOnPage.length - 1) { @@ -457,22 +457,28 @@ function CouchDatabasePage() { for (var i = 0; i < resp.rows.length; i++) { var row = resp.rows[i]; var tr = $(""); - var key = row.key; + var key = "null"; + if (row.key !== null) { + key = $.futon.formatJSON(row.key, {indent: 0, linesep: ""}); + } if (row.id) { $("
" + "ID: " + row.id + "
") - .find("strong").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end() + .find("strong").text(key).end() .appendTo(tr); } else { $("") - .find("strong").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end() + .find("strong").text(key).end() .appendTo(tr); } - var value = row.value; - $("").text( - value !== null ? prettyPrintJSON(value, 0, "") : "null" - ).appendTo(tr).dblclick(function() { + var value = "null"; + if (row.value !== null) { + value = $.futon.formatJSON(row.value, { + html: true, indent: 0, linesep: "", quoteKeys: false + }); + } + $("
").find("div").html(value).end().appendTo(tr).dblclick(function() { location.href = this.previousSibling.firstChild.href; }); tr.appendTo("#documents tbody.content"); @@ -736,7 +742,7 @@ function CouchDocumentPage() { _initValue(value); } } - $("#fields tbody tr").removeClass("odd").filter(":odd").addClass("odd"); + $("#fields tbody.content tr").removeClass("odd").filter(":odd").addClass("odd"); return row; } @@ -838,7 +844,7 @@ function CouchDocumentPage() { cancelChange(); }).appendTo(tools); tools.appendTo(td); - input.val(prettyPrintJSON(value)).appendTo(td); + input.val($.futon.formatJSON(value)).appendTo(td); input.each(function() { this.focus(); this.select(); }); if (needsTextarea) input.makeResizable({vertical: true}); } @@ -849,7 +855,7 @@ function CouchDocumentPage() { delete doc[fieldName]; row.remove(); page.isDirty = true; - $("#fields tbody tr").removeClass("odd").filter(":odd").addClass("odd"); + $("#fields tbody.content tr").removeClass("odd").filter(":odd").addClass("odd"); }).prependTo(row.find("th")); } } @@ -894,7 +900,7 @@ function CouchDocumentPage() { $("").text(name) .attr("href", attachmentHref) .wrapInner("").appendTo(li); - $("()").text("" + prettyPrintSize(attachment.length) + + $("()").text("" + $.futon.formatSize(attachment.length) + ", " + attachment.content_type).addClass("info").appendTo(li); if (name == "tests.js") { li.find('span.info').append(',