diff --git a/Gruntfile.js b/Gruntfile.js index 92244248b..c287f3d7a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -35,7 +35,8 @@ module.exports = function(grunt) { 'src/editors/select.js', 'src/editors/multiselect.js', 'src/editors/base64.js', - + 'src/editors/radio.js', + // All the themes and iconlibs 'src/theme.js', 'src/themes/*.js', diff --git a/README.md b/README.md index a79f6fcf3..13889fdd6 100644 --- a/README.md +++ b/README.md @@ -459,7 +459,7 @@ So, the final order of properties in the form (and in returned JSON data) will b ### format JSON Editor supports many different formats for schemas of type `string`. They will work with schemas of type `integer` and `number` as well, but some formats may produce weird results. -If the `enum` property is specified, `format` will be ignored. +If the `enum` property is specified, `format` will be limited to "radio" or "select" (default). JSON Editor uses HTML5 input types, so some of these may render as basic text input in older browsers: @@ -1032,10 +1032,9 @@ The following schema will now use this custom editor for each of the array eleme If you create a custom editor interface that you think could be helpful to others, submit a pull request! -The possibilities are endless. Some ideas: +The possibilities are endless. Some ideas: * A compact way to edit objects -* Radio button version of the `select` editor * Autosuggest for strings (like enum, but not restricted to those values) * Better editor for arrays of strings (tag editor) * Canvas based image editor that produces Base64 data URLs diff --git a/dist/jsoneditor.js b/dist/jsoneditor.js index 421fa7b25..4e7787417 100644 --- a/dist/jsoneditor.js +++ b/dist/jsoneditor.js @@ -5278,6 +5278,167 @@ JSONEditor.defaults.editors.base64 = JSONEditor.AbstractEditor.extend({ } }); +JSONEditor.defaults.editors.radio = JSONEditor.AbstractEditor.extend({ + setValue: function(value,initial) { + value = this.typecast(value || ''); + + // Sanitize value before setting it + var sanitized = value; + if(this.schema.enum.indexOf(sanitized) < 0) { + sanitized = this.schema.enum[0]; + } + + if(this.value === sanitized) { + return; + } + + var self = this; + $each(this.inputs,function(i,input) { + if (input.value === sanitized) { + input.checked = true; + self.value = sanitized; + self.jsoneditor.notifyWatchers(self.path); + return false; + } + }); + }, + register: function() { + this._super(); + if(!this.inputs) return; + $each(this.inputs,function(i,input) { + input.setAttribute('name',this.formname); + }); + }, + unregister: function() { + this._super(); + if(!this.inputs) return; + $each(this.inputs,function(i,input) { + input.removeAttribute('name'); + }); + }, + getNumColumns: function() { + var longest_text = this.getTitle().length; + for(var i=0; i=e){if(h)return;h=!0,i._getRefs(a,d)}},c(k,function(){e++}),e?c(k,function(b,c){i._getRefs(c,function(c){i.refs["#/definitions/"+b]=c,f++,g(a)})}):g(a)}else if(a.$ref){var l=a.$ref;if(delete a.$ref,i.refs[l]&&i.refs[l]instanceof Array)i.refs[l].push(function(){a=b({},i.refs[l],a),d(a)});else if(i.refs[l])a=b({},i.refs[l],a),d(a);else{if(!i.options.ajax)throw"Must set ajax option to true to load external url "+l;var m=new XMLHttpRequest;m.open("GET",l,!0),m.onreadystatechange=function(){if(4==m.readyState){if(200===m.status){var e=JSON.parse(m.responseText);return i.refs[l]=[],void i._getRefs(e,function(e){var f=i.refs[l];i.refs[l]=e,a=b({},i.refs[l],a),d(a),c(f,function(a,b){b()})})}throw"Failed to fetch ref via ajax- "+l}},m.send()}}else e=f=0,g=function(a){if(f>=e){if(h)return;h=!0,d(a)}},c(a,function(a,b){"object"==typeof b&&b&&b instanceof Array?c(b,function(a,b){"object"!=typeof b||!b||b instanceof Array||e++}):"object"==typeof b&&b&&e++}),e?c(a,function(b,d){"object"==typeof d&&d&&d instanceof Array?c(d,function(c,d){"object"!=typeof d||!d||d instanceof Array||i._getRefs(d,function(d){a[b][c]=d,f++,g(a)})}):"object"==typeof d&&d&&i._getRefs(d,function(c){a[b]=c,f++,g(a)})}):g(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:"Property must be set"}),j}else if("undefined"==typeof d){if(!this.options.required_by_default)return j;j.push({path:e,property:"required",message:"Property must be set"})}if(a.enum){for(g=!1,h=0;h=a.maximum?j.push({path:e,property:"maximum",message:"Value must be less than "+a.maximum}):!a.exclusiveMaximum&&d>a.maximum&&j.push({path:e,property:"maximum",message:"Value must be at most "+a.maximum})),a.minimum&&(a.exclusiveMinimum&&d<=a.minimum?j.push({path:e,property:"minimum",message:"Value must be greater than "+a.minimum}):!a.exclusiveMinimum&&da.maxLength&&j.push({path:e,property:"maxLength",message:"Value must be at most "+a.maxLength+" characters long"}),a.minLength&&(d+"").lengtha.maxItems&&j.push({path:e,property:"maxItems",message:"Value must have at most "+a.maxItems+" items"}),a.minItems&&d.lengtha.maxProperties&&j.push({path:e,property:"maxProperties",message:"Object must have at most "+a.maxProperties+" properties"})}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.schema.enum)this.input_type="select",this.select_options=this.schema.enum,this.input=this.theme.getSelectInput(this.select_options);else if(this.schema.enumSource){if(this.input_type="select",this.input=this.theme.getSelectInput([]),this.enumSource=[],this.schema.enumSource instanceof Array)for(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.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||a instanceof Array)&&(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 this.schema.items instanceof Array&&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||[],a instanceof Array||(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=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].moveup_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.row_holder.style.display=b,a.tabs_holder&&(a.tabs_holder.style.display=""),a.controls.style.display=c,a.setButtonText(this,"","collapse","Collapse")):(a.collapsed=!0,a.row_holder.style.display="none",a.tabs_holder&&(a.tabs_holder.style.display="none"),a.controls.style.display="none",a.setButtonText(this,"","expand","Expand"))}),this.options.collapsed&&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);a instanceof Array||(f="
"+c+": "+f+"
"),d+="
  • "+f+"
  • "}),d=a instanceof Array?"
      "+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.plugins={ace:{theme:""},epiceditor:{},sceditor:{}};for(var g in f.defaults.editors)f.defaults.editors.hasOwnProperty(g)&&(f.defaults.editors[g].options=f.defaults.editors.options||{});f.defaults.resolvers.unshift(function(a){return"string"!=typeof a.type?"multiple":void 0}),f.defaults.resolvers.unshift(function(a){return"string"==typeof a.type?a.type:void 0}),f.defaults.resolvers.unshift(function(a){return"boolean"===a.type?"select":void 0}),f.defaults.resolvers.unshift(function(a){return"any"===a.type?"multiple":void 0}),f.defaults.resolvers.unshift(function(a){return"string"===a.type&&a.media&&"base64"===a.media.binaryEncoding?"base64":void 0}),f.defaults.resolvers.unshift(function(a){return"array"==a.type&&"table"==a.format?"table":void 0}),f.defaults.resolvers.unshift(function(a){if(a.enum){if("array"===a.type||"object"===a.type)return"enum";if("number"===a.type||"integer"===a.type||"string"===a.type)return"select"}}),f.defaults.resolvers.unshift(function(a){return"array"===a.type&&a.items&&!(a.items instanceof Array)&&a.uniqueItems&&a.items.enum&&["string","number","integer"].indexOf(a.items.type)>=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 +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);a instanceof Array||(f="
    "+c+": "+f+"
    "),d+="
  • "+f+"
  • "}),d=a instanceof Array?"
      "+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.defaults.editors.radio=f.AbstractEditor.extend({setValue:function(a){a=this.typecast(a||"");var b=a;if(this.schema.enum.indexOf(b)<0&&(b=this.schema.enum[0]),this.value!==b){var d=this;c(this.inputs,function(a,c){return c.value===b?(c.checked=!0,d.value=b,d.jsoneditor.notifyWatchers(d.path),!1):void 0})}},register:function(){this._super(),this.inputs&&c(this.inputs,function(a,b){b.setAttribute("name",this.formname)})},unregister:function(){this._super(),this.inputs&&c(this.inputs,function(a,b){b.removeAttribute("name")})},getNumColumns:function(){for(var a=this.getTitle().length,b=0;b'),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.plugins={ace:{theme:""},epiceditor:{},sceditor:{}};for(var g in f.defaults.editors)f.defaults.editors.hasOwnProperty(g)&&(f.defaults.editors[g].options=f.defaults.editors.options||{});f.defaults.resolvers.unshift(function(a){return"string"!=typeof a.type?"multiple":void 0}),f.defaults.resolvers.unshift(function(a){return"string"==typeof a.type?a.type:void 0}),f.defaults.resolvers.unshift(function(a){return"boolean"===a.type?"select":void 0}),f.defaults.resolvers.unshift(function(a){return"any"===a.type?"multiple":void 0}),f.defaults.resolvers.unshift(function(a){return"string"===a.type&&a.media&&"base64"===a.media.binaryEncoding?"base64":void 0}),f.defaults.resolvers.unshift(function(a){return"array"==a.type&&"table"==a.format?"table":void 0}),f.defaults.resolvers.unshift(function(a){if(a.enum){if("array"===a.type||"object"===a.type)return"enum";if("number"===a.type||"integer"===a.type||"string"===a.type)return a.format||"select"}}),f.defaults.resolvers.unshift(function(a){return"array"===a.type&&a.items&&!(a.items instanceof Array)&&a.uniqueItems&&a.items.enum&&["string","number","integer"].indexOf(a.items.type)>=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/examples/basic.html b/examples/basic.html index 6505025c2..288a839b6 100644 --- a/examples/basic.html +++ b/examples/basic.html @@ -20,6 +20,7 @@

    Basic JSON Editor Example

    properties: { make: { type: "string", + format: "radio", enum: [ "Toyota", "BMW", diff --git a/src/defaults.js b/src/defaults.js index 85b3ccc07..d2e8dbe30 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -68,7 +68,7 @@ JSONEditor.defaults.resolvers.unshift(function(schema) { return "enum"; } else if(schema.type === "number" || schema.type === "integer" || schema.type === "string") { - return "select"; + return schema.format || "select"; } } }); @@ -82,4 +82,4 @@ JSONEditor.defaults.resolvers.unshift(function(schema) { JSONEditor.defaults.resolvers.unshift(function(schema) { // If this schema uses `oneOf` if(schema.oneOf) return "multiple"; -}); +}); \ No newline at end of file diff --git a/src/editors/radio.js b/src/editors/radio.js new file mode 100644 index 000000000..b44525a04 --- /dev/null +++ b/src/editors/radio.js @@ -0,0 +1,161 @@ +JSONEditor.defaults.editors.radio = JSONEditor.AbstractEditor.extend({ + setValue: function(value,initial) { + value = this.typecast(value || ''); + + // Sanitize value before setting it + var sanitized = value; + if(this.schema.enum.indexOf(sanitized) < 0) { + sanitized = this.schema.enum[0]; + } + + if(this.value === sanitized) { + return; + } + + var self = this; + $each(this.inputs,function(i,input) { + if (input.value === sanitized) { + input.checked = true; + self.value = sanitized; + self.jsoneditor.notifyWatchers(self.path); + return false; + } + }); + }, + register: function() { + this._super(); + if(!this.inputs) return; + $each(this.inputs,function(i,input) { + input.setAttribute('name',this.formname); + }); + }, + unregister: function() { + this._super(); + if(!this.inputs) return; + $each(this.inputs,function(i,input) { + input.removeAttribute('name'); + }); + }, + getNumColumns: function() { + var longest_text = this.getTitle().length; + for(var i=0; i