summaryrefslogtreecommitdiff
path: root/share/www/script/futon.format.js
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2009-12-09 23:06:13 +0000
committerChristopher Lenz <cmlenz@apache.org>2009-12-09 23:06:13 +0000
commit4cd710ae4d2c813f41f8a8bb75595ec2202e7d6e (patch)
tree2fa85dce119601ae598bebc5bf76542b98de3bec /share/www/script/futon.format.js
parent995bef1f24aa746200030edc5a4f9e66b280689a (diff)
A couple of Futon improvements:
* JSON strings are now displayed as-is in the document view, without the escaping of new-lines and quotes. That dramatically improves readability of multi-line strings. * Same goes for editing of JSON string values. When a change to a field value is submitted, and the value is not valid JSON it is assumed to be a string. This improves editing of multi-line strings a lot. * Hitting tab in textareas no longer moves focus to the next form field, but simply inserts a tab character at the current caret position. * Fixed some font declarations. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@889013 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/futon.format.js')
-rw-r--r--share/www/script/futon.format.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/share/www/script/futon.format.js b/share/www/script/futon.format.js
index 7d70bfc2..674f5f8f 100644
--- a/share/www/script/futon.format.js
+++ b/share/www/script/futon.format.js
@@ -17,6 +17,7 @@
// JSON pretty printing
formatJSON: function(val, options) {
options = $.extend({
+ escapeStrings: true,
indent: 4,
linesep: "\n",
quoteKeys: true
@@ -39,9 +40,14 @@
case "boolean":
case "number":
case "string":
- var retval = JSON.stringify(val);
+ var retval = val;
+ if (type == "string" && !options.escapeStrings) {
+ retval = indentLines(retval, tab);
+ } else {
+ retval = escape(JSON.stringify(val));
+ }
if (options.html) {
- retval = "<code class='" + type + "'>" + escape(retval) + "</code>";
+ retval = "<code class='" + type + "'>" + retval + "</code>";
}
return retval;
@@ -95,6 +101,14 @@
}
}
+ function indentLines(text, tab) {
+ var lines = text.split("\n");
+ for (var i in lines) {
+ lines[i] = (i > 0 ? tab : "") + escape(lines[i]);
+ }
+ return lines.join("<br>");
+ }
+
return format(val, 1);
},
@@ -112,4 +126,5 @@
}
});
+
})(jQuery);