diff --git a/README.md b/README.md
index 4f98a7b26..f1eb894ca 100644
--- a/README.md
+++ b/README.md
@@ -373,12 +373,14 @@ JSON Editor supports schema references to external URLs and local definitions.
}
```
-Local references must point to the `definitions` object of the root node of the schema and can't be nested.
-So, both `#/customkey/name` and `#/definitions/name/first` will throw an exception.
+Local references must point to the `definitions` object of the root node of the schema.
+So, `#/customkey/name` will throw an exception.
If loading an external url via Ajax, the url must either be on the same domain or return the correct HTTP cross domain headers.
If your URLs don't meet this requirement, you can pass in the references to JSON Editor during initialization (see Usage section above).
+Self-referential $refs are supported. Check out `examples/recursive.html` for usage examples.
+
### hyper-schema links
The `links` keyword from the hyper-schema specification can be used to add links to related documents.
@@ -456,6 +458,26 @@ So, the final order of properties in the form (and in returned JSON data) will b
3. prop1 (order 1000)
4. prop3 (order 1001)
+### Default Properties
+
+The default behavior of JSON Editor is to include all object properties defined with the `properties` keyword.
+
+To override this behaviour, you can use the keyword `defaultProperties` to set which ones are included:
+
+```json
+{
+ "type": "object",
+ "properties": {
+ "name": {"type": "string"},
+ "age": {"type": "integer"}
+ },
+ "defaultProperties": ["name"]
+}
+```
+
+Now, only the `name` property above will be included by default. You can use the "Object Properties" button
+to add the "age" property back in.
+
### 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.
diff --git a/demo.html b/demo.html
index d4027399c..16cd98132 100644
--- a/demo.html
+++ b/demo.html
@@ -158,7 +158,7 @@
Code
},
age: {
type: "integer",
- default: 24,
+ default: 25,
minimum: 18,
maximum: 99
},
diff --git a/dist/jsoneditor.js b/dist/jsoneditor.js
index f8a46670f..5164ed62e 100644
--- a/dist/jsoneditor.js
+++ b/dist/jsoneditor.js
@@ -1,8 +1,8 @@
-/*! JSON Editor v0.6.19 - JSON Schema -> HTML Editor
+/*! JSON Editor v0.7.0 - JSON Schema -> HTML Editor
* By Jeremy Dorn - https://github.com/jdorn/json-editor/
* Released under the MIT license
*
- * Date: 2014-06-29
+ * Date: 2014-07-13
*/
/**
@@ -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,27 +222,23 @@ 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);
self.root = self.createEditor(editor_class, {
jsoneditor: self,
schema: self.schema,
- container: self.root_container,
- required: true
+ required: true,
+ container: self.root_container
});
+
+ self.root.preBuild();
+ self.root.build();
+ self.root.postBuild();
// Starting data
if(self.options.startval) self.root.setValue(self.options.startval);
@@ -336,9 +333,11 @@ JSONEditor.prototype = {
}
}
},
- getEditorClass: function(schema, editor) {
+ getEditorClass: function(schema) {
var classname;
+ schema = this.expandSchema(schema);
+
$each(JSONEditor.defaults.resolvers,function(i,resolver) {
var tmp = resolver(schema);
if(tmp) {
@@ -472,201 +471,277 @@ 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() {
- var self = this;
- this._getRefs(this.original_schema, function(schema) {
- self.schema = schema;
- self.expanded = self.expandSchema(self.schema);
-
- self.is_ready = true;
- $each(self.ready_callbacks,function(i,callback) {
- callback.apply(self,[self.expanded]);
- });
- });
+ _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) {
- if(called) return;
- called = true;
- self._getRefs(schema,callback,path);
+ var refs = this._getExternalRefs(schema);
+
+ var done = 0, waiting = 0, callback_fired = false;
+
+ $each(refs,function(url) {
+ if(self.refs[url]) return;
+ if(!self.options.ajax) throw "Must set ajax option to true to load external ref "+url;
+ self.refs[url] = 'loading';
+ waiting++;
+
+ var r = new XMLHttpRequest();
+ r.open("GET", url, true);
+ r.onreadystatechange = function () {
+ if (r.readyState != 4) return;
+ // Request succeeded
+ if(r.status === 200) {
+ var response;
+ try {
+ response = JSON.parse(r.responseText);
+ }
+ catch(e) {
+ console.log(e);
+ throw "Failed to parse external ref "+url;
+ }
+ if(!response || typeof response !== "object") throw "External ref does not contain a valid schema - "+url;
+
+ self.refs[url] = response;
+ self._loadExternalRefs(response,function() {
+ done++;
+ if(done >= 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) {
+ schema = $extend({},schema);
+
+ while (schema.$ref) {
+ var ref = schema.$ref;
+ delete schema.$ref;
+ schema = this.extendSchemas(schema,this.refs[ref]);
+ }
+ return schema;
+ },
+ expandSchema: function(schema) {
+ var self = this;
+ var extended = $extend({},schema);
+ var i;
- $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);
+ // 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 {
- check_if_finished(schema);
+ schema.type = self.expandSchema(schema.type);
}
}
- // 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);
+ // 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);
+ }
});
}
- // If this reference has already been loaded
- else if(self.refs[ref]) {
- schema = $extend({},self.refs[ref],schema);
- callback(schema);
+ // Schema
+ else {
+ schema.disallow = self.expandSchema(schema.disallow);
}
- // Otherwise, it needs to be loaded via ajax
+ }
+ // 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);
+ }
+ });
+ }
+ // Version 4 `not`
+ if(schema.not) {
+ schema.not = this.expandSchema(schema.not);
+ }
+
+ // 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= 0;
- }
-
- self.editors[key] = self.jsoneditor.createEditor(editor,{
- jsoneditor: self.jsoneditor,
- schema: schema,
- container: holder,
- path: self.path+'.'+key,
- parent: self,
- required: required
- });
-
- self.minwidth = Math.max(self.minwidth,self.editors[key].getNumColumns());
- self.maxwidth += self.editors[key].getNumColumns();
+ editor.setContainer(holder);
+ editor.build();
+ editor.postBuild();
});
// Control buttons
- this.title_controls = this.getTheme().getHeaderButtonHolder();
- this.editjson_controls = this.getTheme().getHeaderButtonHolder();
- this.addproperty_controls = this.getTheme().getHeaderButtonHolder();
+ this.title_controls = this.theme.getHeaderButtonHolder();
+ this.editjson_controls = this.theme.getHeaderButtonHolder();
+ this.addproperty_controls = this.theme.getHeaderButtonHolder();
this.title.appendChild(this.title_controls);
this.title.appendChild(this.editjson_controls);
this.title.appendChild(this.addproperty_controls);
@@ -2814,28 +2716,11 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
this.refreshAddProperties();
}
- // Sort editors by propertyOrder
- var sorted = {};
- var keys = Object.keys(this.editors);
- keys = keys.sort(function(a,b) {
- var ordera = self.editors[a].schema.propertyOrder;
- var orderb = self.editors[b].schema.propertyOrder;
- if(typeof ordera !== "number") ordera = 1000;
- if(typeof orderb !== "number") orderb = 1000;
-
- return ordera - orderb;
- });
- for(var i=0; i= this.schema.maxProperties);
+ if(this.addproperty_checkboxes) {
+ this.addproperty_list.innerHTML = '';
+ }
+ this.addproperty_checkboxes = {};
+
// Check for which editors can't be removed or added back
- for(i in this.editors) {
- if(!this.editors.hasOwnProperty(i)) continue;
- if(this.editors[i].isRequired()) {
- if(this.addproperty_checkboxes && this.addproperty_checkboxes[i]) {
- this.addproperty_checkboxes[i].disabled = true;
- }
+ for(i in this.cached_editors) {
+ if(!this.cached_editors.hasOwnProperty(i)) continue;
+
+ this.addPropertyCheckbox(i);
+
+ if(this.isRequired(this.cached_editors[i]) && i in this.editors) {
+ this.addproperty_checkboxes[i].disabled = true;
}
- else if(typeof this.schema.minProperties !== "undefined" && num_props <= this.schema.minProperties) {
- if(this.addproperty_checkboxes && this.addproperty_checkboxes[i]) {
- this.addproperty_checkboxes[i].disabled = this.addproperty_checkboxes[i].checked;
- if(!this.addproperty_checkboxes[i].checked) show_modal = true;
- }
- else if(this.editors[i].property_removed && can_add) {
- show_modal = true;
- }
+
+ if(typeof this.schema.minProperties !== "undefined" && num_props <= this.schema.minProperties) {
+ this.addproperty_checkboxes[i].disabled = this.addproperty_checkboxes[i].checked;
+ if(!this.addproperty_checkboxes[i].checked) show_modal = true;
}
- else if(this.editors[i].property_removed) {
- if(this.addproperty_checkboxes && this.addproperty_checkboxes[i]) {
- if(!can_add) {
- this.addproperty_checkboxes[i].disabled = true;
- }
- else {
- this.addproperty_checkboxes[i].disabled = false;
- show_modal = true;
- }
+ else if(!(i in this.editors)) {
+ if(!can_add) {
+ this.addproperty_checkboxes[i].disabled = true;
}
- else if(can_add) {
+ else {
+ this.addproperty_checkboxes[i].disabled = false;
show_modal = true;
}
}
else {
- if(this.addproperty_checkboxes && this.addproperty_checkboxes[i]) {
- this.addproperty_checkboxes[i].disabled = false;
- }
show_modal = true;
can_remove = true;
}
@@ -3143,13 +2979,12 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
}
// Additional addproperty checkboxes not tied to a current editor
- if(this.addproperty_checkboxes) {
- for(i in this.addproperty_checkboxes) {
- if(!this.addproperty_checkboxes.hasOwnProperty(i)) continue;
- if(this.editors[i]) continue;
- show_modal = true;
- this.addproperty_checkboxes[i].disabled = !can_add && !can_remove;
- }
+ for(i in this.schema.properties) {
+ if(!this.schema.properties.hasOwnProperty(i)) continue;
+ if(this.cached_editors[i]) continue;
+ show_modal = true;
+ this.addPropertyCheckbox(i);
+ this.addproperty_checkboxes[i].disabled = !can_add;
}
// If no editors can be added or removed, hide the modal button
@@ -3171,6 +3006,12 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
this.addproperty_add.disabled = false;
}
},
+ isRequired: function(editor) {
+ if(typeof editor.schema.required === "boolean") return editor.schema.required;
+ else if(Array.isArray(this.schema.required)) return this.schema.required.indexOf(editor.key) > -1;
+ else if(this.jsoneditor.options.required_by_default) return true;
+ else return false;
+ },
setValue: function(value, initial) {
var self = this;
value = value || {};
@@ -3178,22 +3019,18 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
if(typeof value !== "object" || Array.isArray(value)) value = {};
// First, set the values for all of the defined properties
- $each(this.editors, function(i,editor) {
+ $each(this.cached_editors, function(i,editor) {
+ // Value explicitly set
if(typeof value[i] !== "undefined") {
- // If property is removed, add property
- if(editor.property_removed) {
- self.addObjectProperty(i);
- }
-
+ self.addObjectProperty(i);
editor.setValue(value[i],initial);
}
+ // Otherwise, remove value unless this is the initial set or it's required
+ else if(!initial && !self.isRequired(editor)) {
+ self.removeObjectProperty(i);
+ }
+ // Otherwise, set the value to the default
else {
- // If property isn't required, remove property
- if(!initial && !editor.property_removed && !editor.isRequired()) {
- self.removeObjectProperty(i);
- return;
- }
-
editor.setValue(editor.getDefault(),initial);
}
});
@@ -3201,17 +3038,16 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
// If additional properties are allowed, create the editors for any of those
if(this.canHaveAdditionalProperties()) {
$each(value, function(i,val) {
- if(!self.editors[i]) {
+ if(!self.cached_editors[i]) {
self.addObjectProperty(i);
- if(self.editors[i]) {
- self.editors[i].setValue(val,initial);
- }
+ self.editors[i].setValue(val,initial);
}
});
}
this.refreshValue();
- this.jsoneditor.notifyWatchers(this.path);
+ this.notify();
+ this.layoutEditors();
},
showValidationErrors: function(errors) {
var self = this;
@@ -3245,7 +3081,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
}
// Show error for the table row if this is inside a table
- if(this.getOption('table_row')) {
+ if(this.options.table_row) {
if(my_errors.length) {
this.theme.addTableRowError(this.container);
}
@@ -3291,22 +3127,6 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
return info.width;
}
},
- addProperty: function() {
- this._super();
- this.row_holder.style.display = '';
- if(this.tabs_holder) this.tabs_holder.style.display = '';
- if(!this.collapsed) this.controls.style.display = '';
- this.title_controls.style.display = '';
- this.theme.enableHeader(this.title);
- },
- removeProperty: function() {
- this._super();
- this.row_holder.style.display = 'none';
- if(this.tabs_holder) this.tabs_holder.style.display = 'none';
- this.controls.style.display = 'none';
- this.title_controls.style.display = 'none';
- this.theme.disableHeader(this.title);
- },
enable: function() {
if(this.add_row_button) this.add_row_button.disabled = false;
if(this.remove_all_rows_button) this.remove_all_rows_button.disabled = false;
@@ -3339,16 +3159,20 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
}
this._super();
},
- build: function() {
+ preBuild: function() {
+ this._super();
+
this.rows = [];
this.row_cache = [];
- var self = this;
-
+
this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete;
this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder;
this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add;
+ },
+ build: function() {
+ var self = this;
- if(!this.getOption('compact',false)) {
+ if(!this.options.compact) {
this.header = document.createElement('span');
this.header.textContent = this.getTitle();
this.title = this.theme.getHeader(this.header);
@@ -3389,21 +3213,25 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
this.panel.appendChild(this.row_holder);
}
- this.row_holder.addEventListener('change_header_text',function() {
- self.refreshTabs(true);
- });
-
// Add controls
this.addControls();
-
- this.jsoneditor.notifyWatchers(this.path);
},
onChildEditorChange: function(editor) {
this.refreshValue();
+ this.refreshTabs(true);
this._super(editor);
},
getItemTitle: function() {
- return (this.schema.items && this.schema.items.title) || 'item';
+ if(!this.item_title) {
+ if(this.schema.items && !Array.isArray(this.schema.items)) {
+ var tmp = this.jsoneditor.expandRefs(this.schema.items);
+ this.item_title = tmp.title || 'item';
+ }
+ else {
+ this.item_title = 'item';
+ }
+ }
+ return this.item_title;
},
getItemSchema: function(i) {
if(Array.isArray(this.schema.items)) {
@@ -3427,7 +3255,6 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
}
},
getItemInfo: function(i) {
- // Get the schema for this item
var schema = this.getItemSchema(i);
// Check if it's cached
@@ -3435,42 +3262,25 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
var stringified = JSON.stringify(schema);
if(typeof this.item_info[stringified] !== "undefined") return this.item_info[stringified];
- // Create a temporary editor with this schema and get info
- var tmp = document.createElement('div');
- this.container.appendChild(tmp);
-
- // Ignore events on this temporary editor
- tmp.addEventListener('change_header_text',function(e) {
- e.preventDefault();
- e.stopPropagation();
- });
-
- var editor = this.jsoneditor.getEditorClass(schema, this.jsoneditor);
- editor = this.jsoneditor.createEditor(editor,{
- jsoneditor: this.jsoneditor,
- schema: schema,
- container: tmp,
- path: this.path+'.'+i,
- parent: this,
- required: true
- });
+ // Get the schema for this item
+ schema = this.jsoneditor.expandRefs(schema);
+
this.item_info[stringified] = {
- child_editors: editor.getChildEditors()? true : false,
- title: schema.title || 'item',
- width: editor.getNumColumns(),
- default: editor.getDefault()
+ title: schema.title || "item",
+ 'default': schema.default,
+ width: 12,
+ child_editors: schema.properties || schema.items
};
- editor.destroy();
- if(tmp.parentNode) tmp.parentNode.removeChild(tmp);
return this.item_info[stringified];
},
getElementEditor: function(i) {
var item_info = this.getItemInfo(i);
var schema = this.getItemSchema(i);
+ schema = this.jsoneditor.expandRefs(schema);
schema.title = item_info.title+' '+i;
- var editor = this.jsoneditor.getEditorClass(schema, this.jsoneditor);
+ var editor = this.jsoneditor.getEditorClass(schema);
var holder;
if(this.tabs_holder) {
@@ -3493,6 +3303,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
parent: this,
required: true
});
+ ret.preBuild();
+ ret.build();
+ ret.postBuild();
if(!ret.title_controls) {
ret.array_controls = this.theme.getButtonHolder();
@@ -3503,11 +3316,11 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
},
destroy: function() {
this.empty(true);
- if(this.title) this.title.parentNode.removeChild(this.title);
- if(this.description) this.description.parentNode.removeChild(this.description);
- if(this.row_holder) this.row_holder.parentNode.removeChild(this.row_holder);
- if(this.controls) this.controls.parentNode.removeChild(this.controls);
- if(this.panel) this.panel.parentNode.removeChild(this.panel);
+ if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title);
+ if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
+ if(this.row_holder && this.row_holder.parentNode) this.row_holder.parentNode.removeChild(this.row_holder);
+ if(this.controls && this.controls.parentNode) this.controls.parentNode.removeChild(this.controls);
+ if(this.panel && this.panel.parentNode) this.panel.parentNode.removeChild(this.panel);
this.rows = this.row_cache = this.title = this.description = this.row_holder = this.panel = this.controls = null;
@@ -3710,7 +3523,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
}
if(!this.collapsed && controls_needed) {
- this.controls.style.display = '';
+ this.controls.style.display = 'inline-block';
}
else {
this.controls.style.display = 'none';
@@ -3977,14 +3790,6 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
});
JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
- addProperty: function() {
- this._super();
- if(this.value.length) this.table.style.display = '';
- },
- removeProperty: function() {
- this._super();
- this.table.style.display = 'none';
- },
register: function() {
this._super();
if(this.rows) {
@@ -4004,16 +3809,17 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
getNumColumns: function() {
return Math.max(Math.min(12,this.width),3);
},
+ preBuild: function() {
+ var item_schema = this.jsoneditor.expandRefs(this.schema.items || {});
+
+ this.item_title = item_schema.title || 'row';
+ this.item_default = item_schema.default || null;
+ this.item_has_child_editors = item_schema.properties || item_schema.items;
+ this.width = 12;
+ this._super();
+ },
build: function() {
- this.rows = [];
var self = this;
-
- this.schema.items = this.schema.items || [];
-
- this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete;
- this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder;
- this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add;
-
this.table = this.theme.getTable();
this.container.appendChild(this.table);
this.thead = this.theme.getTableHead();
@@ -4026,15 +3832,9 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
// Determine the default value of array element
var tmp = this.getElementEditor(0,true);
this.item_default = tmp.getDefault();
- this.item_title = this.schema.items.title || 'row';
this.width = tmp.getNumColumns();
-
- // Build header row for table
- if(tmp.getChildEditors()) {
- this.item_has_child_editors = true;
- }
- if(!this.getOption('compact',false)) {
+ if(!this.options.compact) {
this.title = this.theme.getHeader(this.getTitle());
this.container.appendChild(this.title);
this.title_controls = this.theme.getHeaderButtonHolder();
@@ -4077,8 +3877,6 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
// Add controls
this.addControls();
-
- this.jsoneditor.notifyWatchers(this.path);
},
onChildEditorChange: function(editor) {
this.refreshValue();
@@ -4100,13 +3898,6 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
row.appendChild(holder);
}
- if(ignore) {
- holder.addEventListener('change_header_text',function(e) {
- e.preventDefault();
- e.stopPropagation();
- });
- }
-
var ret = this.jsoneditor.createEditor(editor,{
jsoneditor: this.jsoneditor,
schema: schema_copy,
@@ -4116,23 +3907,29 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
compact: true,
table_row: true
});
+
+ ret.preBuild();
+ if(!ignore) {
+ ret.build();
+ ret.postBuild();
- ret.controls_cell = row.appendChild(this.theme.getTableCell());
- ret.row = row;
- ret.table_controls = this.theme.getButtonHolder();
- ret.controls_cell.appendChild(ret.table_controls);
- ret.table_controls.style.margin = 0;
- ret.table_controls.style.padding = 0;
+ ret.controls_cell = row.appendChild(this.theme.getTableCell());
+ ret.row = row;
+ ret.table_controls = this.theme.getButtonHolder();
+ ret.controls_cell.appendChild(ret.table_controls);
+ ret.table_controls.style.margin = 0;
+ ret.table_controls.style.padding = 0;
+ }
return ret;
},
destroy: function() {
this.innerHTML = '';
- if(this.title) this.title.parentNode.removeChild(this.title);
- if(this.description) this.description.parentNode.removeChild(this.description);
+ if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title);
+ if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
if(this.row_holder && this.row_holder.parentNode) this.row_holder.parentNode.removeChild(this.row_holder);
- this.table.parentNode.removeChild(this.table);
- if(this.panel) this.panel.parentNode.removeChild(this.panel);
+ if(this.table && this.table.parentNode) this.table.parentNode.removeChild(this.table);
+ if(this.panel && this.panel.parentNode) this.panel.parentNode.removeChild(this.panel);
this.rows = this.title = this.description = this.row_holder = this.table = this.panel = null;
@@ -4391,34 +4188,36 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
this.collapsed = false;
this.toggle_button = this.getButton('','collapse','Collapse');
- this.title_controls.appendChild(this.toggle_button);
- this.toggle_button.addEventListener('click',function(e) {
- e.preventDefault();
- e.stopPropagation();
-
- if(self.collapsed) {
- self.collapsed = false;
- self.panel.style.display = '';
- self.setButtonText(this,'','collapse','Collapse');
- }
- else {
- self.collapsed = true;
- self.panel.style.display = 'none';
- self.setButtonText(this,'','expand','Expand');
+ if(this.title_controls) {
+ this.title_controls.appendChild(this.toggle_button);
+ this.toggle_button.addEventListener('click',function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ if(self.collapsed) {
+ self.collapsed = false;
+ self.panel.style.display = '';
+ self.setButtonText(this,'','collapse','Collapse');
+ }
+ else {
+ self.collapsed = true;
+ self.panel.style.display = 'none';
+ self.setButtonText(this,'','expand','Expand');
+ }
+ });
+
+ // If it should start collapsed
+ if(this.options.collapsed) {
+ $trigger(this.toggle_button,'click');
}
- });
- // If it should start collapsed
- if(this.options.collapsed) {
- $trigger(this.toggle_button,'click');
- }
-
- // Collapse button disabled
- if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") {
- if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none';
- }
- else if(this.jsoneditor.options.disable_collapse) {
- this.toggle_button.style.display = 'none';
+ // Collapse button disabled
+ if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") {
+ if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none';
+ }
+ else if(this.jsoneditor.options.disable_collapse) {
+ this.toggle_button.style.display = 'none';
+ }
}
// Add "new row" and "delete last" buttons below editor
@@ -4463,9 +4262,6 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
// Multiple Editor (for when `type` is an array)
JSONEditor.defaults.editors.multiple = JSONEditor.AbstractEditor.extend({
- getDefault: function() {
- return this.schema.default || null;
- },
register: function() {
if(this.editors) {
for(var i=0; i 2) {
$(this.input).select2();
}
-
- this.register();
-
- self.theme.afterInputReady(self.input);
- this.jsoneditor.notifyWatchers(this.path);
+ },
+ postBuild: function() {
+ this._super();
+ this.theme.afterInputReady(this.input);
},
enable: function() {
if(!this.always_disabled) this.input.disabled = false;
@@ -5042,46 +4813,48 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
this._super();
},
destroy: function() {
- if(this.label) this.label.parentNode.removeChild(this.label);
- if(this.description) this.description.parentNode.removeChild(this.description);
- this.input.parentNode.removeChild(this.input);
+ if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
+ if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
+ if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
this._super();
}
});
JSONEditor.defaults.editors.multiselect = JSONEditor.AbstractEditor.extend({
- getDefault: function() {
- return [];
- },
- build: function() {
- var self = this, i;
- if(!this.getOption('compact',false)) this.header = this.label = this.theme.getFormInputLabel(this.getTitle());
- if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description);
+ preBuild: function() {
+ this._super();
this.select_options = {};
this.select_values = {};
- var e = this.schema.items.enum || [];
- var options = [];
+ var items_schema = this.jsoneditor.expandRefs(this.schema.items || {});
+
+ var e = items_schema.enum || [];
+ this.option_keys = [];
for(i=0; i HTML Editor
+/*! JSON Editor v0.7.0 - JSON Schema -> HTML Editor
* By Jeremy Dorn - https://github.com/jdorn/json-editor/
* Released under the MIT license
*
- * Date: 2014-06-29
+ * Date: 2014-07-13
*/
-!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=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+" ":""}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},getTab:function(a){var b=document.createElement("li"),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="tab-pane active",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.bootstrap3=f.AbstractTheme.extend({getSelectInput:function(a){var b=this._super(a);return b.className+="form-control",b},setGridColumnSize:function(a,b){a.className="col-md-"+b},afterInputReady:function(a){a.controlgroup||(a.controlgroup=this.closest(a,".form-group"),this.closest(a,".compact")&&(a.controlgroup.style.marginBottom=0))},getTextareaInput:function(){var a=document.createElement("textarea");return a.className="form-control",a},getRangeInput:function(a,b,c){return this._super(a,b,c)},getFormInputField:function(a){var b=this._super(a);return"checkbox"!==a&&(b.className+="form-control"),b},getFormControl:function(a,b,c){var d=document.createElement("div");return a&&"checkbox"===b.type?(d.className+=" checkbox",a.appendChild(b),a.style.fontSize="14px",d.style.marginTop="0",d.appendChild(a),b.style.position="relative",b.style.float="left"):(d.className+=" form-group",a&&(a.className+=" control-label",d.appendChild(a)),d.appendChild(b)),c&&d.appendChild(c),d},getIndentedPanel:function(){var a=document.createElement("div");return a.className="well well-sm",a},getFormInputDescription:function(a){var b=document.createElement("p");return b.className="help-block",b.textContent=a,b},getHeaderButtonHolder:function(){var a=this.getButtonHolder();return a.style.marginLeft="10px",a},getButtonHolder:function(){var a=document.createElement("div");return a.className="btn-group",a},getButton:function(a,b,c){var d=this._super(a,b,c);return d.className+="btn btn-default",d},getTable:function(){var a=document.createElement("table");return a.className="table table-bordered",a.style.width="auto",a.style.maxWidth="none",a},addInputError:function(a,b){a.controlgroup&&(a.controlgroup.className+=" has-error",a.errmsg?a.errmsg.style.display="":(a.errmsg=document.createElement("p"),a.errmsg.className="help-block errormsg",a.controlgroup.appendChild(a.errmsg)),a.errmsg.textContent=b)},removeInputError:function(a){a.errmsg&&(a.errmsg.style.display="none",a.controlgroup.className=a.controlgroup.className.replace(/\s?has-error/g,""))},getTabHolder:function(){var a=document.createElement("div");return a.innerHTML="
",a.className="rows",a},getTab:function(a){var b=document.createElement("a");return b.className="list-group-item",b.setAttribute("href","#"),b.appendChild(a),b},markTabActive:function(a){a.className+=" active"},markTabInactive:function(a){a.className=a.className.replace(/\s?active/g,"")}}),f.defaults.themes.foundation=f.AbstractTheme.extend({getChildEditorHolder:function(){var a=document.createElement("div");return a.style.marginBottom="15px",a},getSelectInput:function(a){var b=this._super(a);return b.style.minWidth="none",b.style.padding="5px",b.style.marginTop="3px",b},getSwitcher:function(a){var b=this._super(a);return b.style.paddingRight="8px",b},afterInputReady:function(a){this.closest(a,".compact")&&(a.style.marginBottom=0),a.group=this.closest(a,".form-control")},getFormInputLabel:function(a){var b=this._super(a);return b.style.display="inline-block",b},getFormInputField:function(a){var b=this._super(a);return b.style.width="100%",b.style.marginBottom="checkbox"===a?"0":"12px",b},getFormInputDescription:function(a){var b=document.createElement("p");return b.textContent=a,b.style.marginTop="-10px",b.style.fontStyle="italic",b},getIndentedPanel:function(){var a=document.createElement("div");return a.className="panel",a},getHeaderButtonHolder:function(){var a=this.getButtonHolder();return a.style.display="inline-block",a.style.marginLeft="10px",a.style.verticalAlign="middle",a},getButtonHolder:function(){var a=document.createElement("div");return a.className="button-group",a},getButton:function(a,b,c){var d=this._super(a,b,c);return d.className+=" small button",d},addInputError:function(a,b){a.group&&(a.group.className+=" error",a.errmsg?a.errmsg.style.display="":(a.insertAdjacentHTML("afterend",' '),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){for(a=b({},a);a.$ref;){var c=a.$ref;delete a.$ref,a=this.extendSchemas(a,this.refs[c])}return a},expandSchema:function(a){var d,e=this,f=b({},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.not&&(a.not=this.expandSchema(a.not)),a.allOf){for(d=0;d=a.maximum?j.push({path:f,property:"maximum",message:this.translate("error_maximum_excl",[a.maximum])}):!a.exclusiveMaximum&&d>a.maximum&&j.push({path:f,property:"maximum",message:this.translate("error_maximum_incl",[a.maximum])})),a.minimum&&(a.exclusiveMinimum&&d<=a.minimum?j.push({path:f,property:"minimum",message:this.translate("error_minimum_excl",[a.minimum])}):!a.exclusiveMinimum&&da.maxLength&&j.push({path:f,property:"maxLength",message:this.translate("error_maxLength",[a.maxLength])}),a.minLength&&(d+"").lengtha.maxItems&&j.push({path:f,property:"maxItems",message:this.translate("error_maxItems",[a.maxItems])}),a.minItems&&d.lengtha.maxProperties&&j.push({path:f,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.notify())}if(this.link_watchers.length){a=this.getWatchedFieldValues();for(var d=0;d1&&(b[a]=c+" "+e[c])}),b},getOption:function(a){try{throw"getOption is deprecated"}catch(b){console.error(b)}return this.options[a]},showValidationErrors:function(){}}),e.defaults.editors.null=e.AbstractEditor.extend({getValue:function(){return null},setValue:function(){this.jsoneditor.notifyWatchers(this.path)},getNumColumns:function(){return 2}}),e.defaults.editors.string=e.AbstractEditor.extend({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)}}},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.options.compact||(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.options.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.theme.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.schema.template?(this.template=this.jsoneditor.compileTemplate(this.schema.template,this.template_engine),this.refreshValue()):this.refreshValue()},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},e.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({},e.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()),e.plugins.ace.theme&&this.ace_editor.setTheme("ace/theme/"+e.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&&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=this.schema.maxProperties),this.addproperty_checkboxes&&(this.addproperty_list.innerHTML=""),this.addproperty_checkboxes={};for(a in this.cached_editors)this.cached_editors.hasOwnProperty(a)&&(this.addPropertyCheckbox(a),this.isRequired(this.cached_editors[a])&&a in this.editors&&(this.addproperty_checkboxes[a].disabled=!0),"undefined"!=typeof this.schema.minProperties&&d<=this.schema.minProperties?(this.addproperty_checkboxes[a].disabled=this.addproperty_checkboxes[a].checked,this.addproperty_checkboxes[a].checked||(e=!0)):a in this.editors?(e=!0,c=!0):b?(this.addproperty_checkboxes[a].disabled=!1,e=!0):this.addproperty_checkboxes[a].disabled=!0);this.canHaveAdditionalProperties()&&(e=!0);for(a in this.schema.properties)this.schema.properties.hasOwnProperty(a)&&(this.cached_editors[a]||(e=!0,this.addPropertyCheckbox(a),this.addproperty_checkboxes[a].disabled=!b));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")},isRequired:function(a){return"boolean"==typeof a.schema.required?a.schema.required:Array.isArray(this.schema.required)?this.schema.required.indexOf(a.key)>-1:this.jsoneditor.options.required_by_default?!0:!1},setValue:function(a,b){var d=this;a=a||{},("object"!=typeof a||Array.isArray(a))&&(a={}),c(this.cached_editors,function(c,e){"undefined"!=typeof a[c]?(d.addObjectProperty(c),e.setValue(a[c],b)):b||d.isRequired(e)?e.setValue(e.getDefault(),b):d.removeObjectProperty(c)}),this.canHaveAdditionalProperties()&&c(a,function(a,c){d.cached_editors[a]||(d.addObjectProperty(a),d.editors[a].setValue(c,b))}),this.refreshValue(),this.notify(),this.layoutEditors()},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.options.table_row&&(d.length?this.theme.addTableRowError(this.container):this.theme.removeTableRowError(this.container)),c(this.editors,function(a,b){b.showValidationErrors(e)})}}),e.defaults.editors.array=e.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);return"undefined"!=typeof this.item_info[c]?this.item_info[c]:(b=this.jsoneditor.expandRefs(b),this.item_info[c]={title:b.title||"item","default":b.default,width:12,child_editors:b.properties||b.items},this.item_info[c])},getElementEditor:function(a){var b=this.getItemInfo(a),c=this.getItemSchema(a);c=this.jsoneditor.expandRefs(c),c.title=b.title+" "+a;var d,e=this.jsoneditor.getEditorClass(c);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.preBuild(),f.build(),f.postBuild(),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&&this.title.parentNode.removeChild(this.title),this.description&&this.description.parentNode&&this.description.parentNode.removeChild(this.description),this.row_holder&&this.row_holder.parentNode&&this.row_holder.parentNode.removeChild(this.row_holder),this.controls&&this.controls.parentNode&&this.controls.parentNode.removeChild(this.controls),this.panel&&this.panel.parentNode&&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?"inline-block":"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)})}}),e.defaults.editors.table=e.defaults.editors.array.extend({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&&(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)}}),e.defaults.editors.multiple=e.AbstractEditor.extend({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+" ":""}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&&this.display_area.parentNode&&this.display_area.parentNode.removeChild(this.display_area),this.title&&this.title.parentNode&&this.title.parentNode.removeChild(this.title),this.switcher&&this.switcher.parentNode&&this.switcher.parentNode.removeChild(this.switcher),this._super()}}),e.defaults.editors.select=e.AbstractEditor.extend({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(){if(!this.enum_options)return 3;for(var a=this.getTitle().length,b=0;b2&&$(this.input).select2()},postBuild:function(){this._super(),this.theme.afterInputReady(this.input)},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&&this.label.parentNode.removeChild(this.label),this.description&&this.description.parentNode&&this.description.parentNode.removeChild(this.description),this.input&&this.input.parentNode&&this.input.parentNode.removeChild(this.input),this._super()}}),e.defaults.editors.multiselect=e.AbstractEditor.extend({preBuild:function(){this._super(),this.select_options={},this.select_values={};var a=this.jsoneditor.expandRefs(this.schema.items||{}),b=a.enum||[];for(this.option_keys=[],f=0;fType: "+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&&this.preview.parentNode&&this.preview.parentNode.removeChild(this.preview),this.title&&this.title.parentNode&&this.title.parentNode.removeChild(this.title),this.input&&this.input.parentNode&&this.input.parentNode.removeChild(this.input),this.uploader&&this.uploader.parentNode&&this.uploader.parentNode.removeChild(this.uploader),this._super()}}),e.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},getTab:function(a){var b=document.createElement("li"),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="tab-pane active",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)}}),e.defaults.themes.bootstrap3=e.AbstractTheme.extend({getSelectInput:function(a){var b=this._super(a);return b.className+="form-control",b},setGridColumnSize:function(a,b){a.className="col-md-"+b},afterInputReady:function(a){a.controlgroup||(a.controlgroup=this.closest(a,".form-group"),this.closest(a,".compact")&&(a.controlgroup.style.marginBottom=0))},getTextareaInput:function(){var a=document.createElement("textarea");return a.className="form-control",a},getRangeInput:function(a,b,c){return this._super(a,b,c)},getFormInputField:function(a){var b=this._super(a);return"checkbox"!==a&&(b.className+="form-control"),b},getFormControl:function(a,b,c){var d=document.createElement("div");return a&&"checkbox"===b.type?(d.className+=" checkbox",a.appendChild(b),a.style.fontSize="14px",d.style.marginTop="0",d.appendChild(a),b.style.position="relative",b.style.float="left"):(d.className+=" form-group",a&&(a.className+=" control-label",d.appendChild(a)),d.appendChild(b)),c&&d.appendChild(c),d},getIndentedPanel:function(){var a=document.createElement("div");return a.className="well well-sm",a},getFormInputDescription:function(a){var b=document.createElement("p");return b.className="help-block",b.textContent=a,b},getHeaderButtonHolder:function(){var a=this.getButtonHolder();return a.style.marginLeft="10px",a},getButtonHolder:function(){var a=document.createElement("div");return a.className="btn-group",a},getButton:function(a,b,c){var d=this._super(a,b,c);return d.className+="btn btn-default",d},getTable:function(){var a=document.createElement("table");return a.className="table table-bordered",a.style.width="auto",a.style.maxWidth="none",a},addInputError:function(a,b){a.controlgroup&&(a.controlgroup.className+=" has-error",a.errmsg?a.errmsg.style.display="":(a.errmsg=document.createElement("p"),a.errmsg.className="help-block errormsg",a.controlgroup.appendChild(a.errmsg)),a.errmsg.textContent=b)},removeInputError:function(a){a.errmsg&&(a.errmsg.style.display="none",a.controlgroup.className=a.controlgroup.className.replace(/\s?has-error/g,""))},getTabHolder:function(){var a=document.createElement("div");return a.innerHTML="
",a.className="rows",a},getTab:function(a){var b=document.createElement("a");return b.className="list-group-item",b.setAttribute("href","#"),b.appendChild(a),b},markTabActive:function(a){a.className+=" active"},markTabInactive:function(a){a.className=a.className.replace(/\s?active/g,"")}}),e.defaults.themes.foundation=e.AbstractTheme.extend({getChildEditorHolder:function(){var a=document.createElement("div");return a.style.marginBottom="15px",a},getSelectInput:function(a){var b=this._super(a);return b.style.minWidth="none",b.style.padding="5px",b.style.marginTop="3px",b},getSwitcher:function(a){var b=this._super(a);return b.style.paddingRight="8px",b},afterInputReady:function(a){this.closest(a,".compact")&&(a.style.marginBottom=0),a.group=this.closest(a,".form-control")},getFormInputLabel:function(a){var b=this._super(a);return b.style.display="inline-block",b},getFormInputField:function(a){var b=this._super(a);return b.style.width="100%",b.style.marginBottom="checkbox"===a?"0":"12px",b},getFormInputDescription:function(a){var b=document.createElement("p");return b.textContent=a,b.style.marginTop="-10px",b.style.fontStyle="italic",b},getIndentedPanel:function(){var a=document.createElement("div");return a.className="panel",a},getHeaderButtonHolder:function(){var a=this.getButtonHolder();return a.style.display="inline-block",a.style.marginLeft="10px",a.style.verticalAlign="middle",a},getButtonHolder:function(){var a=document.createElement("div");return a.className="button-group",a},getButton:function(a,b,c){var d=this._super(a,b,c);return d.className+=" small button",d},addInputError:function(a,b){a.group&&(a.group.className+=" error",a.errmsg?a.errmsg.style.display="":(a.insertAdjacentHTML("afterend",' '),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")}}),e.defaults.themes.foundation3=e.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)}}),e.defaults.themes.foundation4=e.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}}),e.defaults.themes.foundation5=e.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)}}),e.defaults.themes.html=e.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")}}),e.defaults.themes.jqueryui=e.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"}}),e.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}}),e.defaults.iconlibs.bootstrap2=e.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-"}),e.defaults.iconlibs.bootstrap3=e.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-"}),e.defaults.iconlibs.fontawesome3=e.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-"}),e.defaults.iconlibs.fontawesome4=e.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-"}),e.defaults.iconlibs.foundation2=e.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-"}),e.defaults.iconlibs.foundation3=e.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-"}),e.defaults.iconlibs.jqueryui=e.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-"}),e.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}}}},e.defaults.templates.ejs=function(){return window.EJS?{compile:function(a){var b=new EJS({text:a});return function(a){return b.render(a)}}}:!1},e.defaults.templates.handlebars=function(){return window.Handlebars},e.defaults.templates.hogan=function(){return window.Hogan?{compile:function(a){var b=Hogan.compile(a);return function(a){return b.render(a)}}}:!1},e.defaults.templates.markup=function(){return window.Mark&&window.Mark.up?{compile:function(a){return function(b){return Mark.up(a,b)}}}:!1},e.defaults.templates.mustache=function(){return window.Mustache?{compile:function(a){return function(b){return Mustache.render(a,b)}}}:!1},e.defaults.templates.swig=function(){return window.swig},e.defaults.templates.underscore=function(){return window._?{compile:function(a){return function(b){return _.template(a,b)}}}:!1},e.defaults.theme="html",e.defaults.template="default",e.defaults.options={},e.defaults.translate=function(a,b){var c=e.defaults.languages[e.defaults.language];if(!c)throw"Unknown language "+e.defaults.language;var d=c[a]||e.defaults.languages[e.defaults.default_language][a];if("undefined"==typeof d)throw"Unknown translate string "+a;if(b)for(var f=0;f=0?"multiselect":void 0}),e.defaults.resolvers.unshift(function(a){return a.oneOf?"multiple":void 0}),(window.jQuery||window.Zepto)&&(window.$=window.$||{},$.jsoneditor=e.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 e(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=e}();
\ No newline at end of file
diff --git a/examples/recursive.html b/examples/recursive.html
new file mode 100644
index 000000000..01e9bddfd
--- /dev/null
+++ b/examples/recursive.html
@@ -0,0 +1,172 @@
+
+
+
+
+ Recursive JSON Editor Example
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Recursive JSON Editor Example
+
+
+ This example demonstrates the many ways you can use recursive schemas (aka self-referential or circular schemas).
+
+
+ Within array items as long as minLength is 0. See "coworkers" below.
+ In non-default properties. See "mother" below (click the "object properties" button and check "mother")
+ In oneOf as long as it's not the 1st choice. See "bestFriend" below.
+ In patternProperties. Try adding the property "cousin_1" using the "object properties" button.
+
+
+
+
+
+ Submit (console.log)
+ Restore to Default
+ Disable/Enable Form
+
+
+
+
+
+
+
+
+
diff --git a/src/core.js b/src/core.js
index ecf584a72..7c808a532 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,27 +28,23 @@ 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);
self.root = self.createEditor(editor_class, {
jsoneditor: self,
schema: self.schema,
- container: self.root_container,
- required: true
+ required: true,
+ container: self.root_container
});
+
+ self.root.preBuild();
+ self.root.build();
+ self.root.postBuild();
// Starting data
if(self.options.startval) self.root.setValue(self.options.startval);
@@ -142,9 +139,11 @@ JSONEditor.prototype = {
}
}
},
- getEditorClass: function(schema, editor) {
+ getEditorClass: function(schema) {
var classname;
+ schema = this.expandSchema(schema);
+
$each(JSONEditor.defaults.resolvers,function(i,resolver) {
var tmp = resolver(schema);
if(tmp) {
@@ -278,6 +277,258 @@ 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) {
+ schema = $extend({},schema);
+
+ while (schema.$ref) {
+ var ref = schema.$ref;
+ delete schema.$ref;
+ schema = this.extendSchemas(schema,this.refs[ref]);
+ }
+ return schema;
+ },
+ expandSchema: function(schema) {
+ var self = this;
+ var extended = $extend({},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);
+ }
+ });
+ }
+ // Version 4 `not`
+ if(schema.not) {
+ schema.not = this.expandSchema(schema.not);
+ }
+
+ // allOf schemas should be merged into the parent
+ if(schema.allOf) {
+ for(i=0; i= 0;
- }
-
- self.editors[key] = self.jsoneditor.createEditor(editor,{
- jsoneditor: self.jsoneditor,
- schema: schema,
- container: holder,
- path: self.path+'.'+key,
- parent: self,
- required: required
- });
-
- self.minwidth = Math.max(self.minwidth,self.editors[key].getNumColumns());
- self.maxwidth += self.editors[key].getNumColumns();
+ editor.setContainer(holder);
+ editor.build();
+ editor.postBuild();
});
// Control buttons
- this.title_controls = this.getTheme().getHeaderButtonHolder();
- this.editjson_controls = this.getTheme().getHeaderButtonHolder();
- this.addproperty_controls = this.getTheme().getHeaderButtonHolder();
+ this.title_controls = this.theme.getHeaderButtonHolder();
+ this.editjson_controls = this.theme.getHeaderButtonHolder();
+ this.addproperty_controls = this.theme.getHeaderButtonHolder();
this.title.appendChild(this.title_controls);
this.title.appendChild(this.editjson_controls);
this.title.appendChild(this.addproperty_controls);
@@ -369,28 +426,11 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
this.refreshAddProperties();
}
- // Sort editors by propertyOrder
- var sorted = {};
- var keys = Object.keys(this.editors);
- keys = keys.sort(function(a,b) {
- var ordera = self.editors[a].schema.propertyOrder;
- var orderb = self.editors[b].schema.propertyOrder;
- if(typeof ordera !== "number") ordera = 1000;
- if(typeof orderb !== "number") orderb = 1000;
-
- return ordera - orderb;
- });
- for(var i=0; i= this.schema.maxProperties);
+ if(this.addproperty_checkboxes) {
+ this.addproperty_list.innerHTML = '';
+ }
+ this.addproperty_checkboxes = {};
+
// Check for which editors can't be removed or added back
- for(i in this.editors) {
- if(!this.editors.hasOwnProperty(i)) continue;
- if(this.editors[i].isRequired()) {
- if(this.addproperty_checkboxes && this.addproperty_checkboxes[i]) {
- this.addproperty_checkboxes[i].disabled = true;
- }
+ for(i in this.cached_editors) {
+ if(!this.cached_editors.hasOwnProperty(i)) continue;
+
+ this.addPropertyCheckbox(i);
+
+ if(this.isRequired(this.cached_editors[i]) && i in this.editors) {
+ this.addproperty_checkboxes[i].disabled = true;
}
- else if(typeof this.schema.minProperties !== "undefined" && num_props <= this.schema.minProperties) {
- if(this.addproperty_checkboxes && this.addproperty_checkboxes[i]) {
- this.addproperty_checkboxes[i].disabled = this.addproperty_checkboxes[i].checked;
- if(!this.addproperty_checkboxes[i].checked) show_modal = true;
- }
- else if(this.editors[i].property_removed && can_add) {
- show_modal = true;
- }
+
+ if(typeof this.schema.minProperties !== "undefined" && num_props <= this.schema.minProperties) {
+ this.addproperty_checkboxes[i].disabled = this.addproperty_checkboxes[i].checked;
+ if(!this.addproperty_checkboxes[i].checked) show_modal = true;
}
- else if(this.editors[i].property_removed) {
- if(this.addproperty_checkboxes && this.addproperty_checkboxes[i]) {
- if(!can_add) {
- this.addproperty_checkboxes[i].disabled = true;
- }
- else {
- this.addproperty_checkboxes[i].disabled = false;
- show_modal = true;
- }
+ else if(!(i in this.editors)) {
+ if(!can_add) {
+ this.addproperty_checkboxes[i].disabled = true;
}
- else if(can_add) {
+ else {
+ this.addproperty_checkboxes[i].disabled = false;
show_modal = true;
}
}
else {
- if(this.addproperty_checkboxes && this.addproperty_checkboxes[i]) {
- this.addproperty_checkboxes[i].disabled = false;
- }
show_modal = true;
can_remove = true;
}
@@ -698,13 +689,12 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
}
// Additional addproperty checkboxes not tied to a current editor
- if(this.addproperty_checkboxes) {
- for(i in this.addproperty_checkboxes) {
- if(!this.addproperty_checkboxes.hasOwnProperty(i)) continue;
- if(this.editors[i]) continue;
- show_modal = true;
- this.addproperty_checkboxes[i].disabled = !can_add && !can_remove;
- }
+ for(i in this.schema.properties) {
+ if(!this.schema.properties.hasOwnProperty(i)) continue;
+ if(this.cached_editors[i]) continue;
+ show_modal = true;
+ this.addPropertyCheckbox(i);
+ this.addproperty_checkboxes[i].disabled = !can_add;
}
// If no editors can be added or removed, hide the modal button
@@ -726,6 +716,12 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
this.addproperty_add.disabled = false;
}
},
+ isRequired: function(editor) {
+ if(typeof editor.schema.required === "boolean") return editor.schema.required;
+ else if(Array.isArray(this.schema.required)) return this.schema.required.indexOf(editor.key) > -1;
+ else if(this.jsoneditor.options.required_by_default) return true;
+ else return false;
+ },
setValue: function(value, initial) {
var self = this;
value = value || {};
@@ -733,22 +729,18 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
if(typeof value !== "object" || Array.isArray(value)) value = {};
// First, set the values for all of the defined properties
- $each(this.editors, function(i,editor) {
+ $each(this.cached_editors, function(i,editor) {
+ // Value explicitly set
if(typeof value[i] !== "undefined") {
- // If property is removed, add property
- if(editor.property_removed) {
- self.addObjectProperty(i);
- }
-
+ self.addObjectProperty(i);
editor.setValue(value[i],initial);
}
+ // Otherwise, remove value unless this is the initial set or it's required
+ else if(!initial && !self.isRequired(editor)) {
+ self.removeObjectProperty(i);
+ }
+ // Otherwise, set the value to the default
else {
- // If property isn't required, remove property
- if(!initial && !editor.property_removed && !editor.isRequired()) {
- self.removeObjectProperty(i);
- return;
- }
-
editor.setValue(editor.getDefault(),initial);
}
});
@@ -756,17 +748,16 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
// If additional properties are allowed, create the editors for any of those
if(this.canHaveAdditionalProperties()) {
$each(value, function(i,val) {
- if(!self.editors[i]) {
+ if(!self.cached_editors[i]) {
self.addObjectProperty(i);
- if(self.editors[i]) {
- self.editors[i].setValue(val,initial);
- }
+ self.editors[i].setValue(val,initial);
}
});
}
this.refreshValue();
- this.jsoneditor.notifyWatchers(this.path);
+ this.notify();
+ this.layoutEditors();
},
showValidationErrors: function(errors) {
var self = this;
@@ -800,7 +791,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
}
// Show error for the table row if this is inside a table
- if(this.getOption('table_row')) {
+ if(this.options.table_row) {
if(my_errors.length) {
this.theme.addTableRowError(this.container);
}
diff --git a/src/editors/select.js b/src/editors/select.js
index dffc15197..9c685049e 100644
--- a/src/editors/select.js
+++ b/src/editors/select.js
@@ -1,7 +1,4 @@
JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
- getDefault: function() {
- return this.schema.default || '';
- },
setValue: function(value,initial) {
value = this.typecast(value||'');
@@ -30,6 +27,7 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
this.input.removeAttribute('name');
},
getNumColumns: function() {
+ if(!this.enum_options) return 3;
var longest_text = this.getTitle().length;
for(var i=0; i 2) {
$(this.input).select2();
}
-
- this.register();
-
- self.theme.afterInputReady(self.input);
- this.jsoneditor.notifyWatchers(this.path);
+ },
+ postBuild: function() {
+ this._super();
+ this.theme.afterInputReady(this.input);
},
enable: function() {
if(!this.always_disabled) this.input.disabled = false;
@@ -146,9 +133,9 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
this._super();
},
destroy: function() {
- if(this.label) this.label.parentNode.removeChild(this.label);
- if(this.description) this.description.parentNode.removeChild(this.description);
- this.input.parentNode.removeChild(this.input);
+ if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
+ if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
+ if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
this._super();
}
diff --git a/src/editors/string.js b/src/editors/string.js
index 14125fcc9..eb9e58f15 100644
--- a/src/editors/string.js
+++ b/src/editors/string.js
@@ -1,7 +1,4 @@
JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
- getDefault: function() {
- return this.schema.default || '';
- },
register: function() {
this._super();
if(!this.input) return;
@@ -60,18 +57,6 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
this.watch_listener();
this.jsoneditor.notifyWatchers(this.path);
},
- removeProperty: function() {
- this._super();
- this.input.style.display = 'none';
- if(this.description) this.description.style.display = 'none';
- this.theme.disableLabel(this.label);
- },
- addProperty: function() {
- this._super();
- this.input.style.display = '';
- if(this.description) this.description.style.display = '';
- this.theme.enableLabel(this.label);
- },
getNumColumns: function() {
var min = Math.ceil(this.getTitle().length/5);
var num;
@@ -84,7 +69,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
},
build: function() {
var self = this, i;
- if(!this.getOption('compact',false)) this.header = this.label = this.theme.getFormInputLabel(this.getTitle());
+ if(!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle());
if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description);
this.format = this.schema.format;
@@ -256,7 +241,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
if(typeof this.schema.pattern !== "undefined") this.input.setAttribute('pattern',this.schema.pattern);
else if(typeof this.schema.minLength !== "undefined") this.input.setAttribute('pattern','.{'+this.schema.minLength+',}');
- if(this.getOption('compact')) this.container.setAttribute('class',this.container.getAttribute('class')+' compact');
+ if(this.options.compact) this.container.setAttribute('class',this.container.getAttribute('class')+' compact');
if(this.schema.readOnly || this.schema.readonly || this.schema.template) {
this.always_disabled = true;
@@ -291,7 +276,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
if(this.format) this.input.setAttribute('data-schemaformat',this.format);
- this.control = this.getTheme().getFormControl(this.label, this.input, this.description);
+ this.control = this.theme.getFormControl(this.label, this.input, this.description);
this.container.appendChild(this.control);
// If the Select2 library is loaded
@@ -306,18 +291,14 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
// it will generate an error trying to append it to the missing parentNode
if(self.input.parentNode) self.afterInputReady();
});
-
- this.register();
// Compile and store the template
if(this.schema.template) {
this.template = this.jsoneditor.compileTemplate(this.schema.template, this.template_engine);
this.refreshValue();
- this.jsoneditor.notifyWatchers(this.path);
}
else {
this.refreshValue();
- this.jsoneditor.notifyWatchers(this.path);
}
},
enable: function() {
@@ -447,7 +428,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
this.template = null;
- if(this.input.parentNode) this.input.parentNode.removeChild(this.input);
+ if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
diff --git a/src/editors/table.js b/src/editors/table.js
index e357a2c51..4ca1dab44 100644
--- a/src/editors/table.js
+++ b/src/editors/table.js
@@ -1,12 +1,4 @@
JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
- addProperty: function() {
- this._super();
- if(this.value.length) this.table.style.display = '';
- },
- removeProperty: function() {
- this._super();
- this.table.style.display = 'none';
- },
register: function() {
this._super();
if(this.rows) {
@@ -26,16 +18,17 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
getNumColumns: function() {
return Math.max(Math.min(12,this.width),3);
},
+ preBuild: function() {
+ var item_schema = this.jsoneditor.expandRefs(this.schema.items || {});
+
+ this.item_title = item_schema.title || 'row';
+ this.item_default = item_schema.default || null;
+ this.item_has_child_editors = item_schema.properties || item_schema.items;
+ this.width = 12;
+ this._super();
+ },
build: function() {
- this.rows = [];
var self = this;
-
- this.schema.items = this.schema.items || [];
-
- this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete;
- this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder;
- this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add;
-
this.table = this.theme.getTable();
this.container.appendChild(this.table);
this.thead = this.theme.getTableHead();
@@ -48,15 +41,9 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
// Determine the default value of array element
var tmp = this.getElementEditor(0,true);
this.item_default = tmp.getDefault();
- this.item_title = this.schema.items.title || 'row';
this.width = tmp.getNumColumns();
-
- // Build header row for table
- if(tmp.getChildEditors()) {
- this.item_has_child_editors = true;
- }
- if(!this.getOption('compact',false)) {
+ if(!this.options.compact) {
this.title = this.theme.getHeader(this.getTitle());
this.container.appendChild(this.title);
this.title_controls = this.theme.getHeaderButtonHolder();
@@ -99,8 +86,6 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
// Add controls
this.addControls();
-
- this.jsoneditor.notifyWatchers(this.path);
},
onChildEditorChange: function(editor) {
this.refreshValue();
@@ -122,13 +107,6 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
row.appendChild(holder);
}
- if(ignore) {
- holder.addEventListener('change_header_text',function(e) {
- e.preventDefault();
- e.stopPropagation();
- });
- }
-
var ret = this.jsoneditor.createEditor(editor,{
jsoneditor: this.jsoneditor,
schema: schema_copy,
@@ -138,23 +116,29 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
compact: true,
table_row: true
});
-
- ret.controls_cell = row.appendChild(this.theme.getTableCell());
- ret.row = row;
- ret.table_controls = this.theme.getButtonHolder();
- ret.controls_cell.appendChild(ret.table_controls);
- ret.table_controls.style.margin = 0;
- ret.table_controls.style.padding = 0;
+
+ ret.preBuild();
+ if(!ignore) {
+ ret.build();
+ ret.postBuild();
+
+ ret.controls_cell = row.appendChild(this.theme.getTableCell());
+ ret.row = row;
+ ret.table_controls = this.theme.getButtonHolder();
+ ret.controls_cell.appendChild(ret.table_controls);
+ ret.table_controls.style.margin = 0;
+ ret.table_controls.style.padding = 0;
+ }
return ret;
},
destroy: function() {
this.innerHTML = '';
- if(this.title) this.title.parentNode.removeChild(this.title);
- if(this.description) this.description.parentNode.removeChild(this.description);
+ if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title);
+ if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
if(this.row_holder && this.row_holder.parentNode) this.row_holder.parentNode.removeChild(this.row_holder);
- this.table.parentNode.removeChild(this.table);
- if(this.panel) this.panel.parentNode.removeChild(this.panel);
+ if(this.table && this.table.parentNode) this.table.parentNode.removeChild(this.table);
+ if(this.panel && this.panel.parentNode) this.panel.parentNode.removeChild(this.panel);
this.rows = this.title = this.description = this.row_holder = this.table = this.panel = null;
@@ -413,34 +397,36 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
this.collapsed = false;
this.toggle_button = this.getButton('','collapse','Collapse');
- this.title_controls.appendChild(this.toggle_button);
- this.toggle_button.addEventListener('click',function(e) {
- e.preventDefault();
- e.stopPropagation();
-
- if(self.collapsed) {
- self.collapsed = false;
- self.panel.style.display = '';
- self.setButtonText(this,'','collapse','Collapse');
- }
- else {
- self.collapsed = true;
- self.panel.style.display = 'none';
- self.setButtonText(this,'','expand','Expand');
+ if(this.title_controls) {
+ this.title_controls.appendChild(this.toggle_button);
+ this.toggle_button.addEventListener('click',function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ if(self.collapsed) {
+ self.collapsed = false;
+ self.panel.style.display = '';
+ self.setButtonText(this,'','collapse','Collapse');
+ }
+ else {
+ self.collapsed = true;
+ self.panel.style.display = 'none';
+ self.setButtonText(this,'','expand','Expand');
+ }
+ });
+
+ // If it should start collapsed
+ if(this.options.collapsed) {
+ $trigger(this.toggle_button,'click');
}
- });
- // If it should start collapsed
- if(this.options.collapsed) {
- $trigger(this.toggle_button,'click');
- }
-
- // Collapse button disabled
- if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") {
- if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none';
- }
- else if(this.jsoneditor.options.disable_collapse) {
- this.toggle_button.style.display = 'none';
+ // Collapse button disabled
+ if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") {
+ if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none';
+ }
+ else if(this.jsoneditor.options.disable_collapse) {
+ this.toggle_button.style.display = 'none';
+ }
}
// Add "new row" and "delete last" buttons below editor
diff --git a/src/intro.js b/src/intro.js
index 226187772..6afc4757e 100644
--- a/src/intro.js
+++ b/src/intro.js
@@ -1,8 +1,8 @@
-/*! JSON Editor v0.6.19 - JSON Schema -> HTML Editor
+/*! JSON Editor v0.7.0 - JSON Schema -> HTML Editor
* By Jeremy Dorn - https://github.com/jdorn/json-editor/
* Released under the MIT license
*
- * Date: 2014-06-29
+ * Date: 2014-07-13
*/
/**
diff --git a/src/validator.js b/src/validator.js
index 63d0d6dde..4167de250 100644
--- a/src/validator.js
+++ b/src/validator.js
@@ -1,185 +1,9 @@
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);
- }
-
- return this;
- },
- getRefs: function() {
- var self = this;
- this._getRefs(this.original_schema, function(schema) {
- self.schema = schema;
- self.expanded = self.expandSchema(self.schema);
-
- self.is_ready = true;
- $each(self.ready_callbacks,function(i,callback) {
- callback.apply(self,[self.expanded]);
- });
- });
- },
- _getRefs: function(schema,callback,path,in_definitions) {
- 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);
-
- // 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);
- }
- };
-
- $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);
@@ -192,7 +16,7 @@ JSONEditor.Validator = Class.extend({
path = path || 'root';
// Work on a copy of the schema
- schema = $extend({},schema);
+ schema = $extend({},this.jsoneditor.expandRefs(schema));
/*
* Type Agnostic Validation
@@ -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();
});
});
});