diff --git a/dist/jsoneditor.js b/dist/jsoneditor.js index f8a46670f..d9879d3a0 100644 --- a/dist/jsoneditor.js +++ b/dist/jsoneditor.js @@ -210,6 +210,7 @@ JSONEditor.prototype = { this.schema = this.options.schema; this.theme = new theme_class(); this.template = this.options.template; + this.refs = this.options.refs || {}; this.uuid = 0; this.__data = {}; @@ -221,18 +222,10 @@ JSONEditor.prototype = { this.translate = this.options.translate || JSONEditor.defaults.translate; - this.validator = new JSONEditor.Validator(this.schema,{ - ajax: this.options.ajax, - refs: this.options.refs, - no_additional_properties: this.options.no_additional_properties, - required_by_default: this.options.required_by_default, - translate: this.translate - }); - - this.validator.ready(function(expanded) { - if(self.ready) return; - - self.schema = expanded; + // Fetch all external refs via ajax + this._loadExternalRefs(this.schema, function() { + self._getDefinitions(self.schema); + self.validator = new JSONEditor.Validator(self); // Create the root editor var editor_class = self.getEditorClass(self.schema); @@ -472,201 +465,313 @@ JSONEditor.prototype = { }, disable: function() { this.root.disable(); - } -}; - -JSONEditor.defaults = { - themes: {}, - templates: {}, - iconlibs: {}, - editors: {}, - languages: {}, - resolvers: [], - custom_validators: [] -}; - -JSONEditor.Validator = Class.extend({ - init: function(schema, options) { - this.original_schema = schema; - this.options = options || {}; - this.refs = this.options.refs || {}; - - this.ready_callbacks = []; - this.translate = this.options.translate || JSONEditor.defaults.translate; - - if(this.options.ready) this.ready(this.options.ready); - // Store any $ref and definitions - this.getRefs(); }, - ready: function(callback) { - if(this.is_ready) callback.apply(this,[this.expanded]); - else { - this.ready_callbacks.push(callback); + _getDefinitions: function(schema,path) { + path = path || '#/definitions/'; + if(schema.definitions) { + for(var i in schema.definitions) { + if(!schema.definitions.hasOwnProperty(i)) continue; + this.refs[path+i] = schema.definitions[i]; + if(schema.definitions[i].definitions) { + this._getDefinitions(schema.definitions[i],path+i+'/definitions/'); + } + } } - - return this; }, - getRefs: function() { + _getExternalRefs: function(schema) { + var refs = {}; + var merge_refs = function(newrefs) { + for(var i in newrefs) { + if(newrefs.hasOwnProperty(i)) { + refs[i] = true; + } + } + }; + + if(schema.$ref && schema.$ref.substr(0,1) !== "#" && !this.refs[schema.$ref]) { + refs[schema.$ref] = true; + } + + for(var i in schema) { + if(!schema.hasOwnProperty(i)) continue; + if(schema[i] && typeof schema[i] === "object" && Array.isArray(schema[i])) { + for(var j=0; j= waiting && !callback_fired) { + callback_fired = true; + callback(); + } + }); + } + // Request failed + else { + console.log(r); + throw "Failed to fetch ref via ajax- "+url; + } + }; + r.send(); }); + + if(!waiting) { + callback(); + } }, - _getRefs: function(schema,callback,path,in_definitions) { + expandRefs: function(schema) { + if(schema.$ref) { + schema = this.extendSchemas(schema,this.refs[schema.$ref]); + } + return schema; + }, + expandSchema: function(schema) { var self = this; - var is_root = schema === this.original_schema; - path = path || "#"; - - var waiting, finished, check_if_finished, called; - - // Work on a deep copy of the schema - schema = $extend({},schema); + var extended = schema; + var i; - // First expand out any definition in the root node - if(schema.definitions && (is_root || in_definitions)) { - var defs = schema.definitions; - delete schema.definitions; - - waiting = finished = 0; - check_if_finished = function(schema) { - if(finished >= waiting) { - if(called) return; - called = true; - self._getRefs(schema,callback,path); + // Version 3 `type` + if(typeof schema.type === 'object') { + // Array of types + if(Array.isArray(schema.type)) { + $each(schema.type, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.type[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.type = self.expandSchema(schema.type); + } + } + // Version 3 `disallow` + if(typeof schema.disallow === 'object') { + // Array of types + if(Array.isArray(schema.disallow)) { + $each(schema.disallow, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.disallow[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.disallow = self.expandSchema(schema.disallow); + } + } + // Version 4 `anyOf` + if(schema.anyOf) { + $each(schema.anyOf, function(key,value) { + schema.anyOf[key] = self.expandSchema(value); + }); + } + // Version 4 `dependencies` (schema dependencies) + if(schema.dependencies) { + $each(schema.dependencies,function(key,value) { + if(typeof value === "object" && !(Array.isArray(value))) { + schema.dependencies[key] = self.expandSchema(value); } - }; - - $each(defs,function() { - waiting++; }); - - if(waiting) { - $each(defs,function(i,definition) { - // Expand the definition recursively - self._getRefs(definition,function(def_schema) { - self.refs[path+'/definitions/'+i] = def_schema; - finished++; - check_if_finished(schema); - },path+'/definitions/'+i,true); + } + // `items` + if(schema.items) { + // Array of items + if(Array.isArray(schema.items)) { + $each(schema.items, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.items[key] = self.expandSchema(value); + } }); } + // Schema else { - check_if_finished(schema); + schema.items = self.expandSchema(schema.items); } } - // Expand out any references - else if(schema.$ref) { - var ref = schema.$ref; - delete schema.$ref; + // `properties` + if(schema.properties) { + $each(schema.properties,function(key,value) { + if(typeof value === "object" && !(Array.isArray(value))) { + schema.properties[key] = self.expandSchema(value); + } + }); + } + // `patternProperties` + if(schema.patternProperties) { + $each(schema.patternProperties,function(key,value) { + if(typeof value === "object" && !(Array.isArray(value))) { + schema.patternProperties[key] = self.expandSchema(value); + } + }); + } + // Version 4 `not` + if(schema.not) { + schema.not = this.expandSchema(schema.not); + } + // `additionalProperties` + if(schema.additionalProperties && typeof schema.additionalProperties === "object") { + schema.additionalProperties = self.expandSchema(schema.additionalProperties); + } + // `additionalItems` + if(schema.additionalItems && typeof schema.additionalItems === "object") { + schema.additionalItems = self.expandSchema(schema.additionalItems); + } - // If we're currently loading this external reference, wait for it to be done - if(self.refs[ref] && Array.isArray(self.refs[ref])) { - self.refs[ref].push(function() { - schema = $extend({},self.refs[ref],schema); - callback(schema); - }); + // allOf schemas should be merged into the parent + if(schema.allOf) { + for(i=0; i= waiting) { - if(called) return; - called = true; + // parent should be merged into oneOf schemas + if(schema.oneOf) { + var tmp = $extend({},extended); + delete tmp.oneOf; + for(i=0; i=i){if(l)return;l=!0,g._getRefs(a,d,e)}},c(m,function(){i++}),i?c(m,function(b,c){g._getRefs(c,function(c){g.refs[e+"/definitions/"+b]=c,j++,k(a)},e+"/definitions/"+b,!0)}):k(a)}else if(a.$ref){var n=a.$ref;if(delete a.$ref,g.refs[n]&&Array.isArray(g.refs[n]))g.refs[n].push(function(){a=b({},g.refs[n],a),d(a)});else if(g.refs[n])a=b({},g.refs[n],a),d(a);else{if(!g.options.ajax)throw"Must set ajax option to true to load external url "+n;var o=new XMLHttpRequest;o.open("GET",n,!0),o.onreadystatechange=function(){if(4==o.readyState){if(200===o.status){var f=JSON.parse(o.responseText);return g.refs[n]=[],void g._getRefs(f,function(e){var f=g.refs[n];g.refs[n]=e,a=b({},g.refs[n],a),d(a),c(f,function(a,b){b()})},e)}throw"Failed to fetch ref via ajax- "+n}},o.send()}}else i=j=0,k=function(a){if(j>=i){if(l)return;l=!0,d(a)}},c(a,function(a,b){"object"==typeof b&&b&&Array.isArray(b)?c(b,function(a,b){"object"==typeof b&&b&&!Array.isArray(b)&&i++}):"object"==typeof b&&b&&i++}),i?c(a,function(b,d){"object"==typeof d&&d&&Array.isArray(d)?c(d,function(c,d){"object"==typeof d&&d&&!Array.isArray(d)&&g._getRefs(d,function(d){a[b][c]=d,j++,k(a)},e+"/"+b+"/"+c)}):"object"==typeof d&&d&&g._getRefs(d,function(c){a[b]=c,j++,k(a)},e+"/"+b)}):k(a)},validate:function(a){return this._validateSchema(this.schema,a)},_validateSchema:function(a,d,e){var g,h,i,j=[],k=JSON.stringify(d);if(e=e||"root",a=b({},a),a.required&&a.required===!0){if("undefined"==typeof d)return j.push({path:e,property:"required",message:this.translate("error_notset")}),j}else if("undefined"==typeof d){if(!this.options.required_by_default)return j;j.push({path:e,property:"required",message:this.translate("error_notset")})}if(a.enum){for(g=!1,h=0;h=a.maximum?j.push({path:e,property:"maximum",message:this.translate("error_maximum_excl",[a.maximum])}):!a.exclusiveMaximum&&d>a.maximum&&j.push({path:e,property:"maximum",message:this.translate("error_maximum_incl",[a.maximum])})),a.minimum&&(a.exclusiveMinimum&&d<=a.minimum?j.push({path:e,property:"minimum",message:this.translate("error_minimum_excl",[a.minimum])}):!a.exclusiveMinimum&&da.maxLength&&j.push({path:e,property:"maxLength",message:this.translate("error_maxLength",[a.maxLength])}),a.minLength&&(d+"").lengtha.maxItems&&j.push({path:e,property:"maxItems",message:this.translate("error_maxItems",[a.maxItems])}),a.minItems&&d.lengtha.maxProperties&&j.push({path:e,property:"maxProperties",message:this.translate("error_maxProperties",[a.maxProperties])})}if(a.minProperties){g=0;for(h in d)d.hasOwnProperty(h)&&g++;g=0){b=this.theme.getBlockLinkHolder(),c=this.theme.getBlockLink(),c.setAttribute("target","_blank");var h=document.createElement(e);h.setAttribute("controls","controls"),this.theme.createMediaLink(b,c,h),this.link_watchers.push(function(b){var d=f(b);c.setAttribute("href",d),c.textContent=a.rel||d,h.setAttribute("src",d)})}else b=this.theme.getBlockLink(),b.setAttribute("target","_blank"),b.textContent=a.rel,this.link_watchers.push(function(c){var d=f(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(){var a;if(this.header_template){a=b(this.getWatchedFieldValues(),{key:this.key,i:this.key,title:this.getTitle()});var c=this.header_template(a);c!==this.header_text&&(this.header_text=c,this.updateHeaderText(),this.fireChangeHeaderEvent())}if(this.link_watchers.length){a=this.getWatchedFieldValues();for(var d=0;d1&&(b[a]=c+" "+e[c])}),b},showValidationErrors:function(){}}),f.defaults.editors.null=f.AbstractEditor.extend({getValue:function(){return null},setValue:function(){this.jsoneditor.notifyWatchers(this.path)},getNumColumns:function(){return 2}}),f.defaults.editors.string=f.AbstractEditor.extend({getDefault:function(){return this.schema.default||""},register:function(){this._super(),this.input&&this.input.setAttribute("name",this.formname)},unregister:function(){this._super(),this.input&&this.input.removeAttribute("name")},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,c=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.format&&this.options.default_format&&(this.format=this.options.default_format),this.options.format&&(this.format=this.options.format),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=[],Array.isArray(this.schema.enumSource))for(a=0;a=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(a){if(a.preventDefault(),a.stopPropagation(),c.schema.template)return void(this.value=c.value);var b=this.value,d=c.sanitize(b);b!==d&&(this.value=d),c.refreshValue(),c.watch_listener(),c.jsoneditor.notifyWatchers(c.path),c.parent?c.parent.onChildEditorChange(c):c.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(){c.input.parentNode&&c.afterInputReady()}),this.register(),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,c=this;if(this.source_code)if(this.options.wysiwyg&&["html","bbcode"].indexOf(this.input_type)>=0&&window.$&&$.fn&&$.fn.sceditor)a=b({},{plugins:"html"===c.input_type?"xhtml":"bbcode",emoticonsEnabled:!1,width:"100%",height:300},f.plugins.sceditor),$(c.input).sceditor(a),c.sceditor_instance=$(c.input).sceditor("instance"),c.sceditor_instance.blur(function(){var a=$("
"+c.sceditor_instance.val()+"
");$("#sceditor-start-marker,#sceditor-end-marker,.sceditor-nlf",a).remove(),c.input.value=a.html(),c.value=c.input.value,c.parent?c.parent.onChildEditorChange(c):c.jsoneditor.onChange(),c.jsoneditor.notifyWatchers(c.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",a=b({},f.plugins.epiceditor,{container:this.epiceditor_container,clientSideStorage:!1}),this.epiceditor=new EpicEditor(a).load(),this.epiceditor.importFile(null,this.getValue()),this.epiceditor.on("update",function(){var a=c.epiceditor.exportFile();c.input.value=a,c.value=a,c.parent?c.parent.onChildEditorChange(c):c.jsoneditor.onChange(),c.jsoneditor.notifyWatchers(c.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()),f.plugins.ace.theme&&this.ace_editor.setTheme("ace/theme/"+f.plugins.ace.theme),d=ace.require("ace/mode/"+d),d&&this.ace_editor.getSession().setMode(new d.Mode),this.ace_editor.on("change",function(){var a=c.ace_editor.getValue();c.input.value=a,c.refreshValue(),c.parent?c.parent.onChildEditorChange(c):c.jsoneditor.onChange(),c.jsoneditor.notifyWatchers(c.path)})}c.theme.afterInputReady(c.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&&this.input.parentNode.removeChild(this.input),this.label&&this.label.parentNode&&this.label.parentNode.removeChild(this.label),this.description&&this.description.parentNode&&this.description.parentNode.removeChild(this.description),this._super()},sanitize:function(a){return a},onWatchedFieldChange:function(){var a,b;if(this.template&&(a=this.getWatchedFieldValues(),this.setValue(this.template(a),!1,!0)),this.enumSource){a=this.getWatchedFieldValues();for(var c=[],d=[],e=0;ee)&&(c=g);c===!1&&(f.push({width:0,minh:999999,maxh:0,editors:[]}),c=f.length-1),f[c].editors.push({key:a,width:d,height:e}),f[c].width+=d,f[c].minh=Math.min(f[c].minh,e),f[c].maxh=Math.max(f[c].maxh,e)}}),a=0;af[a].editors[g].width&&(g=b),f[a].editors[b].width*=12/f[a].width,f[a].editors[b].width=Math.floor(f[a].editors[b].width),h+=f[a].editors[b].width;12>h&&(f[a].editors[g].width+=12-h),f[a].width=12}if(this.layout===JSON.stringify(f))return!1;for(this.layout=JSON.stringify(f),e=document.createElement("div"),a=0;a=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.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&&d(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()}var e={},f=Object.keys(this.editors);f=f.sort(function(b,c){var d=a.editors[b].schema.propertyOrder,e=a.editors[c].schema.propertyOrder;return"number"!=typeof d&&(d=1e3),"number"!=typeof e&&(e=1e3),d-e});for(var g=0;g=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(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 d=this;a=a||{},("object"!=typeof a||Array.isArray(a))&&(a={}),c(this.editors,function(c,e){if("undefined"!=typeof a[c])e.property_removed&&d.addObjectProperty(c),e.setValue(a[c],b);else{if(!b&&!e.property_removed&&!e.isRequired())return void d.removeObjectProperty(c);e.setValue(e.getDefault(),b)}}),this.canHaveAdditionalProperties()&&c(a,function(a,c){d.editors[a]||(d.addObjectProperty(a),d.editors[a]&&d.editors[a].setValue(c,b))}),this.refreshValue(),this.jsoneditor.notifyWatchers(this.path)},showValidationErrors:function(a){var b=this,d=[],e=[];if(c(a,function(a,c){c.path===b.path?d.push(c):e.push(c)}),this.error_holder)if(d.length){this.error_holder.innerHTML="",this.error_holder.style.display="",c(d,function(a,c){b.error_holder.appendChild(b.theme.getErrorMessage(c.message))})}else this.error_holder.style.display="none";this.getOption("table_row")&&(d.length?this.theme.addTableRowError(this.container):this.theme.removeTableRowError(this.container)),c(this.editors,function(a,b){b.showValidationErrors(e)})}}),f.defaults.editors.array=f.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?b({},this.schema.additionalItems):void 0:b({},this.schema.items[a]):this.schema.items?b({},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;c(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",a.unregister())},getMax:function(){return Array.isArray(this.schema.items)&&this.schema.additionalItems===!1?Math.min(this.schema.items.length,this.schema.maxItems||1/0):this.schema.maxItems||1/0},refreshTabs:function(a){var b=this;c(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,b){a=a||[],Array.isArray(a)||(a=[a]);var d=JSON.stringify(a);if(d!==this.serialized){if(this.schema.minItems)for(;a.lengththis.getMax()&&(a=a.slice(0,this.getMax()));var e=this;c(a,function(a,b){e.rows[a]?e.rows[a].setValue(b):e.row_cache[a]?(e.rows[a]=e.row_cache[a],e.rows[a].setValue(b),e.rows[a].container.style.display="",e.rows[a].tab&&(e.rows[a].tab.style.display=""),e.rows[a].register()):e.addRow(b)});for(var f=a.length;f=this.rows.length;c(this.rows,function(a,c){c.movedown_buttons&&(c.movedown_button.style.display=a===b.rows.length-1?"none":""),c.delete_button&&(c.delete_button.style.display=e?"none":""),b.value[a]=c.getValue()});var f=!1;this.value.length?1===this.value.length?(this.remove_all_rows_button.style.display="none",e||this.hide_delete_buttons?this.delete_last_row_button.style.display="none":(this.delete_last_row_button.style.display="",f=!0)):e||this.hide_delete_buttons?(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none"):(this.delete_last_row_button.style.display="",this.remove_all_rows_button.style.display="",f=!0):(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none"),this.getMax()&&this.getMax()<=this.rows.length||this.hide_add_button?this.add_row_button.style.display="none":(this.add_row_button.style.display="",f=!0),this.controls.style.display=!this.collapsed&&f?"":"none"}},addRow:function(a){var b=this,d=this.rows.length;b.rows[d]=this.getElementEditor(d),b.row_cache[d]=b.rows[d],b.tabs_holder&&(b.rows[d].tab_text=document.createElement("span"),b.rows[d].tab_text.textContent=b.rows[d].getHeaderText(),b.rows[d].tab=b.theme.getTab(b.rows[d].tab_text),b.rows[d].tab.addEventListener("click",function(a){b.active_tab=b.rows[d].tab,b.refreshTabs(),a.preventDefault(),a.stopPropagation()}),b.theme.addTab(b.tabs_holder,b.rows[d].tab));var e=b.rows[d].title_controls||b.rows[d].array_controls;b.hide_delete_buttons||(b.rows[d].delete_button=this.getButton(b.getItemTitle(),"delete","Delete "+b.getItemTitle()),b.rows[d].delete_button.className+=" delete",b.rows[d].delete_button.setAttribute("data-i",d),b.rows[d].delete_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i"),d=b.getValue(),e=[],f=null;c(d,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()}),e&&e.appendChild(b.rows[d].delete_button)),d&&!b.hide_move_buttons&&(b.rows[d].moveup_button=this.getButton("","moveup","Move up"),b.rows[d].moveup_button.className+=" moveup",b.rows[d].moveup_button.setAttribute("data-i",d),b.rows[d].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()}}),e&&e.appendChild(b.rows[d].moveup_button)),b.hide_move_buttons||(b.rows[d].movedown_button=this.getButton("","movedown","Move down"),b.rows[d].movedown_button.className+=" movedown",b.rows[d].movedown_button.setAttribute("data-i",d),b.rows[d].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()}}),e&&e.appendChild(b.rows[d].movedown_button)),a&&b.rows[d].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.panel&&(a.panel.style.display=""),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.panel&&(a.panel.style.display="none"),a.setButtonText(this,"","expand","Expand"))}),this.options.collapsed&&d(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.rows[b].register()):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,d=[],e=[];if(c(a,function(a,c){c.path===b.path?d.push(c):e.push(c)}),this.error_holder)if(d.length){this.error_holder.innerHTML="",this.error_holder.style.display="",c(d,function(a,c){b.error_holder.appendChild(b.theme.getErrorMessage(c.message))})}else this.error_holder.style.display="none";c(this.rows,function(a,b){b.showValidationErrors(e)})}}),f.defaults.editors.table=f.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 d=JSON.stringify(a);if(d!==this.serialized){var e=!1,f=this;c(a,function(a,b){f.rows[a]?f.rows[a].setValue(b):(f.addRow(b),e=!0)});for(var g=a.length;g=this.rows.length,d=!1;c(this.rows,function(c,e){e.movedown_button&&(c===a.rows.length-1?e.movedown_button.style.display="none":(d=!0,e.movedown_button.style.display="")),e.delete_button&&(b?e.delete_button.style.display="none":(d=!0,e.delete_button.style.display="")),e.moveup_button&&(d=!0)}),c(this.rows,function(a,b){b.controls_cell.style.display=d?"":"none"}),this.controls_header_cell.style.display=d?"":"none";var e=!1;this.value.length?1===this.value.length||this.hide_delete_buttons?(this.table.style.display="",this.remove_all_rows_button.style.display="none",b||this.hide_delete_buttons?this.delete_last_row_button.style.display="none":(this.delete_last_row_button.style.display="",e=!0)):(this.table.style.display="",b||this.hide_delete_buttons?(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none"):(this.delete_last_row_button.style.display="",this.remove_all_rows_button.style.display="",e=!0)):(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none",this.table.style.display="none"),this.schema.maxItems&&this.schema.maxItems<=this.rows.length||this.hide_add_button?this.add_row_button.style.display="none":(this.add_row_button.style.display="",e=!0),this.controls.style.display=e?"":"none"},refreshValue:function(){var a=this;this.value=[],c(this.rows,function(b,c){a.value[b]=c.getValue()}),this.serialized=JSON.stringify(this.value)},addRow:function(a){var b=this,d=this.rows.length;b.rows[d]=this.getElementEditor(d);var e=b.rows[d].table_controls;this.hide_delete_buttons||(b.rows[d].delete_button=this.getButton("","delete","Delete"),b.rows[d].delete_button.className+=" delete",b.rows[d].delete_button.setAttribute("data-i",d),b.rows[d].delete_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i"),d=b.getValue(),e=[];c(d,function(b,c){b!==a&&e.push(c)}),b.setValue(e),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange()}),e.appendChild(b.rows[d].delete_button)),d&&!this.hide_move_buttons&&(b.rows[d].moveup_button=this.getButton("","moveup","Move up"),b.rows[d].moveup_button.className+=" moveup",b.rows[d].moveup_button.setAttribute("data-i",d),b.rows[d].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()}}),e.appendChild(b.rows[d].moveup_button)),this.hide_move_buttons||(b.rows[d].movedown_button=this.getButton("","movedown","Move down"),b.rows[d].movedown_button.className+=" movedown",b.rows[d].movedown_button.setAttribute("data-i",d),b.rows[d].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()}}),e.appendChild(b.rows[d].movedown_button)),a&&b.rows[d].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&&d(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)}}),f.defaults.editors.multiple=f.AbstractEditor.extend({getDefault:function(){return this.schema.default||null},register:function(){if(this.editors){for(var a=0;anull";if("object"==typeof a){var d="";return c(a,function(c,e){var f=b.getHTML(e);Array.isArray(a)||(f="
"+c+": "+f+"
"),d+="
  • "+f+"
  • "}),d=Array.isArray(a)?"
      "+d+"
    ":"
      "+d+"
    "}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()}}),f.defaults.editors.select=f.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))},register:function(){this._super(),this.input&&this.input.setAttribute("name",this.formname)},unregister:function(){this._super(),this.input&&this.input.removeAttribute("name")},getNumColumns:function(){for(var a=this.getTitle().length,b=0;b2&&$(this.input).select2(),this.register(),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()}}),f.defaults.editors.multiselect=f.AbstractEditor.extend({getDefault:function(){return[]},build:function(){var a,b=this;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.select_options={},this.select_values={};var c=this.schema.items.enum||[],d=[];for(a=0;aType: "+a+", Size: "+Math.floor((this.value.length-this.value.split(",")[0].length-1)/1.33333)+" bytes","image"===a.substr(0,5)){this.preview.innerHTML+="
    ";var b=document.createElement("img");b.style.maxWidth="100%",b.style.maxHeight="100px",b.src=this.value,this.preview.appendChild(b)}}else this.preview.innerHTML="Invalid data URI"}},enable:function(){this.uploader&&(this.uploader.disabled=!1),this._super()},disable:function(){this.uploader&&(this.uploader.disabled=!0),this._super()},setValue:function(a){this.value!==a&&(this.value=a,this.input.value=this.value,this.refreshPreview(),this.watch_listener(),this.jsoneditor.notifyWatchers(this.path))},destroy:function(){this.preview.parentNode.removeChild(this.preview),this.title.parentNode.removeChild(this.title),this.input.parentNode.removeChild(this.input),this.uploader&&this.uploader.parentNode.removeChild(this.uploader),this._super()}}),f.AbstractTheme=Class.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){var b=this.getFormInputLabel(a);return b.style.fontWeight="normal",b},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.display="inline-block",a.style.width="auto",a},getMultiCheckboxHolder:function(a,b,c){var d=document.createElement("div");b&&(b.style.display="block",d.appendChild(b));for(var e in a)a.hasOwnProperty(e)&&(a[e].style.display="inline-block",a[e].style.marginRight="20px",d.appendChild(a[e]));return c&&d.appendChild(c),d},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.group.className=a.group.className.replace(/ error/g,""),a.errmsg.style.display="none")}}),f.defaults.themes.foundation3=f.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)}}),f.defaults.themes.foundation4=f.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}}),f.defaults.themes.foundation5=f.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)}}),f.defaults.themes.html=f.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")}}),f.defaults.themes.jqueryui=f.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"}}),f.AbstractIconLib=Class.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}}),f.defaults.iconlibs.bootstrap2=f.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-"}),f.defaults.iconlibs.bootstrap3=f.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-"}),f.defaults.iconlibs.fontawesome3=f.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-"}),f.defaults.iconlibs.fontawesome4=f.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-"}),f.defaults.iconlibs.foundation2=f.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-"}),f.defaults.iconlibs.foundation3=f.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-"}),f.defaults.iconlibs.jqueryui=f.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-"}),f.defaults.templates.default=function(){var a=function(d){var e={};return c(d,function(d,f){if("object"==typeof f&&null!==f){var g={};c(f,function(a,b){g[d+"."+a]=b}),b(e,a(g))}else e[d]=f}),e};return{compile:function(b){return function(d){var e=a(d),f=b+"";return c(e,function(a,b){f=f.replace(new RegExp("{{\\s*"+a+"\\s*}}","g"),b)}),f}}}},f.defaults.templates.ejs=function(){return window.EJS?{compile:function(a){var b=new EJS({text:a});return function(a){return b.render(a)}}}:!1},f.defaults.templates.handlebars=function(){return window.Handlebars},f.defaults.templates.hogan=function(){return window.Hogan?{compile:function(a){var b=Hogan.compile(a);return function(a){return b.render(a)}}}:!1},f.defaults.templates.markup=function(){return window.Mark&&window.Mark.up?{compile:function(a){return function(b){return Mark.up(a,b)}}}:!1},f.defaults.templates.mustache=function(){return window.Mustache?{compile:function(a){return function(b){return Mustache.render(a,b)}}}:!1},f.defaults.templates.swig=function(){return window.swig},f.defaults.templates.underscore=function(){return window._?{compile:function(a){return function(b){return _.template(a,b)}}}:!1},f.defaults.theme="html",f.defaults.template="default",f.defaults.options={},f.defaults.translate=function(a,b){var c=f.defaults.languages[f.defaults.language];if(!c)throw"Unknown language "+f.defaults.language;var d=c[a]||f.defaults.languages[f.defaults.default_language][a];if("undefined"==typeof d)throw"Unknown translate string "+a;if(b)for(var e=0;e=0?"multiselect":void 0}),f.defaults.resolvers.unshift(function(a){return a.oneOf?"multiple":void 0}),(window.jQuery||window.Zepto)&&(window.$=window.$||{},$.jsoneditor=f.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 f(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=f}(); \ No newline at end of file +!function(){!function(){var a=!1,b=/xyz/.test(function(){postMessage("xyz")})?/\b_super\b/:/.*/;this.Class=function(){},Class.extend=function(c){function d(){!a&&this.init&&this.init.apply(this,arguments)}var e=this.prototype;a=!0;var f=new this;a=!1;for(var g in c)f[g]="function"==typeof c[g]&&"function"==typeof e[g]&&b.test(c[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,c[g]):c[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=g&&!h&&(h=!0,b())})}},c.send()}}),g||b()},expandRefs:function(a){return a.$ref&&(a=this.extendSchemas(a,this.refs[a.$ref])),a},expandSchema:function(a){var d,e=this,f=a;if("object"==typeof a.type&&(Array.isArray(a.type)?c(a.type,function(b,c){"object"==typeof c&&(a.type[b]=e.expandSchema(c))}):a.type=e.expandSchema(a.type)),"object"==typeof a.disallow&&(Array.isArray(a.disallow)?c(a.disallow,function(b,c){"object"==typeof c&&(a.disallow[b]=e.expandSchema(c))}):a.disallow=e.expandSchema(a.disallow)),a.anyOf&&c(a.anyOf,function(b,c){a.anyOf[b]=e.expandSchema(c)}),a.dependencies&&c(a.dependencies,function(b,c){"object"!=typeof c||Array.isArray(c)||(a.dependencies[b]=e.expandSchema(c))}),a.items&&(Array.isArray(a.items)?c(a.items,function(b,c){"object"==typeof c&&(a.items[b]=e.expandSchema(c))}):a.items=e.expandSchema(a.items)),a.properties&&c(a.properties,function(b,c){"object"!=typeof c||Array.isArray(c)||(a.properties[b]=e.expandSchema(c))}),a.patternProperties&&c(a.patternProperties,function(b,c){"object"!=typeof c||Array.isArray(c)||(a.patternProperties[b]=e.expandSchema(c))}),a.not&&(a.not=this.expandSchema(a.not)),a.additionalProperties&&"object"==typeof a.additionalProperties&&(a.additionalProperties=e.expandSchema(a.additionalProperties)),a.additionalItems&&"object"==typeof a.additionalItems&&(a.additionalItems=e.expandSchema(a.additionalItems)),a.allOf){for(d=0;d=a.maximum?j.push({path:e,property:"maximum",message:this.translate("error_maximum_excl",[a.maximum])}):!a.exclusiveMaximum&&d>a.maximum&&j.push({path:e,property:"maximum",message:this.translate("error_maximum_incl",[a.maximum])})),a.minimum&&(a.exclusiveMinimum&&d<=a.minimum?j.push({path:e,property:"minimum",message:this.translate("error_minimum_excl",[a.minimum])}):!a.exclusiveMinimum&&da.maxLength&&j.push({path:e,property:"maxLength",message:this.translate("error_maxLength",[a.maxLength])}),a.minLength&&(d+"").lengtha.maxItems&&j.push({path:e,property:"maxItems",message:this.translate("error_maxItems",[a.maxItems])}),a.minItems&&d.lengtha.maxProperties&&j.push({path:e,property:"maxProperties",message:this.translate("error_maxProperties",[a.maxProperties])})}if(a.minProperties){g=0;for(h in d)d.hasOwnProperty(h)&&g++;g=0){b=this.theme.getBlockLinkHolder(),c=this.theme.getBlockLink(),c.setAttribute("target","_blank");var h=document.createElement(e);h.setAttribute("controls","controls"),this.theme.createMediaLink(b,c,h),this.link_watchers.push(function(b){var d=f(b);c.setAttribute("href",d),c.textContent=a.rel||d,h.setAttribute("src",d)})}else b=this.theme.getBlockLink(),b.setAttribute("target","_blank"),b.textContent=a.rel,this.link_watchers.push(function(c){var d=f(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(){var a;if(this.header_template){a=b(this.getWatchedFieldValues(),{key:this.key,i:this.key,title:this.getTitle()});var c=this.header_template(a);c!==this.header_text&&(this.header_text=c,this.updateHeaderText(),this.fireChangeHeaderEvent())}if(this.link_watchers.length){a=this.getWatchedFieldValues();for(var d=0;d1&&(b[a]=c+" "+e[c])}),b},showValidationErrors:function(){}}),f.defaults.editors.null=f.AbstractEditor.extend({getValue:function(){return null},setValue:function(){this.jsoneditor.notifyWatchers(this.path)},getNumColumns:function(){return 2}}),f.defaults.editors.string=f.AbstractEditor.extend({getDefault:function(){return this.schema.default||""},register:function(){this._super(),this.input&&this.input.setAttribute("name",this.formname)},unregister:function(){this._super(),this.input&&this.input.removeAttribute("name")},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,c=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.format&&this.options.default_format&&(this.format=this.options.default_format),this.options.format&&(this.format=this.options.format),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=[],Array.isArray(this.schema.enumSource))for(a=0;a=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(a){if(a.preventDefault(),a.stopPropagation(),c.schema.template)return void(this.value=c.value);var b=this.value,d=c.sanitize(b);b!==d&&(this.value=d),c.refreshValue(),c.watch_listener(),c.jsoneditor.notifyWatchers(c.path),c.parent?c.parent.onChildEditorChange(c):c.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(){c.input.parentNode&&c.afterInputReady()}),this.register(),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,c=this;if(this.source_code)if(this.options.wysiwyg&&["html","bbcode"].indexOf(this.input_type)>=0&&window.$&&$.fn&&$.fn.sceditor)a=b({},{plugins:"html"===c.input_type?"xhtml":"bbcode",emoticonsEnabled:!1,width:"100%",height:300},f.plugins.sceditor),$(c.input).sceditor(a),c.sceditor_instance=$(c.input).sceditor("instance"),c.sceditor_instance.blur(function(){var a=$("
    "+c.sceditor_instance.val()+"
    ");$("#sceditor-start-marker,#sceditor-end-marker,.sceditor-nlf",a).remove(),c.input.value=a.html(),c.value=c.input.value,c.parent?c.parent.onChildEditorChange(c):c.jsoneditor.onChange(),c.jsoneditor.notifyWatchers(c.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",a=b({},f.plugins.epiceditor,{container:this.epiceditor_container,clientSideStorage:!1}),this.epiceditor=new EpicEditor(a).load(),this.epiceditor.importFile(null,this.getValue()),this.epiceditor.on("update",function(){var a=c.epiceditor.exportFile(); +c.input.value=a,c.value=a,c.parent?c.parent.onChildEditorChange(c):c.jsoneditor.onChange(),c.jsoneditor.notifyWatchers(c.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()),f.plugins.ace.theme&&this.ace_editor.setTheme("ace/theme/"+f.plugins.ace.theme),d=ace.require("ace/mode/"+d),d&&this.ace_editor.getSession().setMode(new d.Mode),this.ace_editor.on("change",function(){var a=c.ace_editor.getValue();c.input.value=a,c.refreshValue(),c.parent?c.parent.onChildEditorChange(c):c.jsoneditor.onChange(),c.jsoneditor.notifyWatchers(c.path)})}c.theme.afterInputReady(c.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&&this.input.parentNode.removeChild(this.input),this.label&&this.label.parentNode&&this.label.parentNode.removeChild(this.label),this.description&&this.description.parentNode&&this.description.parentNode.removeChild(this.description),this._super()},sanitize:function(a){return a},onWatchedFieldChange:function(){var a,b;if(this.template&&(a=this.getWatchedFieldValues(),this.setValue(this.template(a),!1,!0)),this.enumSource){a=this.getWatchedFieldValues();for(var c=[],d=[],e=0;ee)&&(c=g);c===!1&&(f.push({width:0,minh:999999,maxh:0,editors:[]}),c=f.length-1),f[c].editors.push({key:a,width:d,height:e}),f[c].width+=d,f[c].minh=Math.min(f[c].minh,e),f[c].maxh=Math.max(f[c].maxh,e)}}),a=0;af[a].editors[g].width&&(g=b),f[a].editors[b].width*=12/f[a].width,f[a].editors[b].width=Math.floor(f[a].editors[b].width),h+=f[a].editors[b].width;12>h&&(f[a].editors[g].width+=12-h),f[a].width=12}if(this.layout===JSON.stringify(f))return!1;for(this.layout=JSON.stringify(f),e=document.createElement("div"),a=0;a=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.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&&d(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()}var e={},f=Object.keys(this.editors);f=f.sort(function(b,c){var d=a.editors[b].schema.propertyOrder,e=a.editors[c].schema.propertyOrder;return"number"!=typeof d&&(d=1e3),"number"!=typeof e&&(e=1e3),d-e});for(var g=0;g=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(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 d=this;a=a||{},("object"!=typeof a||Array.isArray(a))&&(a={}),c(this.editors,function(c,e){if("undefined"!=typeof a[c])e.property_removed&&d.addObjectProperty(c),e.setValue(a[c],b);else{if(!b&&!e.property_removed&&!e.isRequired())return void d.removeObjectProperty(c);e.setValue(e.getDefault(),b)}}),this.canHaveAdditionalProperties()&&c(a,function(a,c){d.editors[a]||(d.addObjectProperty(a),d.editors[a]&&d.editors[a].setValue(c,b))}),this.refreshValue(),this.jsoneditor.notifyWatchers(this.path)},showValidationErrors:function(a){var b=this,d=[],e=[];if(c(a,function(a,c){c.path===b.path?d.push(c):e.push(c)}),this.error_holder)if(d.length){this.error_holder.innerHTML="",this.error_holder.style.display="",c(d,function(a,c){b.error_holder.appendChild(b.theme.getErrorMessage(c.message))})}else this.error_holder.style.display="none";this.getOption("table_row")&&(d.length?this.theme.addTableRowError(this.container):this.theme.removeTableRowError(this.container)),c(this.editors,function(a,b){b.showValidationErrors(e)})}}),f.defaults.editors.array=f.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?b({},this.schema.additionalItems):void 0:b({},this.schema.items[a]):this.schema.items?b({},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;c(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",a.unregister())},getMax:function(){return Array.isArray(this.schema.items)&&this.schema.additionalItems===!1?Math.min(this.schema.items.length,this.schema.maxItems||1/0):this.schema.maxItems||1/0},refreshTabs:function(a){var b=this;c(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,b){a=a||[],Array.isArray(a)||(a=[a]);var d=JSON.stringify(a);if(d!==this.serialized){if(this.schema.minItems)for(;a.lengththis.getMax()&&(a=a.slice(0,this.getMax()));var e=this;c(a,function(a,b){e.rows[a]?e.rows[a].setValue(b):e.row_cache[a]?(e.rows[a]=e.row_cache[a],e.rows[a].setValue(b),e.rows[a].container.style.display="",e.rows[a].tab&&(e.rows[a].tab.style.display=""),e.rows[a].register()):e.addRow(b)});for(var f=a.length;f=this.rows.length;c(this.rows,function(a,c){c.movedown_buttons&&(c.movedown_button.style.display=a===b.rows.length-1?"none":""),c.delete_button&&(c.delete_button.style.display=e?"none":""),b.value[a]=c.getValue()});var f=!1;this.value.length?1===this.value.length?(this.remove_all_rows_button.style.display="none",e||this.hide_delete_buttons?this.delete_last_row_button.style.display="none":(this.delete_last_row_button.style.display="",f=!0)):e||this.hide_delete_buttons?(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none"):(this.delete_last_row_button.style.display="",this.remove_all_rows_button.style.display="",f=!0):(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none"),this.getMax()&&this.getMax()<=this.rows.length||this.hide_add_button?this.add_row_button.style.display="none":(this.add_row_button.style.display="",f=!0),this.controls.style.display=!this.collapsed&&f?"":"none"}},addRow:function(a){var b=this,d=this.rows.length;b.rows[d]=this.getElementEditor(d),b.row_cache[d]=b.rows[d],b.tabs_holder&&(b.rows[d].tab_text=document.createElement("span"),b.rows[d].tab_text.textContent=b.rows[d].getHeaderText(),b.rows[d].tab=b.theme.getTab(b.rows[d].tab_text),b.rows[d].tab.addEventListener("click",function(a){b.active_tab=b.rows[d].tab,b.refreshTabs(),a.preventDefault(),a.stopPropagation()}),b.theme.addTab(b.tabs_holder,b.rows[d].tab));var e=b.rows[d].title_controls||b.rows[d].array_controls;b.hide_delete_buttons||(b.rows[d].delete_button=this.getButton(b.getItemTitle(),"delete","Delete "+b.getItemTitle()),b.rows[d].delete_button.className+=" delete",b.rows[d].delete_button.setAttribute("data-i",d),b.rows[d].delete_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i"),d=b.getValue(),e=[],f=null;c(d,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()}),e&&e.appendChild(b.rows[d].delete_button)),d&&!b.hide_move_buttons&&(b.rows[d].moveup_button=this.getButton("","moveup","Move up"),b.rows[d].moveup_button.className+=" moveup",b.rows[d].moveup_button.setAttribute("data-i",d),b.rows[d].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()}}),e&&e.appendChild(b.rows[d].moveup_button)),b.hide_move_buttons||(b.rows[d].movedown_button=this.getButton("","movedown","Move down"),b.rows[d].movedown_button.className+=" movedown",b.rows[d].movedown_button.setAttribute("data-i",d),b.rows[d].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()}}),e&&e.appendChild(b.rows[d].movedown_button)),a&&b.rows[d].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.panel&&(a.panel.style.display=""),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.panel&&(a.panel.style.display="none"),a.setButtonText(this,"","expand","Expand"))}),this.options.collapsed&&d(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.rows[b].register()):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,d=[],e=[];if(c(a,function(a,c){c.path===b.path?d.push(c):e.push(c)}),this.error_holder)if(d.length){this.error_holder.innerHTML="",this.error_holder.style.display="",c(d,function(a,c){b.error_holder.appendChild(b.theme.getErrorMessage(c.message))})}else this.error_holder.style.display="none";c(this.rows,function(a,b){b.showValidationErrors(e)})}}),f.defaults.editors.table=f.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 d=JSON.stringify(a);if(d!==this.serialized){var e=!1,f=this;c(a,function(a,b){f.rows[a]?f.rows[a].setValue(b):(f.addRow(b),e=!0)});for(var g=a.length;g=this.rows.length,d=!1;c(this.rows,function(c,e){e.movedown_button&&(c===a.rows.length-1?e.movedown_button.style.display="none":(d=!0,e.movedown_button.style.display="")),e.delete_button&&(b?e.delete_button.style.display="none":(d=!0,e.delete_button.style.display="")),e.moveup_button&&(d=!0)}),c(this.rows,function(a,b){b.controls_cell.style.display=d?"":"none"}),this.controls_header_cell.style.display=d?"":"none";var e=!1;this.value.length?1===this.value.length||this.hide_delete_buttons?(this.table.style.display="",this.remove_all_rows_button.style.display="none",b||this.hide_delete_buttons?this.delete_last_row_button.style.display="none":(this.delete_last_row_button.style.display="",e=!0)):(this.table.style.display="",b||this.hide_delete_buttons?(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none"):(this.delete_last_row_button.style.display="",this.remove_all_rows_button.style.display="",e=!0)):(this.delete_last_row_button.style.display="none",this.remove_all_rows_button.style.display="none",this.table.style.display="none"),this.schema.maxItems&&this.schema.maxItems<=this.rows.length||this.hide_add_button?this.add_row_button.style.display="none":(this.add_row_button.style.display="",e=!0),this.controls.style.display=e?"":"none"},refreshValue:function(){var a=this;this.value=[],c(this.rows,function(b,c){a.value[b]=c.getValue()}),this.serialized=JSON.stringify(this.value)},addRow:function(a){var b=this,d=this.rows.length;b.rows[d]=this.getElementEditor(d);var e=b.rows[d].table_controls;this.hide_delete_buttons||(b.rows[d].delete_button=this.getButton("","delete","Delete"),b.rows[d].delete_button.className+=" delete",b.rows[d].delete_button.setAttribute("data-i",d),b.rows[d].delete_button.addEventListener("click",function(){var a=1*this.getAttribute("data-i"),d=b.getValue(),e=[];c(d,function(b,c){b!==a&&e.push(c)}),b.setValue(e),b.parent?b.parent.onChildEditorChange(b):b.jsoneditor.onChange()}),e.appendChild(b.rows[d].delete_button)),d&&!this.hide_move_buttons&&(b.rows[d].moveup_button=this.getButton("","moveup","Move up"),b.rows[d].moveup_button.className+=" moveup",b.rows[d].moveup_button.setAttribute("data-i",d),b.rows[d].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()}}),e.appendChild(b.rows[d].moveup_button)),this.hide_move_buttons||(b.rows[d].movedown_button=this.getButton("","movedown","Move down"),b.rows[d].movedown_button.className+=" movedown",b.rows[d].movedown_button.setAttribute("data-i",d),b.rows[d].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()}}),e.appendChild(b.rows[d].movedown_button)),a&&b.rows[d].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&&d(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)}}),f.defaults.editors.multiple=f.AbstractEditor.extend({getDefault:function(){return this.schema.default||null},register:function(){if(this.editors){for(var a=0;anull";if("object"==typeof a){var d="";return c(a,function(c,e){var f=b.getHTML(e);Array.isArray(a)||(f="
    "+c+": "+f+"
    "),d+="
  • "+f+"
  • "}),d=Array.isArray(a)?"
      "+d+"
    ":"
      "+d+"
    "}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()}}),f.defaults.editors.select=f.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))},register:function(){this._super(),this.input&&this.input.setAttribute("name",this.formname)},unregister:function(){this._super(),this.input&&this.input.removeAttribute("name")},getNumColumns:function(){for(var a=this.getTitle().length,b=0;b2&&$(this.input).select2(),this.register(),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()}}),f.defaults.editors.multiselect=f.AbstractEditor.extend({getDefault:function(){return[]},build:function(){var a,b=this;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.select_options={},this.select_values={};var c=this.schema.items.enum||[],d=[];for(a=0;aType: "+a+", Size: "+Math.floor((this.value.length-this.value.split(",")[0].length-1)/1.33333)+" bytes","image"===a.substr(0,5)){this.preview.innerHTML+="
    ";var b=document.createElement("img");b.style.maxWidth="100%",b.style.maxHeight="100px",b.src=this.value,this.preview.appendChild(b)}}else this.preview.innerHTML="Invalid data URI"}},enable:function(){this.uploader&&(this.uploader.disabled=!1),this._super()},disable:function(){this.uploader&&(this.uploader.disabled=!0),this._super()},setValue:function(a){this.value!==a&&(this.value=a,this.input.value=this.value,this.refreshPreview(),this.watch_listener(),this.jsoneditor.notifyWatchers(this.path))},destroy:function(){this.preview.parentNode.removeChild(this.preview),this.title.parentNode.removeChild(this.title),this.input.parentNode.removeChild(this.input),this.uploader&&this.uploader.parentNode.removeChild(this.uploader),this._super()}}),f.AbstractTheme=Class.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){var b=this.getFormInputLabel(a);return b.style.fontWeight="normal",b},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.display="inline-block",a.style.width="auto",a},getMultiCheckboxHolder:function(a,b,c){var d=document.createElement("div");b&&(b.style.display="block",d.appendChild(b));for(var e in a)a.hasOwnProperty(e)&&(a[e].style.display="inline-block",a[e].style.marginRight="20px",d.appendChild(a[e]));return c&&d.appendChild(c),d},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.group.className=a.group.className.replace(/ error/g,""),a.errmsg.style.display="none")}}),f.defaults.themes.foundation3=f.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)}}),f.defaults.themes.foundation4=f.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}}),f.defaults.themes.foundation5=f.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)}}),f.defaults.themes.html=f.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")}}),f.defaults.themes.jqueryui=f.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"}}),f.AbstractIconLib=Class.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}}),f.defaults.iconlibs.bootstrap2=f.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-"}),f.defaults.iconlibs.bootstrap3=f.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-"}),f.defaults.iconlibs.fontawesome3=f.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-"}),f.defaults.iconlibs.fontawesome4=f.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-"}),f.defaults.iconlibs.foundation2=f.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-"}),f.defaults.iconlibs.foundation3=f.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-"}),f.defaults.iconlibs.jqueryui=f.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-"}),f.defaults.templates.default=function(){var a=function(d){var e={};return c(d,function(d,f){if("object"==typeof f&&null!==f){var g={};c(f,function(a,b){g[d+"."+a]=b}),b(e,a(g))}else e[d]=f}),e};return{compile:function(b){return function(d){var e=a(d),f=b+"";return c(e,function(a,b){f=f.replace(new RegExp("{{\\s*"+a+"\\s*}}","g"),b)}),f}}}},f.defaults.templates.ejs=function(){return window.EJS?{compile:function(a){var b=new EJS({text:a});return function(a){return b.render(a)}}}:!1},f.defaults.templates.handlebars=function(){return window.Handlebars},f.defaults.templates.hogan=function(){return window.Hogan?{compile:function(a){var b=Hogan.compile(a);return function(a){return b.render(a)}}}:!1},f.defaults.templates.markup=function(){return window.Mark&&window.Mark.up?{compile:function(a){return function(b){return Mark.up(a,b)}}}:!1},f.defaults.templates.mustache=function(){return window.Mustache?{compile:function(a){return function(b){return Mustache.render(a,b)}}}:!1},f.defaults.templates.swig=function(){return window.swig},f.defaults.templates.underscore=function(){return window._?{compile:function(a){return function(b){return _.template(a,b)}}}:!1},f.defaults.theme="html",f.defaults.template="default",f.defaults.options={},f.defaults.translate=function(a,b){var c=f.defaults.languages[f.defaults.language];if(!c)throw"Unknown language "+f.defaults.language;var d=c[a]||f.defaults.languages[f.defaults.default_language][a];if("undefined"==typeof d)throw"Unknown translate string "+a;if(b)for(var e=0;e=0?"multiselect":void 0}),f.defaults.resolvers.unshift(function(a){return a.oneOf?"multiple":void 0}),(window.jQuery||window.Zepto)&&(window.$=window.$||{},$.jsoneditor=f.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 f(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=f}(); \ No newline at end of file diff --git a/src/core.js b/src/core.js index ecf584a72..7a0ce976b 100644 --- a/src/core.js +++ b/src/core.js @@ -16,6 +16,7 @@ JSONEditor.prototype = { this.schema = this.options.schema; this.theme = new theme_class(); this.template = this.options.template; + this.refs = this.options.refs || {}; this.uuid = 0; this.__data = {}; @@ -27,18 +28,10 @@ JSONEditor.prototype = { this.translate = this.options.translate || JSONEditor.defaults.translate; - this.validator = new JSONEditor.Validator(this.schema,{ - ajax: this.options.ajax, - refs: this.options.refs, - no_additional_properties: this.options.no_additional_properties, - required_by_default: this.options.required_by_default, - translate: this.translate - }); - - this.validator.ready(function(expanded) { - if(self.ready) return; - - self.schema = expanded; + // Fetch all external refs via ajax + this._loadExternalRefs(this.schema, function() { + self._getDefinitions(self.schema); + self.validator = new JSONEditor.Validator(self); // Create the root editor var editor_class = self.getEditorClass(self.schema); @@ -278,6 +271,294 @@ JSONEditor.prototype = { }, disable: function() { this.root.disable(); + }, + _getDefinitions: function(schema,path) { + path = path || '#/definitions/'; + if(schema.definitions) { + for(var i in schema.definitions) { + if(!schema.definitions.hasOwnProperty(i)) continue; + this.refs[path+i] = schema.definitions[i]; + if(schema.definitions[i].definitions) { + this._getDefinitions(schema.definitions[i],path+i+'/definitions/'); + } + } + } + }, + _getExternalRefs: function(schema) { + var refs = {}; + var merge_refs = function(newrefs) { + for(var i in newrefs) { + if(newrefs.hasOwnProperty(i)) { + refs[i] = true; + } + } + }; + + if(schema.$ref && schema.$ref.substr(0,1) !== "#" && !this.refs[schema.$ref]) { + refs[schema.$ref] = true; + } + + for(var i in schema) { + if(!schema.hasOwnProperty(i)) continue; + if(schema[i] && typeof schema[i] === "object" && Array.isArray(schema[i])) { + for(var j=0; j= waiting && !callback_fired) { + callback_fired = true; + callback(); + } + }); + } + // Request failed + else { + console.log(r); + throw "Failed to fetch ref via ajax- "+url; + } + }; + r.send(); + }); + + if(!waiting) { + callback(); + } + }, + expandRefs: function(schema) { + if(schema.$ref) { + schema = this.extendSchemas(schema,this.refs[schema.$ref]); + } + return schema; + }, + expandSchema: function(schema) { + var self = this; + var extended = schema; + var i; + + // Version 3 `type` + if(typeof schema.type === 'object') { + // Array of types + if(Array.isArray(schema.type)) { + $each(schema.type, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.type[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.type = self.expandSchema(schema.type); + } + } + // Version 3 `disallow` + if(typeof schema.disallow === 'object') { + // Array of types + if(Array.isArray(schema.disallow)) { + $each(schema.disallow, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.disallow[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.disallow = self.expandSchema(schema.disallow); + } + } + // Version 4 `anyOf` + if(schema.anyOf) { + $each(schema.anyOf, function(key,value) { + schema.anyOf[key] = self.expandSchema(value); + }); + } + // Version 4 `dependencies` (schema dependencies) + if(schema.dependencies) { + $each(schema.dependencies,function(key,value) { + if(typeof value === "object" && !(Array.isArray(value))) { + schema.dependencies[key] = self.expandSchema(value); + } + }); + } + // `items` + if(schema.items) { + // Array of items + if(Array.isArray(schema.items)) { + $each(schema.items, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.items[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.items = self.expandSchema(schema.items); + } + } + // `properties` + if(schema.properties) { + $each(schema.properties,function(key,value) { + if(typeof value === "object" && !(Array.isArray(value))) { + schema.properties[key] = self.expandSchema(value); + } + }); + } + // `patternProperties` + if(schema.patternProperties) { + $each(schema.patternProperties,function(key,value) { + if(typeof value === "object" && !(Array.isArray(value))) { + schema.patternProperties[key] = self.expandSchema(value); + } + }); + } + // Version 4 `not` + if(schema.not) { + schema.not = this.expandSchema(schema.not); + } + // `additionalProperties` + if(schema.additionalProperties && typeof schema.additionalProperties === "object") { + schema.additionalProperties = self.expandSchema(schema.additionalProperties); + } + // `additionalItems` + if(schema.additionalItems && typeof schema.additionalItems === "object") { + schema.additionalItems = self.expandSchema(schema.additionalItems); + } + + // allOf schemas should be merged into the parent + if(schema.allOf) { + for(i=0; i= waiting) { - if(called) return; - called = true; - self._getRefs(schema,callback,path); - } - }; - - $each(defs,function() { - waiting++; - }); - - if(waiting) { - $each(defs,function(i,definition) { - // Expand the definition recursively - self._getRefs(definition,function(def_schema) { - self.refs[path+'/definitions/'+i] = def_schema; - finished++; - check_if_finished(schema); - },path+'/definitions/'+i,true); - }); - } - else { - check_if_finished(schema); - } - } - // Expand out any references - else if(schema.$ref) { - var ref = schema.$ref; - delete schema.$ref; - - // If we're currently loading this external reference, wait for it to be done - if(self.refs[ref] && Array.isArray(self.refs[ref])) { - self.refs[ref].push(function() { - schema = $extend({},self.refs[ref],schema); - callback(schema); - }); - } - // If this reference has already been loaded - else if(self.refs[ref]) { - schema = $extend({},self.refs[ref],schema); - callback(schema); - } - // Otherwise, it needs to be loaded via ajax - else { - if(!self.options.ajax) throw "Must set ajax option to true to load external url "+ref; - - var r = new XMLHttpRequest(); - r.open("GET", ref, true); - r.onreadystatechange = function () { - if (r.readyState != 4) return; - if(r.status === 200) { - var response = JSON.parse(r.responseText); - self.refs[ref] = []; - - // Recursively expand this schema - self._getRefs(response, function(ref_schema) { - var list = self.refs[ref]; - self.refs[ref] = ref_schema; - schema = $extend({},self.refs[ref],schema); - callback(schema); - - // If anything is waiting on this to load - $each(list,function(i,v) { - v(); - }); - },path); - return; - } - - // Request failed - throw "Failed to fetch ref via ajax- "+ref; - }; - r.send(); - } - } - // Expand out any subschemas - else { - waiting = finished = 0; - check_if_finished = function(schema) { - if(finished >= waiting) { - if(called) return; - called = true; - - callback(schema); - } - }; - - $each(schema, function(key, value) { - // Arrays that need to be expanded - if(typeof value === "object" && value && Array.isArray(value)) { - $each(value,function(j,item) { - if(typeof item === "object" && item && !(Array.isArray(item))) { - waiting++; - } - }); - } - // Objects that need to be expanded - else if(typeof value === "object" && value) { - waiting++; - } - }); - - if(waiting) { - $each(schema, function(key, value) { - // Arrays that need to be expanded - if(typeof value === "object" && value && Array.isArray(value)) { - $each(value,function(j,item) { - if(typeof item === "object" && item && !(Array.isArray(item))) { - self._getRefs(item,function(expanded) { - schema[key][j] = expanded; - - finished++; - check_if_finished(schema); - },path+'/'+key+'/'+j); - } - }); - } - // Objects that need to be expanded - else if(typeof value === "object" && value) { - self._getRefs(value,function(expanded) { - schema[key] = expanded; - - finished++; - check_if_finished(schema); - },path+'/'+key); - } - }); - } - else { - check_if_finished(schema); - } - } + init: function(jsoneditor,schema) { + this.jsoneditor = jsoneditor; + this.schema = schema || this.jsoneditor.schema; + this.options = {}; + this.translate = this.jsoneditor.translate || JSONEditor.defaults.translate; }, validate: function(value) { return this._validateSchema(this.schema, value); @@ -214,7 +38,7 @@ JSONEditor.Validator = Class.extend({ // Value not defined else if(typeof value === "undefined") { // If required_by_default is set, all fields are required - if(this.options.required_by_default) { + if(this.jsoneditor.options.required_by_default) { errors.push({ path: path, property: 'required', @@ -624,7 +448,7 @@ JSONEditor.Validator = Class.extend({ } // The no_additional_properties option currently doesn't work with extended schemas that use oneOf or anyOf - if(typeof schema.additionalProperties === "undefined" && this.options.no_additional_properties && !schema.oneOf && !schema.anyOf) { + if(typeof schema.additionalProperties === "undefined" && this.jsoneditor.options.no_additional_properties && !schema.oneOf && !schema.anyOf) { schema.additionalProperties = false; } @@ -706,195 +530,5 @@ JSONEditor.Validator = Class.extend({ else { return !this._validateSchema(type,value).length; } - }, - expandSchema: function(schema) { - var self = this; - var extended = schema; - var i; - - // Version 3 `type` - if(typeof schema.type === 'object') { - // Array of types - if(Array.isArray(schema.type)) { - $each(schema.type, function(key,value) { - // Schema - if(typeof value === 'object') { - schema.type[key] = self.expandSchema(value); - } - }); - } - // Schema - else { - schema.type = self.expandSchema(schema.type); - } - } - // Version 3 `disallow` - if(typeof schema.disallow === 'object') { - // Array of types - if(Array.isArray(schema.disallow)) { - $each(schema.disallow, function(key,value) { - // Schema - if(typeof value === 'object') { - schema.disallow[key] = self.expandSchema(value); - } - }); - } - // Schema - else { - schema.disallow = self.expandSchema(schema.disallow); - } - } - // Version 4 `anyOf` - if(schema.anyOf) { - $each(schema.anyOf, function(key,value) { - schema.anyOf[key] = self.expandSchema(value); - }); - } - // Version 4 `dependencies` (schema dependencies) - if(schema.dependencies) { - $each(schema.dependencies,function(key,value) { - if(typeof value === "object" && !(Array.isArray(value))) { - schema.dependencies[key] = self.expandSchema(value); - } - }); - } - // `items` - if(schema.items) { - // Array of items - if(Array.isArray(schema.items)) { - $each(schema.items, function(key,value) { - // Schema - if(typeof value === 'object') { - schema.items[key] = self.expandSchema(value); - } - }); - } - // Schema - else { - schema.items = self.expandSchema(schema.items); - } - } - // `properties` - if(schema.properties) { - $each(schema.properties,function(key,value) { - if(typeof value === "object" && !(Array.isArray(value))) { - schema.properties[key] = self.expandSchema(value); - } - }); - } - // `patternProperties` - if(schema.patternProperties) { - $each(schema.patternProperties,function(key,value) { - if(typeof value === "object" && !(Array.isArray(value))) { - schema.patternProperties[key] = self.expandSchema(value); - } - }); - } - // Version 4 `not` - if(schema.not) { - schema.not = this.expandSchema(schema.not); - } - // `additionalProperties` - if(schema.additionalProperties && typeof schema.additionalProperties === "object") { - schema.additionalProperties = self.expandSchema(schema.additionalProperties); - } - // `additionalItems` - if(schema.additionalItems && typeof schema.additionalItems === "object") { - schema.additionalItems = self.expandSchema(schema.additionalItems); - } - - // allOf schemas should be merged into the parent - if(schema.allOf) { - for(i=0; i"+i+" test "+j+":: Expected: [], Actual: "+JSON.stringify(result)+""); + } + else { + console.log(num,'valid',j); + } + } + catch(e) { + console.log(test.schema,value); + throw e; + } + }); + $.each(test.invalid,function(j,value) { + try { + num++; + var result = editor.validate(value); + if(!result.length) { + console.error(num,'invalid',j,JSON.stringify(result,null,2)); + $("#output").append("
    "+i+" test "+j+":: Expected: errors, Actual: []
    "); - var validator = new JSONEditor.Validator(test.schema,{ - ajax: true, - ready: function() { - var self = this; - $.each(test.valid,function(j,value) { - num++; - var result = self.validate(value); - if(result.length) { - console.error(num,'valid',j,JSON.stringify(result,null,2)); - $("#output").append("
    "+i+" test "+j+":: Expected: [], Actual: "+JSON.stringify(result)+"
    "); - } - else { - console.log(num,'valid',j); - } - }); - $.each(test.invalid,function(j,value) { - num++; - var result = self.validate(value); - if(!result.length) { - console.error(num,'invalid',j,JSON.stringify(result,null,2)); - $("#output").append("
    "+i+" test "+j+":: Expected: errors, Actual: []
    "); - - } - else { - var errors = []; - $.each(result,function(k,error) { - errors.push(error.path+": "+error.message); - }); - if(errors.length === 1) errors = errors[0]; + } + else { + var errors = []; + $.each(result,function(k,error) { + errors.push(error.path+": "+error.message); + }); + if(errors.length === 1) errors = errors[0]; - console.log(num,'invalid',j,JSON.stringify(errors,null,2)); - } - }); - next(); + console.log(num,'invalid',j,JSON.stringify(errors,null,2)); + } + } + catch(e) { + console.log(test.schema,value); + throw e; } + }); + next(); }); }); });