diff --git a/dist/jsoneditor.js b/dist/jsoneditor.js index e9adf2d99..bdc1f6aae 100644 --- a/dist/jsoneditor.js +++ b/dist/jsoneditor.js @@ -1,4 +1,4 @@ -/*! JSON Editor v0.6.3 - JSON Schema -> HTML Editor +/*! JSON Editor v0.6.4 - JSON Schema -> HTML Editor * By Jeremy Dorn - https://github.com/jdorn/json-editor/ * Released under the MIT license * @@ -2124,19 +2124,18 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({ clientSideStorage: false }); - this.epiceditor = new EpicEditor(options); + this.epiceditor = new EpicEditor(options).load(); this.epiceditor.importFile(null,this.getValue()); this.epiceditor.on('update',function() { var val = self.epiceditor.exportFile(); self.input.value = val; + self.value = val; if(self.parent) self.parent.onChildEditorChange(self); else self.jsoneditor.onChange(); self.jsoneditor.notifyWatchers(self.path); }); - - this.epiceditor.load(); } // ACE editor for everything else else if(window.ace) { diff --git a/dist/jsoneditor.min.js b/dist/jsoneditor.min.js index 2e6935f94..5b2490873 100644 --- a/dist/jsoneditor.min.js +++ b/dist/jsoneditor.min.js @@ -1,10 +1,10 @@ -/*! JSON Editor v0.6.3 - JSON Schema -> HTML Editor +/*! JSON Editor v0.6.4 - JSON Schema -> HTML Editor * By Jeremy Dorn - https://github.com/jdorn/json-editor/ * Released under the MIT license * * Date: 2014-04-26 */ -!function(){var a;!function(){var b=!1,c=/xyz/.test(function(){})?/\b_super\b/:/.*/;a=function(){},a.extend=function(a){function d(){!b&&this.init&&this.init.apply(this,arguments)}var e=this.prototype;b=!0;var f=new this;b=!1;for(var g in a)f[g]="function"==typeof a[g]&&"function"==typeof e[g]&&c.test(a[g])?function(a,b){return function(){var c=this._super;this._super=e[a];var d=b.apply(this,arguments);return this._super=c,d}}(g,a[g]):a[g];return d.prototype=f,d.prototype.constructor=d,d.extend=arguments.callee,d}}(),function(){function a(a,b){b=b||{bubbles:!1,cancelable:!1,detail:void 0};var c=document.createEvent("CustomEvent");return c.initCustomEvent(a,b.bubbles,b.cancelable,b.detail),c}a.prototype=window.Event.prototype,window.CustomEvent=a}(),function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c=e){if(h)return;h=!0,i._getRefs(a,b)}},d(k,function(){e++}),e?d(k,function(b,c){i._getRefs(c,function(c){i.refs["#/definitions/"+b]=c,f++,g(a)})}):g(a)}else if(a.$ref){var l=a.$ref;if(delete a.$ref,i.refs[l]&&i.refs[l]instanceof Array)i.refs[l].push(function(){a=c({},i.refs[l],a),b(a)});else if(i.refs[l])a=c({},i.refs[l],a),b(a);else{if(!i.options.ajax)throw"Must set ajax option to true to load external url "+l;var m=new XMLHttpRequest;m.open("GET",l,!0),m.onreadystatechange=function(){if(4==m.readyState){if(200===m.status){var e=JSON.parse(m.responseText);return i.refs[l]=[],void i._getRefs(e,function(e){var f=i.refs[l];i.refs[l]=e,a=c({},i.refs[l],a),b(a),d(f,function(a,b){b()})})}throw"Failed to fetch ref via ajax- "+l}},m.send()}}else e=f=0,g=function(a){if(f>=e){if(h)return;h=!0,b(a)}},d(a,function(a,b){"object"==typeof b&&b&&b instanceof Array?d(b,function(a,b){"object"!=typeof b||!b||b instanceof Array||e++}):"object"==typeof b&&b&&e++}),e?d(a,function(b,c){"object"==typeof c&&c&&c instanceof Array?d(c,function(c,d){"object"!=typeof d||!d||d instanceof Array||i._getRefs(d,function(d){a[b][c]=d,f++,g(a)})}):"object"==typeof c&&c&&i._getRefs(c,function(c){a[b]=c,f++,g(a)})}):g(a)},validate:function(a){return this._validateSchema(this.schema,a)},_validateSchema:function(a,b,e){var f,h,i,j=[],k=JSON.stringify(b);if(e=e||"root",a=c({},a),a.required&&a.required===!0){if("undefined"==typeof b)return j.push({path:e,property:"required",message:"Property must be set"}),j}else if("undefined"==typeof b){if(!this.options.required_by_default)return j;j.push({path:e,property:"required",message:"Property must be set"})}if(a.enum){for(f=!1,h=0;h=a.maximum?j.push({path:e,property:"maximum",message:"Value must be less than "+a.maximum}):!a.exclusiveMaximum&&b>a.maximum&&j.push({path:e,property:"maximum",message:"Value must be at most "+a.maximum})),a.minimum&&(a.exclusiveMinimum&&b<=a.minimum?j.push({path:e,property:"minimum",message:"Value must be greater than "+a.minimum}):!a.exclusiveMinimum&&ba.maxLength&&j.push({path:e,property:"maxLength",message:"Value must be at most "+a.maxLength+" characters long"}),a.minLength&&(b+"").lengtha.maxItems&&j.push({path:e,property:"maxItems",message:"Value must have at most "+a.maxItems+" items"}),a.minItems&&b.lengtha.maxProperties&&j.push({path:e,property:"maxProperties",message:"Object must have at most "+a.maxProperties+" properties"})}if(a.minProperties){f=0;for(h in b)b.hasOwnProperty(h)&&f++;f=0){b=this.theme.getBlockLinkHolder();var f=this.theme.getBlockLink();f.setAttribute("target","_blank");var h=document.createElement(d);h.setAttribute("controls","controls"),this.theme.createMediaLink(b,f,h),this.link_watchers.push(function(b){var c=e(b);f.setAttribute("href",c),f.textContent=a.rel||c,h.setAttribute("src",c)})}else b=this.theme.getBlockLink(),b.setAttribute("target","_blank"),b.textContent=a.rel,this.link_watchers.push(function(c){var d=e(c);b.setAttribute("href",d),b.textContent=a.rel||d});return b},refreshWatchedFieldValues:function(){if(this.watched_values){var a={},b=!1,c=this;if(this.watched){var d,e;for(var f in this.watched)this.watched.hasOwnProperty(f)&&(e=c.jsoneditor.getEditor(this.watched[f]),d=e?e.getValue():null,c.watched_values[f]!==d&&(b=!0),a[f]=d)}return a.self=this.getValue(),this.watched_values.self!==a.self&&(b=!0),this.watched_values=a,b}},getWatchedFieldValues:function(){return this.watched_values},updateHeaderText:function(){this.header&&(this.header.textContent=this.getHeaderText())},getHeaderText:function(a){return this.header_text?this.header_text:a?this.schema.title:this.getTitle()},onWatchedFieldChange:function(){if(this.header_template){var a=c(this.getWatchedFieldValues(),{key:this.key,i:this.key,title:this.getTitle()}),b=this.header_template(a);b!==this.header_text&&(this.header_text=b,this.updateHeaderText(),this.fireChangeHeaderEvent())}if(this.link_watchers.length)for(var a=this.getWatchedFieldValues(),d=0;d1&&(b[a]=d+" "+e[d])}),b},showValidationErrors:function(){}}),g.defaults.editors.null=g.AbstractEditor.extend({getValue:function(){return null},setValue:function(){this.jsoneditor.notifyWatchers(this.path)},getNumColumns:function(){return 2}}),g.defaults.editors.string=g.AbstractEditor.extend({getDefault:function(){return this.schema.default||""},setValue:function(a,b,c){var d=this;if((!this.template||c)&&(a=a||"","object"==typeof a&&(a=JSON.stringify(a)),"string"!=typeof a&&(a=""+a),a!==this.serialized)){var e=this.sanitize(a);if(this.select_options&&this.select_options.indexOf(e)<0&&(e=this.select_options[0]),this.input.value!==e){this.input.value=e,this.sceditor_instance?this.sceditor_instance.val(e):this.epiceditor?this.epiceditor.importFile(null,e):this.ace_editor&&this.ace_editor.setValue(e);var f=c||this.getValue()!==a;this.refreshValue(),f&&(d.parent?d.parent.onChildEditorChange(d):d.jsoneditor.onChange()),this.watch_listener(),this.jsoneditor.notifyWatchers(this.path)}}},removeProperty:function(){this._super(),this.input.style.display="none",this.description&&(this.description.style.display="none"),this.theme.disableLabel(this.label)},addProperty:function(){this._super(),this.input.style.display="",this.description&&(this.description.style.display=""),this.theme.enableLabel(this.label)},getNumColumns:function(){var a,b=Math.ceil(this.getTitle().length/5);return a="textarea"===this.input_type?6:["text","email"].indexOf(this.input_type)>=0?4:2,Math.min(12,Math.max(b,a))},build:function(){var a=this;if(this.getOption("compact",!1)||(this.header=this.label=this.theme.getFormInputLabel(this.getTitle())),this.schema.description&&(this.description=this.theme.getFormInputDescription(this.schema.description)),this.format=this.schema.format,!this.format&&this.schema.media&&this.schema.media.type&&(this.format=this.schema.media.type.replace(/(^(application|text)\/(x-)?(script\.)?)|(-source$)/g,"")),this.schema.enum)this.input_type="select",this.select_options=this.schema.enum,this.input=this.theme.getSelectInput(this.select_options);else if(this.schema.enumSource){if(this.input_type="select",this.input=this.theme.getSelectInput([]),this.enumSource=[],this.schema.enumSource instanceof Array)for(var b=0;b=0?(this.input_type=this.format,this.source_code=!0,this.input=this.theme.getTextareaInput()):(this.input_type=this.format,this.input=this.theme.getFormInputField(this.input_type));else this.input_type="text",this.input=this.theme.getFormInputField(this.input_type);"undefined"!=typeof this.schema.maxLength&&this.input.setAttribute("maxlength",this.schema.maxLength),"undefined"!=typeof this.schema.pattern?this.input.setAttribute("pattern",this.schema.pattern):"undefined"!=typeof this.schema.minLength&&this.input.setAttribute("pattern",".{"+this.schema.minLength+",}"),this.getOption("compact")&&this.container.setAttribute("class",this.container.getAttribute("class")+" compact"),(this.schema.readOnly||this.schema.readonly||this.schema.template)&&(this.always_disabled=!0,this.input.disabled=!0),this.input.addEventListener("change",function(b){if(b.preventDefault(),b.stopPropagation(),a.schema.template)return void(this.value=a.value);var c=this.value,d=a.sanitize(c);c!==d&&(this.value=d),a.refreshValue(),a.watch_listener(),a.jsoneditor.notifyWatchers(a.path),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange()}),this.format&&this.input.setAttribute("data-schemaformat",this.format),this.control=this.getTheme().getFormControl(this.label,this.input,this.description),this.container.appendChild(this.control),"select"===this.input_type&&window.$&&$.fn&&$.fn.select2&&$(this.input).select2(),requestAnimationFrame(function(){a.afterInputReady()}),this.schema.template?(this.template=this.jsoneditor.compileTemplate(this.schema.template,this.template_engine),this.refreshValue(),this.jsoneditor.notifyWatchers(this.path)):(this.refreshValue(),this.jsoneditor.notifyWatchers(this.path))},enable:function(){this.always_disabled||(this.input.disabled=!1),this._super()},disable:function(){this.input.disabled=!0,this._super()},afterInputReady:function(){var a=this;if(this.source_code)if(this.options.wysiwyg&&["html","bbcode"].indexOf(this.input_type)>=0&&window.$&&$.fn&&$.fn.sceditor)$(a.input).sceditor({plugins:"html"===a.input_type?"xhtml":"bbcode",emoticonsEnabled:!1,width:"100%",height:300}),a.sceditor_instance=$(a.input).sceditor("instance"),a.sceditor_instance.blur(function(){var b=$("
"+a.sceditor_instance.val()+"
");$("#sceditor-start-marker,#sceditor-end-marker,.sceditor-nlf",b).remove(),a.input.value=b.html(),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange(),a.jsoneditor.notifyWatchers(a.path)});else if("markdown"===this.input_type&&window.EpicEditor){this.epiceditor_container=document.createElement("div"),this.input.parentNode.insertBefore(this.epiceditor_container,this.input),this.input.style.display="none";var b=c({},g.plugins.epiceditor,{container:this.epiceditor_container,clientSideStorage:!1});this.epiceditor=new EpicEditor(b),this.epiceditor.importFile(null,this.getValue()),this.epiceditor.on("update",function(){var b=a.epiceditor.exportFile();a.input.value=b,a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange(),a.jsoneditor.notifyWatchers(a.path)}),this.epiceditor.load()}else if(window.ace){var d=this.input_type; +!function(){var a;!function(){var b=!1,c=/xyz/.test(function(){})?/\b_super\b/:/.*/;a=function(){},a.extend=function(a){function d(){!b&&this.init&&this.init.apply(this,arguments)}var e=this.prototype;b=!0;var f=new this;b=!1;for(var g in a)f[g]="function"==typeof a[g]&&"function"==typeof e[g]&&c.test(a[g])?function(a,b){return function(){var c=this._super;this._super=e[a];var d=b.apply(this,arguments);return this._super=c,d}}(g,a[g]):a[g];return d.prototype=f,d.prototype.constructor=d,d.extend=arguments.callee,d}}(),function(){function a(a,b){b=b||{bubbles:!1,cancelable:!1,detail:void 0};var c=document.createEvent("CustomEvent");return c.initCustomEvent(a,b.bubbles,b.cancelable,b.detail),c}a.prototype=window.Event.prototype,window.CustomEvent=a}(),function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c=e){if(h)return;h=!0,i._getRefs(a,b)}},d(k,function(){e++}),e?d(k,function(b,c){i._getRefs(c,function(c){i.refs["#/definitions/"+b]=c,f++,g(a)})}):g(a)}else if(a.$ref){var l=a.$ref;if(delete a.$ref,i.refs[l]&&i.refs[l]instanceof Array)i.refs[l].push(function(){a=c({},i.refs[l],a),b(a)});else if(i.refs[l])a=c({},i.refs[l],a),b(a);else{if(!i.options.ajax)throw"Must set ajax option to true to load external url "+l;var m=new XMLHttpRequest;m.open("GET",l,!0),m.onreadystatechange=function(){if(4==m.readyState){if(200===m.status){var e=JSON.parse(m.responseText);return i.refs[l]=[],void i._getRefs(e,function(e){var f=i.refs[l];i.refs[l]=e,a=c({},i.refs[l],a),b(a),d(f,function(a,b){b()})})}throw"Failed to fetch ref via ajax- "+l}},m.send()}}else e=f=0,g=function(a){if(f>=e){if(h)return;h=!0,b(a)}},d(a,function(a,b){"object"==typeof b&&b&&b instanceof Array?d(b,function(a,b){"object"!=typeof b||!b||b instanceof Array||e++}):"object"==typeof b&&b&&e++}),e?d(a,function(b,c){"object"==typeof c&&c&&c instanceof Array?d(c,function(c,d){"object"!=typeof d||!d||d instanceof Array||i._getRefs(d,function(d){a[b][c]=d,f++,g(a)})}):"object"==typeof c&&c&&i._getRefs(c,function(c){a[b]=c,f++,g(a)})}):g(a)},validate:function(a){return this._validateSchema(this.schema,a)},_validateSchema:function(a,b,e){var f,h,i,j=[],k=JSON.stringify(b);if(e=e||"root",a=c({},a),a.required&&a.required===!0){if("undefined"==typeof b)return j.push({path:e,property:"required",message:"Property must be set"}),j}else if("undefined"==typeof b){if(!this.options.required_by_default)return j;j.push({path:e,property:"required",message:"Property must be set"})}if(a.enum){for(f=!1,h=0;h=a.maximum?j.push({path:e,property:"maximum",message:"Value must be less than "+a.maximum}):!a.exclusiveMaximum&&b>a.maximum&&j.push({path:e,property:"maximum",message:"Value must be at most "+a.maximum})),a.minimum&&(a.exclusiveMinimum&&b<=a.minimum?j.push({path:e,property:"minimum",message:"Value must be greater than "+a.minimum}):!a.exclusiveMinimum&&ba.maxLength&&j.push({path:e,property:"maxLength",message:"Value must be at most "+a.maxLength+" characters long"}),a.minLength&&(b+"").lengtha.maxItems&&j.push({path:e,property:"maxItems",message:"Value must have at most "+a.maxItems+" items"}),a.minItems&&b.lengtha.maxProperties&&j.push({path:e,property:"maxProperties",message:"Object must have at most "+a.maxProperties+" properties"})}if(a.minProperties){f=0;for(h in b)b.hasOwnProperty(h)&&f++;f=0){b=this.theme.getBlockLinkHolder();var f=this.theme.getBlockLink();f.setAttribute("target","_blank");var h=document.createElement(d);h.setAttribute("controls","controls"),this.theme.createMediaLink(b,f,h),this.link_watchers.push(function(b){var c=e(b);f.setAttribute("href",c),f.textContent=a.rel||c,h.setAttribute("src",c)})}else b=this.theme.getBlockLink(),b.setAttribute("target","_blank"),b.textContent=a.rel,this.link_watchers.push(function(c){var d=e(c);b.setAttribute("href",d),b.textContent=a.rel||d});return b},refreshWatchedFieldValues:function(){if(this.watched_values){var a={},b=!1,c=this;if(this.watched){var d,e;for(var f in this.watched)this.watched.hasOwnProperty(f)&&(e=c.jsoneditor.getEditor(this.watched[f]),d=e?e.getValue():null,c.watched_values[f]!==d&&(b=!0),a[f]=d)}return a.self=this.getValue(),this.watched_values.self!==a.self&&(b=!0),this.watched_values=a,b}},getWatchedFieldValues:function(){return this.watched_values},updateHeaderText:function(){this.header&&(this.header.textContent=this.getHeaderText())},getHeaderText:function(a){return this.header_text?this.header_text:a?this.schema.title:this.getTitle()},onWatchedFieldChange:function(){if(this.header_template){var a=c(this.getWatchedFieldValues(),{key:this.key,i:this.key,title:this.getTitle()}),b=this.header_template(a);b!==this.header_text&&(this.header_text=b,this.updateHeaderText(),this.fireChangeHeaderEvent())}if(this.link_watchers.length)for(var a=this.getWatchedFieldValues(),d=0;d1&&(b[a]=d+" "+e[d])}),b},showValidationErrors:function(){}}),g.defaults.editors.null=g.AbstractEditor.extend({getValue:function(){return null},setValue:function(){this.jsoneditor.notifyWatchers(this.path)},getNumColumns:function(){return 2}}),g.defaults.editors.string=g.AbstractEditor.extend({getDefault:function(){return this.schema.default||""},setValue:function(a,b,c){var d=this;if((!this.template||c)&&(a=a||"","object"==typeof a&&(a=JSON.stringify(a)),"string"!=typeof a&&(a=""+a),a!==this.serialized)){var e=this.sanitize(a);if(this.select_options&&this.select_options.indexOf(e)<0&&(e=this.select_options[0]),this.input.value!==e){this.input.value=e,this.sceditor_instance?this.sceditor_instance.val(e):this.epiceditor?this.epiceditor.importFile(null,e):this.ace_editor&&this.ace_editor.setValue(e);var f=c||this.getValue()!==a;this.refreshValue(),f&&(d.parent?d.parent.onChildEditorChange(d):d.jsoneditor.onChange()),this.watch_listener(),this.jsoneditor.notifyWatchers(this.path)}}},removeProperty:function(){this._super(),this.input.style.display="none",this.description&&(this.description.style.display="none"),this.theme.disableLabel(this.label)},addProperty:function(){this._super(),this.input.style.display="",this.description&&(this.description.style.display=""),this.theme.enableLabel(this.label)},getNumColumns:function(){var a,b=Math.ceil(this.getTitle().length/5);return a="textarea"===this.input_type?6:["text","email"].indexOf(this.input_type)>=0?4:2,Math.min(12,Math.max(b,a))},build:function(){var a=this;if(this.getOption("compact",!1)||(this.header=this.label=this.theme.getFormInputLabel(this.getTitle())),this.schema.description&&(this.description=this.theme.getFormInputDescription(this.schema.description)),this.format=this.schema.format,!this.format&&this.schema.media&&this.schema.media.type&&(this.format=this.schema.media.type.replace(/(^(application|text)\/(x-)?(script\.)?)|(-source$)/g,"")),this.schema.enum)this.input_type="select",this.select_options=this.schema.enum,this.input=this.theme.getSelectInput(this.select_options);else if(this.schema.enumSource){if(this.input_type="select",this.input=this.theme.getSelectInput([]),this.enumSource=[],this.schema.enumSource instanceof Array)for(var b=0;b=0?(this.input_type=this.format,this.source_code=!0,this.input=this.theme.getTextareaInput()):(this.input_type=this.format,this.input=this.theme.getFormInputField(this.input_type));else this.input_type="text",this.input=this.theme.getFormInputField(this.input_type);"undefined"!=typeof this.schema.maxLength&&this.input.setAttribute("maxlength",this.schema.maxLength),"undefined"!=typeof this.schema.pattern?this.input.setAttribute("pattern",this.schema.pattern):"undefined"!=typeof this.schema.minLength&&this.input.setAttribute("pattern",".{"+this.schema.minLength+",}"),this.getOption("compact")&&this.container.setAttribute("class",this.container.getAttribute("class")+" compact"),(this.schema.readOnly||this.schema.readonly||this.schema.template)&&(this.always_disabled=!0,this.input.disabled=!0),this.input.addEventListener("change",function(b){if(b.preventDefault(),b.stopPropagation(),a.schema.template)return void(this.value=a.value);var c=this.value,d=a.sanitize(c);c!==d&&(this.value=d),a.refreshValue(),a.watch_listener(),a.jsoneditor.notifyWatchers(a.path),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange()}),this.format&&this.input.setAttribute("data-schemaformat",this.format),this.control=this.getTheme().getFormControl(this.label,this.input,this.description),this.container.appendChild(this.control),"select"===this.input_type&&window.$&&$.fn&&$.fn.select2&&$(this.input).select2(),requestAnimationFrame(function(){a.afterInputReady()}),this.schema.template?(this.template=this.jsoneditor.compileTemplate(this.schema.template,this.template_engine),this.refreshValue(),this.jsoneditor.notifyWatchers(this.path)):(this.refreshValue(),this.jsoneditor.notifyWatchers(this.path))},enable:function(){this.always_disabled||(this.input.disabled=!1),this._super()},disable:function(){this.input.disabled=!0,this._super()},afterInputReady:function(){var a=this;if(this.source_code)if(this.options.wysiwyg&&["html","bbcode"].indexOf(this.input_type)>=0&&window.$&&$.fn&&$.fn.sceditor)$(a.input).sceditor({plugins:"html"===a.input_type?"xhtml":"bbcode",emoticonsEnabled:!1,width:"100%",height:300}),a.sceditor_instance=$(a.input).sceditor("instance"),a.sceditor_instance.blur(function(){var b=$("
"+a.sceditor_instance.val()+"
");$("#sceditor-start-marker,#sceditor-end-marker,.sceditor-nlf",b).remove(),a.input.value=b.html(),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange(),a.jsoneditor.notifyWatchers(a.path)});else if("markdown"===this.input_type&&window.EpicEditor){this.epiceditor_container=document.createElement("div"),this.input.parentNode.insertBefore(this.epiceditor_container,this.input),this.input.style.display="none";var b=c({},g.plugins.epiceditor,{container:this.epiceditor_container,clientSideStorage:!1});this.epiceditor=new EpicEditor(b).load(),this.epiceditor.importFile(null,this.getValue()),this.epiceditor.on("update",function(){var b=a.epiceditor.exportFile();a.input.value=b,a.value=b,a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange(),a.jsoneditor.notifyWatchers(a.path)})}else if(window.ace){var d=this.input_type; ("cpp"===d||"c++"===d||"c"===d)&&(d="c_cpp"),this.ace_container=document.createElement("div"),this.ace_container.style.width="100%",this.ace_container.style.position="relative",this.ace_container.style.height="400px",this.input.parentNode.insertBefore(this.ace_container,this.input),this.input.style.display="none",this.ace_editor=ace.edit(this.ace_container),this.ace_editor.setValue(this.getValue()),g.plugins.ace.theme&&this.ace_editor.setTheme("ace/theme/"+g.plugins.ace.theme);var d=ace.require("ace/mode/"+d);d&&this.ace_editor.getSession().setMode(new d.Mode),this.ace_editor.on("change",function(){var b=a.ace_editor.getValue();a.input.value=b,a.refreshValue(),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange(),a.jsoneditor.notifyWatchers(a.path)})}a.theme.afterInputReady(a.input)},refreshValue:function(){this.value=this.input.value,"string"!=typeof this.value&&(this.value=""),this.serialized=this.value},destroy:function(){this.sceditor_instance?this.sceditor_instance.destroy():this.epiceditor?this.epiceditor.unload():this.ace_editor&&this.ace_editor.destroy(),this.template=null,this.input.parentNode.removeChild(this.input),this.label&&this.label.parentNode.removeChild(this.label),this.description&&this.description.parentNode.removeChild(this.description),this._super()},sanitize:function(a){return a},onWatchedFieldChange:function(){if(this.template){var a=this.getWatchedFieldValues();this.setValue(this.template(a),!1,!0)}if(this.enumSource){for(var a=this.getWatchedFieldValues(),b=[],c=[],d=0;df)&&(d=g);d===!1&&(c.push({width:0,minh:999999,maxh:0,editors:[]}),d=c.length-1),c[d].editors.push({key:a,width:e,height:f}),c[d].width+=e,c[d].minh=Math.min(c[d].minh,f),c[d].maxh=Math.max(c[d].maxh,f)}});for(var e=0;ec[e].editors[f].width&&(f=h),c[e].editors[h].width*=12/c[e].width,c[e].editors[h].width=Math.floor(c[e].editors[h].width),g+=c[e].editors[h].width;12>g&&(c[e].editors[f].width+=12-g),c[e].width=12}if(this.layout===JSON.stringify(c))return!1;this.layout=JSON.stringify(c),b=document.createElement("div");for(var e=0;e=0),a.editors[b]=a.jsoneditor.createEditor(d,{jsoneditor:a.jsoneditor,schema:c,container:e,path:a.path+"."+b,parent:a,required:f}),a.minwidth=Math.max(a.minwidth,a.editors[b].getNumColumns()),a.maxwidth+=a.editors[b].getNumColumns()}),this.layoutEditors(),this.layoutEditors(),this.title_controls=this.getTheme().getHeaderButtonHolder(),this.editjson_controls=this.getTheme().getHeaderButtonHolder(),this.addproperty_controls=this.getTheme().getHeaderButtonHolder(),this.title.appendChild(this.title_controls),this.title.appendChild(this.editjson_controls),this.title.appendChild(this.addproperty_controls),this.collapsed=!1,this.toggle_button=this.getButton("","collapse","Collapse"),this.title_controls.appendChild(this.toggle_button),this.toggle_button.addEventListener("click",function(){a.collapsed?(a.editor_holder.style.display="",a.collapsed=!1,a.setButtonText(a.toggle_button,"","collapse","Collapse")):(a.editor_holder.style.display="none",a.collapsed=!0,a.setButtonText(a.toggle_button,"","expand","Expand"))}),this.options.collapsed&&e(this.toggle_button,"click"),this.schema.options&&"undefined"!=typeof this.schema.options.disable_collapse?this.schema.options.disable_collapse&&(this.toggle_button.style.display="none"):this.jsoneditor.options.disable_collapse&&(this.toggle_button.style.display="none"),this.editjson_button=this.getButton("JSON","edit","Edit JSON"),this.editjson_button.addEventListener("click",function(){a.toggleEditJSON()}),this.editjson_controls.appendChild(this.editjson_button),this.editjson_controls.appendChild(this.editjson_holder),this.schema.options&&"undefined"!=typeof this.schema.options.disable_edit_json?this.schema.options.disable_edit_json&&(this.editjson_button.style.display="none"):this.jsoneditor.options.disable_edit_json&&(this.editjson_button.style.display="none"),this.addproperty_button=this.getButton("Properties","edit","Object Properties"),this.addproperty_button.addEventListener("click",function(){a.toggleAddProperty()}),this.addproperty_controls.appendChild(this.addproperty_button),this.addproperty_controls.appendChild(this.addproperty_holder),this.refreshAddProperties()}this.jsoneditor.notifyWatchers(this.path)},showEditJSON:function(){this.editjson_holder&&(this.hideAddProperty(),this.editjson_holder.style.left=this.editjson_button.offsetLeft+"px",this.editjson_holder.style.top=this.editjson_button.offsetTop+this.editjson_button.offsetHeight+"px",this.editjson_textarea.value=JSON.stringify(this.getValue(),null,2),this.disable(),this.editjson_holder.style.display="",this.editjson_button.disabled=!1,this.editing_json=!0)},hideEditJSON:function(){this.editjson_holder&&this.editing_json&&(this.editjson_holder.style.display="none",this.enable(),this.editing_json=!1)},saveJSON:function(){if(this.editjson_holder)try{var a=JSON.parse(this.editjson_textarea.value);this.setValue(a),this.hideEditJSON()}catch(b){throw alert("invalid JSON"),b}},toggleEditJSON:function(){this.editing_json?this.hideEditJSON():this.showEditJSON()},addPropertyCheckbox:function(a){var b=this.editors[a];if(b){var c,d,e,f=this;return c=f.theme.getCheckbox(),c.style.width="auto",d=f.theme.getCheckboxLabel(a),e=f.theme.getFormControl(d,c),e.style.paddingBottom=e.style.marginBottom=e.style.paddingTop=e.style.marginTop=0,e.style.height="auto",f.addproperty_list.appendChild(e),c.checked=!b.property_removed,b.isRequired()&&(c.disabled=!0),c.addEventListener("change",function(){c.checked?f.addObjectProperty(a):f.removeObjectProperty(a)}),c}},showAddProperty:function(){if(this.addproperty_holder){this.hideEditJSON(),this.addproperty_holder.style.left=this.addproperty_button.offsetLeft+"px",this.addproperty_holder.style.top=this.addproperty_button.offsetTop+this.addproperty_button.offsetHeight+"px",this.addproperty_list.innerHTML="";var a=this;this.addproperty_checkboxes={},d(this.editors,function(b){a.addproperty_checkboxes[b]=a.addPropertyCheckbox(b)}),this.disable(),this.adding_property=!0,this.addproperty_button.disabled=!1,this.addproperty_holder.style.display="",this.refreshAddProperties()}},hideAddProperty:function(){this.addproperty_holder&&this.adding_property&&(this.addproperty_holder.style.display="none",this.enable(),this.adding_property=!1)},toggleAddProperty:function(){this.adding_property?this.hideAddProperty():this.showAddProperty()},removeObjectProperty:function(a){this.editors[a]&&(this.editors[a].property_removed=!0,this.editors[a].unregister(),this.refreshValue(),this.layoutEditors(),this.jsoneditor.notifyWatchers(this.path),this.parent?this.parent.onChildEditorChange(this):this.jsoneditor.onChange())},addObjectProperty:function(a){var b=this;if(this.editors[a]){if(!this.editors[a].property_removed)return;this.editors[a].property_removed=!1,this.editors[a].register(),this.jsoneditor.notifyWatchers(this.editors[a].path)}else{var e={},f=!1;b.schema.patternProperties&&d(b.schema.patternProperties,function(b,d){var g=new RegExp(b);g.test(a)&&(f=!0,e=c(e,d))}),f||"object"!=typeof b.schema.additionalProperties||(e=c(e,b.schema.additionalProperties));var g=b.jsoneditor.getEditorClass(e,b.jsoneditor),h=b.getTheme().getChildEditorHolder();b.editor_holder.appendChild(h),b.editors[a]=b.jsoneditor.createEditor(g,{jsoneditor:b.jsoneditor,schema:e,container:h,path:b.path+"."+a,parent:b,required:!1}),b.editors[a].not_core=!0}b.refreshValue(),b.jsoneditor.notifyWatchers(b.path),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange(),b.layoutEditors()},onChildEditorChange:function(a){this.refreshValue(),this._super(a)},canHaveAdditionalProperties:function(){return this.schema.additionalProperties!==!1&&!this.jsoneditor.options.no_additional_properties},destroy:function(){d(this.editors,function(a,b){b.destroy()}),this.editor_holder.innerHTML="",this.title&&this.title.parentNode.removeChild(this.title),this.error_holder&&this.error_holder.parentNode.removeChild(this.error_holder),this.editors=null,this.editor_holder.parentNode.removeChild(this.editor_holder),this.editor_holder=null,this._super()},refreshValue:function(){this.value={},this.serialized="";var a=this,b=0,c=!1,e=this.editors;d(this.editors,function(a,b){b.property_removed&&b.not_core&&(e={},c=!0)}),d(this.editors,function(d,f){if(f.property_removed){if(!f.not_core&&c)e[d]=f;else if(f.not_core){var g=f.container;f.destroy(),g.parentNode&&g.parentNode.removeChild(g)}}else c&&(e[d]=f),b++,a.value[d]=f.getValue()}),this.editors=e,this.adding_property&&this.refreshAddProperties()},refreshAddProperties:function(){var a,b=!1,c=!1,d=0,e=!1;for(a in this.editors)this.editors.hasOwnProperty(a)&&(this.editors[a].property_removed||d++);b=this.canHaveAdditionalProperties()&&!("undefined"!=typeof this.schema.maxProperties&&d>=this.schema.maxProperties);for(a in this.editors)this.editors.hasOwnProperty(a)&&(this.editors[a].isRequired()?this.addproperty_checkboxes&&this.addproperty_checkboxes[a]&&(this.addproperty_checkboxes[a].disabled=!0):"undefined"!=typeof this.schema.minProperties&&d<=this.schema.minProperties?this.addproperty_checkboxes&&this.addproperty_checkboxes[a]?(this.addproperty_checkboxes[a].disabled=this.addproperty_checkboxes[a].checked,this.addproperty_checkboxes[a].checked||(e=!0)):this.editors[a].property_removed&&b&&(e=!0):this.editors[a].property_removed?this.addproperty_checkboxes&&this.addproperty_checkboxes[a]?b?(this.addproperty_checkboxes[a].disabled=!1,e=!0):this.addproperty_checkboxes[a].disabled=!0:b&&(e=!0):(this.addproperty_checkboxes&&this.addproperty_checkboxes[a]&&(this.addproperty_checkboxes[a].disabled=!1),e=!0,c=!0));if(this.canHaveAdditionalProperties()&&(e=!0),this.addproperty_checkboxes)for(var a in this.addproperty_checkboxes)this.addproperty_checkboxes.hasOwnProperty(a)&&(this.editors[a]||(e=!0,this.addproperty_checkboxes[a].disabled=!b&&!c));e?this.canHaveAdditionalProperties()?this.addproperty_add.disabled=b?!1:!0:(this.addproperty_add.style.display="none",this.addproperty_input.style.display="none"):(this.hideAddProperty(),this.addproperty_controls.style.display="none")},setValue:function(a,b){var c=this;a=a||{},("object"!=typeof a||a instanceof Array)&&(a={}),d(this.editors,function(d,e){if("undefined"!=typeof a[d])e.property_removed&&c.addObjectProperty(d),e.setValue(a[d],b);else{if(!b&&!e.property_removed&&!e.isRequired())return void c.removeObjectProperty(d);e.setValue(e.getDefault(),b)}}),this.canHaveAdditionalProperties()&&d(a,function(a,d){c.editors[a]||(c.addObjectProperty(a),c.editors[a]&&c.editors[a].setValue(d,b))}),this.refreshValue(),this.jsoneditor.notifyWatchers(this.path)},showValidationErrors:function(a){var b=this,c=[],e=[];if(d(a,function(a,d){d.path===b.path?c.push(d):e.push(d)}),this.error_holder)if(c.length){this.error_holder.innerHTML="",this.error_holder.style.display="",d(c,function(a,c){b.error_holder.appendChild(b.theme.getErrorMessage(c.message))})}else this.error_holder.style.display="none";this.getOption("table_row")&&(c.length?this.theme.addTableRowError(this.container):this.theme.removeTableRowError(this.container)),d(this.editors,function(a,b){b.showValidationErrors(e)})}}),g.defaults.editors.array=g.AbstractEditor.extend({getDefault:function(){return this.schema.default||[]},register:function(){if(this._super(),this.rows)for(var a=0;a=this.schema.items.length?this.schema.additionalItems===!0?{}:this.schema.additionalItems?c({},this.schema.additionalItems):void 0:c({},this.schema.items[a]):this.schema.items?c({},this.schema.items):{}},getItemInfo:function(a){var b=this.getItemSchema(a);this.item_info=this.item_info||{};var c=JSON.stringify(b);if("undefined"!=typeof this.item_info[c])return this.item_info[c];var d=document.createElement("div");this.container.appendChild(d),d.addEventListener("change_header_text",function(a){a.preventDefault(),a.stopPropagation()});var e=this.jsoneditor.getEditorClass(b,this.jsoneditor);return e=this.jsoneditor.createEditor(e,{jsoneditor:this.jsoneditor,schema:b,container:d,path:this.path+"."+a,parent:this,required:!0}),this.item_info[c]={child_editors:e.getChildEditors()?!0:!1,title:b.title||"item",width:e.getNumColumns(),"default":e.getDefault()},e.destroy(),d.parentNode&&d.parentNode.removeChild(d),this.item_info[c]},getElementEditor:function(a){var b=this.getItemInfo(a),c=this.getItemSchema(a);c.title=b.title+" "+a;var d,e=this.jsoneditor.getEditorClass(c,this.jsoneditor);d=this.tabs_holder?this.theme.getTabContent():b.child_editors?this.theme.getChildEditorHolder():this.theme.getIndentedPanel(),this.row_holder.appendChild(d);var f=this.jsoneditor.createEditor(e,{jsoneditor:this.jsoneditor,schema:c,container:d,path:this.path+"."+a,parent:this,required:!0});return f.title_controls||(f.array_controls=this.theme.getButtonHolder(),d.appendChild(f.array_controls)),f},destroy:function(){this.empty(!0),this.title&&this.title.parentNode.removeChild(this.title),this.description&&this.description.parentNode.removeChild(this.description),this.row_holder&&this.row_holder.parentNode.removeChild(this.row_holder),this.controls&&this.controls.parentNode.removeChild(this.controls),this.panel&&this.panel.parentNode.removeChild(this.panel),this.rows=this.row_cache=this.title=this.description=this.row_holder=this.panel=this.controls=null,this._super()},empty:function(a){if(this.rows){var b=this;d(this.rows,function(c,d){a&&(d.tab&&d.tab.parentNode&&d.tab.parentNode.removeChild(d.tab),b.destroyRow(d,!0),b.row_cache[c]=null),b.rows[c]=null}),b.rows=[],a&&(b.row_cache=[])}},destroyRow:function(a,b){var c=a.container;b?(a.destroy(),c.parentNode&&c.parentNode.removeChild(c),a.tab&&a.tab.parentNode&&a.tab.parentNode.removeChild(a.tab)):(a.tab&&(a.tab.style.display="none"),c.style.display="none")},getMax:function(){return this.schema.items instanceof Array&&0==this.schema.additionalItems?Math.min(this.schema.items.length,this.schema.maxItems||1/0):this.schema.maxItems||1/0},refreshTabs:function(a){var b=this;d(this.rows,function(c,d){d.tab&&(a?d.tab_text.textContent=d.getHeaderText():d.tab===b.active_tab?(b.theme.markTabActive(d.tab),d.container.style.display=""):(b.theme.markTabInactive(d.tab),d.container.style.display="none"))})},setValue:function(a){a=a||[],a instanceof Array||(a=[a]);var b=JSON.stringify(a);if(b!==this.serialized){if(this.schema.minItems)for(;a.lengththis.getMax()&&(a=a.slice(0,this.getMax()));var c=this;d(a,function(a,b){c.rows[a]?c.rows[a].setValue(b):c.row_cache[a]?(c.rows[a]=c.row_cache[a],c.rows[a].setValue(b),c.rows[a].container.style.display="",c.rows[a].tab&&(c.rows[a].tab.style.display="")):c.addRow(b)});for(var e=a.length;e=this.rows.length;d(this.rows,function(b,d){d.movedown_button.style.display=b===a.rows.length-1?"none":"",d.delete_button.style.display=c?"none":"",a.value[b]=d.getValue()}),this.value.length?1===this.value.length?(this.remove_all_rows_button.style.display="none",this.delete_last_row_button.style.display=c?"none":""):c?(this.delete_last_row_button.style.display="none",this.delete_last_row_button.style.display="none"):(this.delete_last_row_button.style.display="",this.remove_all_rows_button.style.display=""):(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none"),this.add_row_button.style.display=this.getMax()&&this.getMax()<=this.rows.length?"none":""}},addRow:function(a){var b=this,c=this.rows.length;b.rows[c]=this.getElementEditor(c),b.row_cache[c]=b.rows[c],b.tabs_holder&&(b.rows[c].tab_text=document.createElement("span"),b.rows[c].tab_text.textContent=b.rows[c].getHeaderText(),b.rows[c].tab=b.theme.getTab(b.rows[c].tab_text),b.rows[c].tab.addEventListener("click",function(a){b.active_tab=b.rows[c].tab,b.refreshTabs(),a.preventDefault(),a.stopPropagation()}),b.theme.addTab(b.tabs_holder,b.rows[c].tab)),b.rows[c].delete_button=this.getButton(b.getItemTitle(),"delete","Delete "+b.getItemTitle()),b.rows[c].delete_button.className+=" delete",b.rows[c].delete_button.setAttribute("data-i",c),b.rows[c].delete_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i"),c=b.getValue(),e=[],f=null;d(c,function(c,d){return c===a?void(b.rows[c].tab===b.active_tab&&(b.rows[c+1]?f=b.rows[c+1].tab:c&&(f=b.rows[c-1].tab))):void e.push(d)}),b.setValue(e),f&&(b.active_tab=f,b.refreshTabs()),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange()}),b.rows[c].moveup_button=this.getButton("","moveup","Move up"),b.rows[c].moveup_button.className+=" moveup",b.rows[c].moveup_button.setAttribute("data-i",c),b.rows[c].moveup_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i");if(!(0>=a)){var c=b.getValue(),d=c[a-1];c[a-1]=c[a],c[a]=d,b.setValue(c),b.active_tab=b.rows[a-1].tab,b.refreshTabs(),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange()}}),b.rows[c].movedown_button=this.getButton("","movedown","Move down"),b.rows[c].movedown_button.className+=" movedown",b.rows[c].movedown_button.setAttribute("data-i",c),b.rows[c].movedown_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i"),c=b.getValue();if(!(a>=c.length-1)){var d=c[a+1];c[a+1]=c[a],c[a]=d,b.setValue(c),b.active_tab=b.rows[a+1].tab,b.refreshTabs(),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange()}});var e=b.rows[c].title_controls||b.rows[c].array_controls;e&&(e.appendChild(b.rows[c].delete_button),c&&e.appendChild(b.rows[c].moveup_button),e.appendChild(b.rows[c].movedown_button)),a&&b.rows[c].setValue(a),b.refreshTabs()},addControls:function(){var a=this;this.collapsed=!1,this.toggle_button=this.getButton("","collapse","Collapse"),this.title_controls.appendChild(this.toggle_button);var b=a.row_holder.style.display,c=a.controls.style.display;this.toggle_button.addEventListener("click",function(){a.collapsed?(a.collapsed=!1,a.row_holder.style.display=b,a.tabs_holder&&(a.tabs_holder.style.display=""),a.controls.style.display=c,a.setButtonText(this,"","collapse","Collapse")):(a.collapsed=!0,a.row_holder.style.display="none",a.tabs_holder&&(a.tabs_holder.style.display="none"),a.controls.style.display="none",a.setButtonText(this,"","expand","Expand"))}),this.options.collapsed&&e(this.toggle_button,"click"),this.schema.options&&"undefined"!=typeof this.schema.options.disable_collapse?this.schema.options.disable_collapse&&(this.toggle_button.style.display="none"):this.jsoneditor.options.disable_collapse&&(this.toggle_button.style.display="none"),this.add_row_button=this.getButton(this.getItemTitle(),"add","Add "+this.getItemTitle()),this.add_row_button.addEventListener("click",function(){var b=a.rows.length;a.row_cache[b]?(a.rows[b]=a.row_cache[b],a.rows[b].container.style.display="",a.rows[b].tab&&(a.rows[b].tab.style.display="")):a.addRow(),a.active_tab=a.rows[b].tab,a.refreshTabs(),a.refreshValue(),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange(),a.jsoneditor.notifyWatchers(a.path)}),a.controls.appendChild(this.add_row_button),this.delete_last_row_button=this.getButton("Last "+this.getItemTitle(),"delete","Delete Last "+this.getItemTitle()),this.delete_last_row_button.addEventListener("click",function(){var b=a.getValue(),c=null;a.rows.length>1&&a.rows[a.rows.length-1].tab===a.active_tab&&(c=a.rows[a.rows.length-2].tab),b.pop(),a.setValue(b),c&&(a.active_tab=c,a.refreshTabs()),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange()}),a.controls.appendChild(this.delete_last_row_button),this.remove_all_rows_button=this.getButton("All","delete","Delete All"),this.remove_all_rows_button.addEventListener("click",function(){a.setValue([]),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange()}),a.controls.appendChild(this.remove_all_rows_button),a.tabs&&(this.add_row_button.style.width="100%",this.add_row_button.style.textAlign="left",this.add_row_button.style.marginBottom="3px",this.delete_last_row_button.style.width="100%",this.delete_last_row_button.style.textAlign="left",this.delete_last_row_button.style.marginBottom="3px",this.remove_all_rows_button.style.width="100%",this.remove_all_rows_button.style.textAlign="left",this.remove_all_rows_button.style.marginBottom="3px")},showValidationErrors:function(a){var b=this,c=[],e=[];if(d(a,function(a,d){d.path===b.path?c.push(d):e.push(d)}),this.error_holder)if(c.length){this.error_holder.innerHTML="",this.error_holder.style.display="",d(c,function(a,c){b.error_holder.appendChild(b.theme.getErrorMessage(c.message))})}else this.error_holder.style.display="none";d(this.rows,function(a,b){b.showValidationErrors(e)})}}),g.defaults.editors.table=g.defaults.editors.array.extend({addProperty:function(){this._super(),this.value.length&&(this.table.style.display="")},removeProperty:function(){this._super(),this.table.style.display="none"},register:function(){if(this._super(),this.rows)for(var a=0;athis.schema.maxItems&&(a=a.slice(0,this.schema.maxItems));var b=JSON.stringify(a);if(b!==this.serialized){var c=!1,e=this;d(a,function(a,b){e.rows[a]?e.rows[a].setValue(b):(e.addRow(b),c=!0)});for(var f=a.length;f=this.rows.length;d(this.rows,function(c,d){d.movedown_button.style.display=c===a.rows.length-1?"none":"",d.delete_button.style.display=b?"none":""}),this.value.length?1===this.value.length?(this.table.style.display="",this.remove_all_rows_button.style.display="none",this.delete_last_row_button.style.display=b?"none":""):(this.table.style.display="",b?(this.delete_last_row_button.style.display="none",this.delete_last_row_button.style.display="none"):(this.delete_last_row_button.style.display="",this.remove_all_rows_button.style.display="")):(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none",this.table.style.display="none"),this.add_row_button.style.display=this.schema.maxItems&&this.schema.maxItems<=this.rows.length?"none":""},refreshValue:function(){var a=this;this.value=[],d(this.rows,function(b,c){a.value[b]=c.getValue()}),this.serialized=JSON.stringify(this.value)},addRow:function(a){var b=this,c=this.rows.length;b.rows[c]=this.getElementEditor(c),b.rows[c].delete_button=this.getButton("","delete","Delete"),b.rows[c].delete_button.className+=" delete",b.rows[c].delete_button.setAttribute("data-i",c),b.rows[c].delete_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i"),c=b.getValue(),e=[];d(c,function(b,c){b!==a&&e.push(c)}),b.setValue(e),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange()}),b.rows[c].moveup_button=this.getButton("","moveup","Move up"),b.rows[c].moveup_button.className+=" moveup",b.rows[c].moveup_button.setAttribute("data-i",c),b.rows[c].moveup_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i");if(!(0>=a)){var c=b.getValue(),d=c[a-1];c[a-1]=c[a],c[a]=d,b.setValue(c),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange()}}),b.rows[c].movedown_button=this.getButton("","movedown","Move down"),b.rows[c].movedown_button.className+=" movedown",b.rows[c].movedown_button.setAttribute("data-i",c),b.rows[c].movedown_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i"),c=b.getValue();if(!(a>=c.length-1)){var d=c[a+1];c[a+1]=c[a],c[a]=d,b.setValue(c),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange()}});var e=b.rows[c].table_controls;e.appendChild(b.rows[c].delete_button),c&&e.appendChild(b.rows[c].moveup_button),e.appendChild(b.rows[c].movedown_button),a&&b.rows[c].setValue(a),b.jsoneditor.notifyWatchers(b.path)},addControls:function(){var a=this;this.collapsed=!1,this.toggle_button=this.getButton("","collapse","Collapse"),this.title_controls.appendChild(this.toggle_button),this.toggle_button.addEventListener("click",function(b){b.preventDefault(),b.stopPropagation(),a.collapsed?(a.collapsed=!1,a.panel.style.display="",a.setButtonText(this,"","collapse","Collapse")):(a.collapsed=!0,a.panel.style.display="none",a.setButtonText(this,"","expand","Expand"))}),this.options.collapsed&&e(this.toggle_button,"click"),this.schema.options&&"undefined"!=typeof this.schema.options.disable_collapse?this.schema.options.disable_collapse&&(this.toggle_button.style.display="none"):this.jsoneditor.options.disable_collapse&&(this.toggle_button.style.display="none"),this.add_row_button=this.getButton(this.getItemTitle(),"add","Add "+this.getItemTitle()),this.add_row_button.addEventListener("click",function(b){b.preventDefault(),b.stopPropagation(),a.addRow(),a.refreshValue(),a.refreshRowButtons(),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange()}),a.controls.appendChild(this.add_row_button),this.delete_last_row_button=this.getButton("Last "+this.getItemTitle(),"delete","Delete Last "+this.getItemTitle()),this.delete_last_row_button.addEventListener("click",function(b){b.preventDefault(),b.stopPropagation();var c=a.getValue();c.pop(),a.setValue(c),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange()}),a.controls.appendChild(this.delete_last_row_button),this.remove_all_rows_button=this.getButton("All","delete","Delete All"),this.remove_all_rows_button.addEventListener("click",function(b){b.preventDefault(),b.stopPropagation(),a.setValue([]),a.parent?a.parent.onChildEditorChange(a):a.jsoneditor.onChange()}),a.controls.appendChild(this.remove_all_rows_button)}}),g.defaults.editors.multiple=g.AbstractEditor.extend({getDefault:function(){return this.schema.default||null},register:function(){if(this.editors){for(var a=0;anull";if("object"==typeof a){var c="";return d(a,function(d,e){var f=b.getHTML(e);a instanceof Array||(f="
"+d+": "+f+"
"),c+="
  • "+f+"
  • "}),c=a instanceof Array?"
      "+c+"
    ":"
      "+c+"
    "}return"boolean"==typeof a?a?"true":"false":"string"==typeof a?a.replace(/&/g,"&").replace(//g,">"):a},setValue:function(a){this.value!==a&&(this.value=a,this.refreshValue(),this.jsoneditor.notifyWatchers(this.path))},destroy:function(){this.display_area.parentNode.removeChild(this.display_area),this.title.parentNode.removeChild(this.title),this.switcher.parentNode.removeChild(this.switcher),this._super()}}),g.defaults.editors.select=g.AbstractEditor.extend({getDefault:function(){return this.schema.default||""},setValue:function(a){a=this.typecast(a||"");var b=a;this.enum_values.indexOf(b)<0&&(b=this.enum_values[0]),this.value!==b&&(this.input.value=this.enum_options[this.enum_values.indexOf(b)],this.value=b,this.jsoneditor.notifyWatchers(this.path))},getNumColumns:function(){for(var a=this.getTitle().length,b=0;b2&&$(this.input).select2(),a.theme.afterInputReady(a.input),this.jsoneditor.notifyWatchers(this.path)},enable:function(){this.always_disabled||(this.input.disabled=!1),this._super()},disable:function(){this.input.disabled=!0,this._super()},destroy:function(){this.label&&this.label.parentNode.removeChild(this.label),this.description&&this.description.parentNode.removeChild(this.description),this.input.parentNode.removeChild(this.input),this._super()}}),g.AbstractTheme=a.extend({getContainer:function(){return document.createElement("div")},getFloatRightLinkHolder:function(){var a=document.createElement("div");return a.style=a.style||{},a.style.float="right",a.style["margin-left"]="10px",a},getModal:function(){var a=document.createElement("div");return a.style.backgroundColor="white",a.style.border="1px solid black",a.style.boxShadow="3px 3px black",a.style.position="absolute",a.style.zIndex="10",a.style.display="none",a},getGridContainer:function(){var a=document.createElement("div");return a},getGridRow:function(){var a=document.createElement("div");return a.className="row",a},getGridColumn:function(){var a=document.createElement("div");return a},setGridColumnSize:function(){},getLink:function(a){var b=document.createElement("a");return b.setAttribute("href","#"),b.appendChild(document.createTextNode(a)),b},disableHeader:function(a){a.style.color="#ccc"},disableLabel:function(a){a.style.color="#ccc"},enableHeader:function(a){a.style.color=""},enableLabel:function(a){a.style.color=""},getFormInputLabel:function(a){var b=document.createElement("label");return b.appendChild(document.createTextNode(a)),b},getCheckboxLabel:function(a){return this.getFormInputLabel(a)},getHeader:function(a){var b=document.createElement("h3");return"string"==typeof a?b.textContent=a:b.appendChild(a),b},getCheckbox:function(){var a=this.getFormInputField("checkbox");return a.style.marginRight="5px",a},getSelectInput:function(a){var b=document.createElement("select");return a&&this.setSelectOptions(b,a),b},getSwitcher:function(a){var b=this.getSelectInput(a);return b.style.backgroundColor="transparent",b.style.height="auto",b.style.fontStyle="italic",b.style.fontWeight="normal",b.style.padding="0 0 0 3px",b},getSwitcherOptions:function(a){return a.getElementsByTagName("option")},setSwitcherOptions:function(a,b,c){this.setSelectOptions(a,b,c)},setSelectOptions:function(a,b,c){c=c||[],a.innerHTML="";for(var d=0;d'),a.errmsg=a.parentNode.getElementsByClassName("errormsg")[0]),a.errmsg.textContent=b) },removeInputError:function(a){a.errmsg&&(a.errmsg.style.display="none")}}),g.defaults.themes.foundation3=g.defaults.themes.foundation.extend({getHeaderButtonHolder:function(){var a=this._super();return a.style.fontSize=".6em",a},getFormInputLabel:function(a){var b=this._super(a);return b.style.fontWeight="bold",b},getTabHolder:function(){var a=document.createElement("div");return a.className="row",a.innerHTML="
    ",a},setGridColumnSize:function(a,b){var c=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"];a.className="columns "+c[b]},getTab:function(a){var b=document.createElement("dd"),c=document.createElement("a");return c.setAttribute("href","#"),c.appendChild(a),b.appendChild(c),b},getTabContentHolder:function(a){return a.children[1]},getTabContent:function(){var a=document.createElement("div");return a.className="content active",a.style.paddingLeft="5px",a},markTabActive:function(a){a.className+=" active"},markTabInactive:function(a){a.className=a.className.replace(/\s*active/g,"")},addTab:function(a,b){a.children[0].appendChild(b)}}),g.defaults.themes.foundation4=g.defaults.themes.foundation.extend({getHeaderButtonHolder:function(){var a=this._super();return a.style.fontSize=".6em",a},setGridColumnSize:function(a,b){a.className="columns large-"+b},getFormInputDescription:function(a){var b=this._super(a);return b.style.fontSize=".8rem",b},getFormInputLabel:function(a){var b=this._super(a);return b.style.fontWeight="bold",b}}),g.defaults.themes.foundation5=g.defaults.themes.foundation.extend({getFormInputDescription:function(a){var b=this._super(a);return b.style.fontSize=".8rem",b},setGridColumnSize:function(a,b){a.className="columns medium-"+b},getButton:function(a,b,c){var d=this._super(a,b,c);return d.className=d.className.replace(/\s*small/g,"")+" tiny",d},getTabHolder:function(){var a=document.createElement("div");return a.innerHTML="
    ",a},getTab:function(a){var b=document.createElement("dd"),c=document.createElement("a");return c.setAttribute("href","#"),c.appendChild(a),b.appendChild(c),b},getTabContentHolder:function(a){return a.children[1]},getTabContent:function(){var a=document.createElement("div");return a.className="content active",a.style.paddingLeft="5px",a},markTabActive:function(a){a.className+=" active"},markTabInactive:function(a){a.className=a.className.replace(/\s*active/g,"")},addTab:function(a,b){a.children[0].appendChild(b)}}),g.defaults.themes.html=g.AbstractTheme.extend({getFormInputLabel:function(a){var b=this._super(a);return b.style.display="block",b.style.marginBottom="3px",b.style.fontWeight="bold",b},getFormInputDescription:function(a){var b=this._super(a);return b.style.fontSize=".8em",b.style.margin=0,b.style.display="inline-block",b.style.fontStyle="italic",b},getIndentedPanel:function(){var a=this._super();return a.style.border="1px solid #ddd",a.style.padding="5px",a.style.margin="5px",a.style.borderRadius="3px",a},getChildEditorHolder:function(){var a=this._super();return a.style.marginBottom="8px",a},getHeaderButtonHolder:function(){var a=this.getButtonHolder();return a.style.display="inline-block",a.style.marginLeft="10px",a.style.fontSize=".8em",a.style.verticalAlign="middle",a},getTable:function(){var a=this._super();return a.style.borderBottom="1px solid #ccc",a.style.marginBottom="5px",a},addInputError:function(a,b){if(a.style.borderColor="red",a.errmsg)a.errmsg.style.display="block";else{var c=this.closest(a,".form-control");a.errmsg=document.createElement("div"),a.errmsg.setAttribute("class","errmsg"),a.errmsg.style=a.errmsg.style||{},a.errmsg.style.color="red",c.appendChild(a.errmsg)}a.errmsg.innerHTML="",a.errmsg.appendChild(document.createTextNode(b))},removeInputError:function(a){a.style.borderColor="",a.errmsg&&(a.errmsg.style.display="none")}}),g.defaults.themes.jqueryui=g.AbstractTheme.extend({getTable:function(){var a=this._super();return a.setAttribute("cellpadding",5),a.setAttribute("cellspacing",0),a},getTableHeaderCell:function(a){var b=this._super(a);return b.className="ui-state-active",b.style.fontWeight="bold",b},getTableCell:function(){var a=this._super();return a.className="ui-widget-content",a},getHeaderButtonHolder:function(){var a=this.getButtonHolder();return a.style.marginLeft="10px",a.style.fontSize=".6em",a.style.display="inline-block",a},getFormInputDescription:function(a){var b=this.getDescription(a);return b.style.marginLeft="10px",b.style.display="inline-block",b},getFormControl:function(a,b,c){var d=this._super(a,b,c);return"checkbox"===b.type?(d.style.lineHeight="25px",d.style.padding="3px 0"):d.style.padding="4px 0 8px 0",d},getDescription:function(a){var b=document.createElement("span");return b.style.fontSize=".8em",b.style.fontStyle="italic",b.textContent=a,b},getButtonHolder:function(){var a=document.createElement("div");return a.className="ui-buttonset",a.style.fontSize=".7em",a},getFormInputLabel:function(a){var b=document.createElement("label");return b.style.fontWeight="bold",b.style.display="block",b.textContent=a,b},getButton:function(a,b,c){var d=document.createElement("button");d.className="ui-button ui-widget ui-state-default ui-corner-all",b&&!a?(d.className+=" ui-button-icon-only",b.className+=" ui-button-icon-primary ui-icon-primary",d.appendChild(b)):b?(d.className+=" ui-button-text-icon-primary",b.className+=" ui-button-icon-primary ui-icon-primary",d.appendChild(b)):d.className+=" ui-button-text-only";var e=document.createElement("span");return e.className="ui-button-text",e.textContent=a||c||".",d.appendChild(e),d.setAttribute("title",c),d},setButtonText:function(a,b,c,d){a.innerHTML="",a.className="ui-button ui-widget ui-state-default ui-corner-all",c&&!b?(a.className+=" ui-button-icon-only",c.className+=" ui-button-icon-primary ui-icon-primary",a.appendChild(c)):c?(a.className+=" ui-button-text-icon-primary",c.className+=" ui-button-icon-primary ui-icon-primary",a.appendChild(c)):a.className+=" ui-button-text-only";var e=document.createElement("span");e.className="ui-button-text",e.textContent=b||d||".",a.appendChild(e),a.setAttribute("title",d)},getIndentedPanel:function(){var a=document.createElement("div");return a.className="ui-widget-content ui-corner-all",a.style.padding="1em 1.4em",a.style.marginBottom="20px",a},afterInputReady:function(a){a.controls||(a.controls=this.closest(a,".form-control"))},addInputError:function(a,b){a.controls&&(a.errmsg?a.errmsg.style.display="":(a.errmsg=document.createElement("div"),a.errmsg.className="ui-state-error",a.controls.appendChild(a.errmsg)),a.errmsg.textContent=b)},removeInputError:function(a){a.errmsg&&(a.errmsg.style.display="none")},markTabActive:function(a){a.className=a.className.replace(/\s*ui-widget-header/g,"")+" ui-state-active"},markTabInactive:function(a){a.className=a.className.replace(/\s*ui-state-active/g,"")+" ui-widget-header"}}),g.AbstractIconLib=a.extend({mapping:{collapse:"",expand:"","delete":"",edit:"",add:"",cancel:"",save:"",moveup:"",movedown:""},icon_prefix:"",getIconClass:function(a){return this.mapping[a]?this.icon_prefix+this.mapping[a]:null},getIcon:function(a){var b=this.getIconClass(a);if(!b)return null;var c=document.createElement("i");return c.className=b,c}}),g.defaults.iconlibs.bootstrap2=g.AbstractIconLib.extend({mapping:{collapse:"chevron-down",expand:"chevron-up","delete":"trash",edit:"pencil",add:"plus",cancel:"ban-circle",save:"ok",moveup:"arrow-up",movedown:"arrow-down"},icon_prefix:"icon-"}),g.defaults.iconlibs.bootstrap3=g.AbstractIconLib.extend({mapping:{collapse:"chevron-down",expand:"chevron-right","delete":"remove",edit:"pencil",add:"plus",cancel:"floppy-remove",save:"floppy-saved",moveup:"arrow-up",movedown:"arrow-down"},icon_prefix:"glyphicon glyphicon-"}),g.defaults.iconlibs.fontawesome3=g.AbstractIconLib.extend({mapping:{collapse:"chevron-down",expand:"chevron-right","delete":"remove",edit:"pencil",add:"plus",cancel:"ban-circle",save:"save",moveup:"arrow-up",movedown:"arrow-down"},icon_prefix:"icon-"}),g.defaults.iconlibs.fontawesome4=g.AbstractIconLib.extend({mapping:{collapse:"caret-square-o-down",expand:"caret-square-o-right","delete":"times",edit:"pencil",add:"plus",cancel:"ban",save:"save",moveup:"arrow-up",movedown:"arrow-down"},icon_prefix:"fa fa-"}),g.defaults.iconlibs.foundation2=g.AbstractIconLib.extend({mapping:{collapse:"minus",expand:"plus","delete":"remove",edit:"edit",add:"add-doc",cancel:"error",save:"checkmark",moveup:"up-arrow",movedown:"down-arrow"},icon_prefix:"foundicon-"}),g.defaults.iconlibs.foundation3=g.AbstractIconLib.extend({mapping:{collapse:"minus",expand:"plus","delete":"x",edit:"pencil",add:"page-add",cancel:"x-circle",save:"save",moveup:"arrow-up",movedown:"arrow-down"},icon_prefix:"fi-"}),g.defaults.iconlibs.jqueryui=g.AbstractIconLib.extend({mapping:{collapse:"triangle-1-s",expand:"triangle-1-e","delete":"trash",edit:"pencil",add:"plusthick",cancel:"closethick",save:"disk",moveup:"arrowthick-1-n",movedown:"arrowthick-1-s"},icon_prefix:"ui-icon ui-icon-"}),g.defaults.templates.default=function(){var a=function(b){var e={};return d(b,function(b,f){if("object"==typeof f&&null!==f){var g={};d(f,function(a,c){g[b+"."+a]=c}),c(e,a(g))}else e[b]=f}),e};return{compile:function(b){return function(c){var e=a(c),f=b+"";return d(e,function(a,b){f=f.replace(new RegExp("{{\\s*"+a+"\\s*}}","g"),b)}),f}}}},g.defaults.templates.ejs=function(){return window.EJS?{compile:function(a){var b=new EJS({text:a});return function(a){return b.render(a)}}}:!1},g.defaults.templates.handlebars=function(){return window.Handlebars},g.defaults.templates.hogan=function(){return window.Hogan?{compile:function(a){var b=Hogan.compile(a);return function(a){return b.render(a)}}}:!1},g.defaults.templates.markup=function(){return window.Mark&&window.Mark.up?{compile:function(a){return function(b){return Mark.up(a,b)}}}:!1},g.defaults.templates.mustache=function(){return window.Mustache?{compile:function(a){return function(b){return Mustache.render(a,b)}}}:!1},g.defaults.templates.swig=function(){return window.swig},g.defaults.templates.underscore=function(){return window._?{compile:function(a){return function(b){return _.template(a,b)}}}:!1},g.defaults.theme="html",g.defaults.template="default",g.defaults.options={},g.plugins={ace:{theme:""},epiceditor:{}};for(var h in g.defaults.editors)g.defaults.editors.hasOwnProperty(h)&&(g.defaults.editors[h].options=g.defaults.editors.options||{});g.defaults.resolvers.unshift(function(a){return"string"!=typeof a.type?"multiple":void 0}),g.defaults.resolvers.unshift(function(a){return"string"==typeof a.type?a.type:void 0}),g.defaults.resolvers.unshift(function(a){return"boolean"===a.type?"select":void 0}),g.defaults.resolvers.unshift(function(a){return"any"===a.type?"multiple":void 0}),g.defaults.resolvers.unshift(function(a){return"array"==a.type&&"table"==a.format?"table":void 0}),g.defaults.resolvers.unshift(function(a){if(a.enum){if("array"===a.type||"object"===a.type)return"enum";if("number"===a.type||"integer"===a.type||"string"===a.type)return"select"}}),g.defaults.resolvers.unshift(function(a){return a.oneOf?"multiple":void 0}),(window.jQuery||window.Zepto)&&(window.$=window.$||{},$.jsoneditor=g.defaults,(window.jQuery||window.Zepto).fn.jsoneditor=function(a){var b=this,c=this.data("jsoneditor");if("value"===a){if(!c)throw"Must initialize jsoneditor before getting/setting the value";if(!(arguments.length>1))return c.getValue();c.setValue(arguments[1])}else{if("validate"===a){if(!c)throw"Must initialize jsoneditor before validating";return arguments.length>1?c.validate(arguments[1]):c.validate()}"destroy"===a?c&&(c.destroy(),this.data("jsoneditor",null)):(c&&c.destroy(),c=new g(this.get(0),a),this.data("jsoneditor",c),c.on("change",function(){b.trigger("change")}),c.on("ready",function(){b.trigger("ready")}))}return this}),window.JSONEditor=g}(); \ No newline at end of file diff --git a/src/editors/string.js b/src/editors/string.js index 870f7660b..333d96dfb 100644 --- a/src/editors/string.js +++ b/src/editors/string.js @@ -353,19 +353,18 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({ clientSideStorage: false }); - this.epiceditor = new EpicEditor(options); + this.epiceditor = new EpicEditor(options).load(); this.epiceditor.importFile(null,this.getValue()); this.epiceditor.on('update',function() { var val = self.epiceditor.exportFile(); self.input.value = val; + self.value = val; if(self.parent) self.parent.onChildEditorChange(self); else self.jsoneditor.onChange(); self.jsoneditor.notifyWatchers(self.path); }); - - this.epiceditor.load(); } // ACE editor for everything else else if(window.ace) { diff --git a/src/intro.js b/src/intro.js index fad769e38..bc93e1f4a 100644 --- a/src/intro.js +++ b/src/intro.js @@ -1,4 +1,4 @@ -/*! JSON Editor v0.6.3 - JSON Schema -> HTML Editor +/*! JSON Editor v0.6.4 - JSON Schema -> HTML Editor * By Jeremy Dorn - https://github.com/jdorn/json-editor/ * Released under the MIT license *