diff --git a/jquery.jsoneditor.js b/jquery.jsoneditor.js index b202d99..b0771ad 100644 --- a/jquery.jsoneditor.js +++ b/jquery.jsoneditor.js @@ -28,21 +28,23 @@ var K = function() {}; var onchange = options.change || K; var onpropertyclick = options.propertyclick || K; + var enableAddNewValue = options.enableAddNewValue != null ? options.enableAddNewValue : true; return this.each(function() { - JSONEditor($(this), json, onchange, onpropertyclick, options.propertyElement, options.valueElement); + JSONEditor($(this), json, onchange, onpropertyclick, options.propertyElement, options.valueElement, enableAddNewValue); }); }; - function JSONEditor(target, json, onchange, onpropertyclick, propertyElement, valueElement) { + function JSONEditor(target, json, onchange, onpropertyclick, propertyElement, valueElement, enableAddNewValue) { var opt = { target: target, onchange: onchange, onpropertyclick: onpropertyclick, original: json, propertyElement: propertyElement, - valueElement: valueElement + valueElement: valueElement, + enableAddNewValue: enableAddNewValue }; construct(opt, json, opt.target); $(opt.target).on('blur focus', '.property, .value', function() { @@ -189,7 +191,7 @@ } } - if (isObject(json) || isArray(json)) { + if (opt.enableAddNewValue && (isObject(json) || isArray(json))) { addListAppender(root, function () { addNewValue(json); construct(opt, json, root, path); diff --git a/jquery.jsoneditor.min.js b/jquery.jsoneditor.min.js index d6b253b..e122d85 100644 --- a/jquery.jsoneditor.min.js +++ b/jquery.jsoneditor.min.js @@ -1,14 +1,4 @@ -// Simple yet flexible JSON editor plugin. -// Turns any element into a stylable interactive JSON editor. - -// Copyright (c) 2013 David Durman - -// Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php). - -(function(e){function v(b,a,c,d,f,h){b={target:b,onchange:c,onpropertyclick:d,original:a,propertyElement:f,valueElement:h};r(b,a,b.target);e(b.target).on("blur focus",".property, .value",function(){e(this).toggleClass("editing")})}function l(b){return"[object Object]"==Object.prototype.toString.call(b)}function m(b){return"[object Array]"==Object.prototype.toString.call(b)}function n(b,a,c){var d=2==arguments.length;if(-1",{"class":"expander"});a.bind("click",function(){e(this).parent().toggleClass("expanded")});b.prepend(a)}}function w(b,a){var c= -e("
",{"class":"item appender"}),d=e("",{"class":"property"});d.text("Add New Value");c.append(d);b.append(c);d.click(a);return c}function r(b,a,c,d){d=d||"";c.children(".item").remove();for(var f in a)if(a.hasOwnProperty(f)){var h=e("
",{"class":"item","data-path":d}),g=e(b.propertyElement||"",{"class":"property"}),k=e(b.valueElement||"",{"class":"value"});(l(a[f])||m(a[f]))&&s(h);h.append(g).append(k);c.append(h);g.val(f).attr("title",f);var n=q(a[f]);k.val(n).attr("title", -n);t(h,a[f]);g.change(x(b));k.change(y(b));g.click(z(b));(l(a[f])||m(a[f]))&&r(b,a[f],h,(d?d+".":"")+f)}(l(a)||m(a))&&w(c,function(){if(m(a))a.push(null);else if(l(a)){for(var e=1,f="newKey";a.hasOwnProperty(f);)f="newKey"+e,e++;a[f]=null}r(b,a,c,d);b.onchange(p(q(b.original)))})}function u(b,a){e(b).parentsUntil(a.target).each(function(){var b=e(this).data("path"),b=(b?b+".":b)+e(this).children(".property").val(),d;a:{d=a.original;for(var b=b.split("."),f=0;f-1){var r=n,e=0,u=t.split(".");for(f=u.length;e",{"class":"expander"});i.bind("click",function(){var t=n(this).parent();t.toggleClass("expanded")});t.prepend(i)}}function b(t,i){var r=n("
",{"class":"item appender"}),u=n("