json-editor
Advanced tools
Comparing version 0.7.23 to 0.7.25
@@ -10,8 +10,8 @@ 'use strict'; | ||
target: { | ||
files: { | ||
files: { | ||
'dist/jsoneditor.js': [ | ||
// License & version info, start the containing closure | ||
'src/intro.js', | ||
// Simple inheritance | ||
@@ -23,3 +23,3 @@ 'src/class.js', | ||
'src/utilities.js', | ||
// The main JSONEditor class | ||
@@ -30,3 +30,3 @@ 'src/core.js', | ||
'src/validator.js', | ||
// All the editors | ||
@@ -62,6 +62,6 @@ 'src/editor.js', | ||
'src/defaults.js', | ||
// Wrapper for $.fn style initialization | ||
'src/jquery.js', | ||
// End the closure | ||
@@ -100,6 +100,6 @@ 'src/outro.js' | ||
'src/ie9.js', | ||
// Utils like extend, each, and trigger | ||
'src/utilities.js', | ||
// The main JSONEditor class | ||
@@ -110,7 +110,7 @@ 'src/core.js', | ||
'src/validator.js', | ||
// All the editors | ||
'src/editor.js', | ||
'src/editors/*.js', | ||
// All the themes and iconlibs | ||
@@ -127,3 +127,3 @@ 'src/theme.js', | ||
'src/defaults.js', | ||
// Wrapper for $.fn style initialization | ||
@@ -130,0 +130,0 @@ 'src/jquery.js' |
@@ -5,3 +5,3 @@ { | ||
"description": "JSON Schema based editor", | ||
"version": "0.7.23", | ||
"version": "0.7.25", | ||
"main": "dist/jsoneditor.js", | ||
@@ -8,0 +8,0 @@ "author": { |
@@ -19,4 +19,8 @@ JSON Editor | ||
JSON Editor has no required dependencies. It only needs a modern browser (tested in Chrome and Firefox). | ||
JSON Schema has the following dependencies: | ||
* [math.js](http://mathjs.org/) for floating point math | ||
It needs a modern browser (tested in Chrome and Firefox). | ||
### Optional Requirements | ||
@@ -201,3 +205,3 @@ | ||
name.setValue("John Smith"); | ||
console.log(name.getValue()); | ||
@@ -210,3 +214,3 @@ } | ||
When feasible, JSON Editor won't let users enter invalid data. This is done by | ||
When feasible, JSON Editor won't let users enter invalid data. This is done by | ||
using input masks and intelligently enabling/disabling controls. | ||
@@ -303,2 +307,3 @@ | ||
* barebones | ||
* html (the default) | ||
@@ -310,7 +315,10 @@ * bootstrap2 | ||
* foundation5 | ||
* foundation6 | ||
* jqueryui | ||
The default theme is `html`, which doesn't use any special class names or styling. | ||
The default theme is `html`, which does not rely on an external framework. | ||
This default can be changed by setting the `JSONEditor.defaults.options.theme` variable. | ||
If you want to specify your own styles with CSS, you can use `barebones`, which includes almost no classes or inline styles. | ||
```javascript | ||
@@ -425,2 +433,18 @@ JSONEditor.defaults.options.theme = 'foundation5'; | ||
Make link download when clicked | ||
```js+jinja | ||
{ | ||
"title": "Document filename", | ||
"type": "string", | ||
"links": [ | ||
{ | ||
"rel": "Download File", | ||
"href": "/documents/{{self}}", | ||
// Can also set `download` to a string as per the HTML5 spec | ||
"download": true | ||
} | ||
] | ||
} | ||
``` | ||
Show a video preview (using HTML5 video) | ||
@@ -588,2 +612,3 @@ ```js+jinja | ||
* golang | ||
* groovy | ||
* handlebars | ||
@@ -738,3 +763,5 @@ * haskell | ||
* `disable_array_add` - If set to true, the "add row" button will be hidden (works for arrays) | ||
* `disable_array_delete` - If set to true, the "delete row" buttons will be hidden (works for arrays) | ||
* `disable_array_delete` - If set to true, all of the "delete" buttons will be hidden (works for arrays) | ||
* `disable_array_delete_all_rows` - If set to true, just the "delete all rows" button will be hidden (works for arrays) | ||
* `disable_array_delete_last_row` - If set to true, just the "delete last row" buttons will be hidden (works for arrays) | ||
* `disable_array_reorder` - If set to true, the "move up/down" buttons will be hidden (works for arrays) | ||
@@ -760,3 +787,3 @@ * `disable_collapse` - If set to true, the collapse button will be hidden (works for objects and arrays) | ||
"name": { | ||
"type": "string" | ||
"type": "string" | ||
} | ||
@@ -778,3 +805,3 @@ } | ||
The `dependencies` keyword from the JSON Schema specification is not nearly flexible enough to handle most use cases, | ||
The `dependencies` keyword from the JSON Schema specification is not nearly flexible enough to handle most use cases, | ||
so JSON Editor introduces a couple custom keywords that help in this regard. | ||
@@ -942,3 +969,3 @@ | ||
This is the most basic usage of `enumSource`. The more verbose form of this property supports | ||
This is the most basic usage of `enumSource`. The more verbose form of this property supports | ||
filtering, pulling from multiple sources, constant values, etc.. | ||
@@ -994,3 +1021,3 @@ Here's a more complex example (this uses the Swig template engine syntax to show some advanced features) | ||
The colors examples used an array of strings directly. Using the verbose form, you can | ||
The colors examples used an array of strings directly. Using the verbose form, you can | ||
also make it work with an array of objects. Here's an example: | ||
@@ -1056,3 +1083,3 @@ | ||
If one of the included template engines isn't sufficient, | ||
If one of the included template engines isn't sufficient, | ||
you can use any custom template engine with a `compile` method. For example: | ||
@@ -1091,6 +1118,6 @@ | ||
// Override a specific translation | ||
JSONEditor.defaults.languages.en.error_minLength = | ||
JSONEditor.defaults.languages.en.error_minLength = | ||
"This better be at least {{0}} characters long or else!"; | ||
// Create your own language mapping | ||
@@ -1127,3 +1154,3 @@ // Any keys not defined here will fall back to the "en" language | ||
} | ||
// If no valid editor is returned, the next resolver function will be used | ||
@@ -1214,5 +1241,5 @@ }); | ||
var value = $(this).jsoneditor('value'); | ||
value.name = "John Smith"; | ||
// Set the value | ||
@@ -1219,0 +1246,0 @@ $(this).jsoneditor('value',value); |
@@ -113,3 +113,3 @@ // Set the default theme | ||
*/ | ||
error_pattern: "Value must match the provided pattern", | ||
error_pattern: "Value must match the pattern {{0}}", | ||
/** | ||
@@ -157,3 +157,47 @@ * When an array has additional items whereas it is not supposed to | ||
*/ | ||
error_dependency: "Must have property {{0}}" | ||
error_dependency: "Must have property {{0}}", | ||
/** | ||
* Text on Delete All buttons | ||
*/ | ||
button_delete_all: "All", | ||
/** | ||
* Title on Delete All buttons | ||
*/ | ||
button_delete_all_title: "Delete All", | ||
/** | ||
* Text on Delete Last buttons | ||
* @variable This key takes one variable: The title of object to delete | ||
*/ | ||
button_delete_last: "Last {{0}}", | ||
/** | ||
* Title on Delete Last buttons | ||
* @variable This key takes one variable: The title of object to delete | ||
*/ | ||
button_delete_last_title: "Delete Last {{0}}", | ||
/** | ||
* Title on Add Row buttons | ||
* @variable This key takes one variable: The title of object to add | ||
*/ | ||
button_add_row_title: "Add {{0}}", | ||
/** | ||
* Title on Move Down buttons | ||
*/ | ||
button_move_down_title: "Move down", | ||
/** | ||
* Title on Move Up buttons | ||
*/ | ||
button_move_up_title: "Move up", | ||
/** | ||
* Title on Delete Row buttons | ||
* @variable This key takes one variable: The title of object to delete | ||
*/ | ||
button_delete_row_title: "Delete {{0}}", | ||
/** | ||
* Title on Delete Row buttons, short version (no parameter with the object title) | ||
*/ | ||
button_delete_row_title_short: "Delete", | ||
/** | ||
* Title on Collapse buttons | ||
*/ | ||
button_collapse: "Collapse" | ||
}; | ||
@@ -160,0 +204,0 @@ |
@@ -38,2 +38,4 @@ /** | ||
this.translate = this.jsoneditor.translate || JSONEditor.defaults.translate; | ||
this.original_schema = options.schema; | ||
@@ -179,3 +181,11 @@ this.schema = this.jsoneditor.expandSchema(this.original_schema); | ||
var href = this.jsoneditor.compileTemplate(data.href,this.template_engine); | ||
// Template to generate the link's download attribute | ||
var download = null; | ||
if(data.download) download = data.download; | ||
if(download && download !== true) { | ||
download = this.jsoneditor.compileTemplate(download, this.template_engine); | ||
} | ||
// Image links | ||
@@ -220,7 +230,7 @@ if(type === 'image') { | ||
else { | ||
holder = this.theme.getBlockLink(); | ||
link = holder = this.theme.getBlockLink(); | ||
holder.setAttribute('target','_blank'); | ||
holder.textContent = data.rel; | ||
// When a watched field changes, update the url | ||
// When a watched field changes, update the url | ||
this.link_watchers.push(function(vars) { | ||
@@ -232,3 +242,14 @@ var url = href(vars); | ||
} | ||
if(download && link) { | ||
if(download === true) { | ||
link.setAttribute('download',''); | ||
} | ||
else { | ||
this.link_watchers.push(function(vars) { | ||
link.setAttribute('download',download(vars)); | ||
}); | ||
} | ||
} | ||
return holder; | ||
@@ -235,0 +256,0 @@ }, |
@@ -70,2 +70,4 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({ | ||
this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete; | ||
this.hide_delete_all_rows_buttons = this.hide_delete_buttons || this.options.disable_array_delete_all_rows || this.jsoneditor.options.disable_array_delete_all_rows; | ||
this.hide_delete_last_row_buttons = this.hide_delete_buttons || this.options.disable_array_delete_last_row || this.jsoneditor.options.disable_array_delete_last_row; | ||
this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder; | ||
@@ -397,4 +399,4 @@ this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add; | ||
// If there are minItems items in the array, hide the delete button beneath the rows | ||
if(minItems || this.hide_delete_buttons) { | ||
// If there are minItems items in the array, or configured to hide the delete_last_row button, hide the delete button beneath the rows | ||
if(minItems || this.hide_delete_last_row_buttons) { | ||
this.delete_last_row_button.style.display = 'none'; | ||
@@ -408,9 +410,14 @@ } | ||
else { | ||
// If there are minItems items in the array, hide the delete button beneath the rows | ||
if(minItems || this.hide_delete_buttons) { | ||
if(minItems || this.hide_delete_last_row_buttons) { | ||
this.delete_last_row_button.style.display = 'none'; | ||
} | ||
else { | ||
this.delete_last_row_button.style.display = ''; | ||
controls_needed = true; | ||
} | ||
if(minItems || this.hide_delete_all_rows_buttons) { | ||
this.remove_all_rows_button.style.display = 'none'; | ||
} | ||
else { | ||
this.delete_last_row_button.style.display = ''; | ||
this.remove_all_rows_button.style.display = ''; | ||
@@ -463,3 +470,3 @@ controls_needed = true; | ||
if(!self.hide_delete_buttons) { | ||
self.rows[i].delete_button = this.getButton(self.getItemTitle(),'delete','Delete '+self.getItemTitle()); | ||
self.rows[i].delete_button = this.getButton(self.getItemTitle(),'delete',this.translate('button_delete_row_title',[self.getItemTitle()])); | ||
self.rows[i].delete_button.className += ' delete'; | ||
@@ -506,3 +513,3 @@ self.rows[i].delete_button.setAttribute('data-i',i); | ||
if(i && !self.hide_move_buttons) { | ||
self.rows[i].moveup_button = this.getButton('','moveup','Move up'); | ||
self.rows[i].moveup_button = this.getButton('','moveup',this.translate('button_move_up_title')); | ||
self.rows[i].moveup_button.className += ' moveup'; | ||
@@ -534,3 +541,3 @@ self.rows[i].moveup_button.setAttribute('data-i',i); | ||
if(!self.hide_move_buttons) { | ||
self.rows[i].movedown_button = this.getButton('','movedown','Move down'); | ||
self.rows[i].movedown_button = this.getButton('','movedown',this.translate('button_move_down_title')); | ||
self.rows[i].movedown_button.className += ' movedown'; | ||
@@ -567,3 +574,3 @@ self.rows[i].movedown_button.setAttribute('data-i',i); | ||
this.collapsed = false; | ||
this.toggle_button = this.getButton('','collapse','Collapse'); | ||
this.toggle_button = this.getButton('','collapse',this.translate('button_collapse')); | ||
this.title_controls.appendChild(this.toggle_button); | ||
@@ -607,3 +614,3 @@ var row_holder_display = self.row_holder.style.display; | ||
// Add "new row" and "delete last" buttons below editor | ||
this.add_row_button = this.getButton(this.getItemTitle(),'add','Add '+this.getItemTitle()); | ||
this.add_row_button = this.getButton(this.getItemTitle(),'add',this.translate('button_add_row_title',[this.getItemTitle()])); | ||
@@ -631,3 +638,3 @@ this.add_row_button.addEventListener('click',function(e) { | ||
this.delete_last_row_button = this.getButton('Last '+this.getItemTitle(),'delete','Delete Last '+this.getItemTitle()); | ||
this.delete_last_row_button = this.getButton(this.translate('button_delete_last',[this.getItemTitle()]),'delete',this.translate('button_delete_last_title',[this.getItemTitle()])); | ||
this.delete_last_row_button.addEventListener('click',function(e) { | ||
@@ -651,3 +658,3 @@ e.preventDefault(); | ||
this.remove_all_rows_button = this.getButton('All','delete','Delete All'); | ||
this.remove_all_rows_button = this.getButton(this.translate('button_delete_all'),'delete',this.translate('button_delete_all_title')); | ||
this.remove_all_rows_button.addEventListener('click',function(e) { | ||
@@ -654,0 +661,0 @@ e.preventDefault(); |
@@ -32,3 +32,3 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({ | ||
if(this.addproperty_button) this.addproperty_button.disabled = false; | ||
this._super(); | ||
@@ -46,3 +46,3 @@ if(this.editors) { | ||
this.hideEditJSON(); | ||
this._super(); | ||
@@ -58,3 +58,3 @@ if(this.editors) { | ||
var self = this, i, j; | ||
if(!this.row_container) return; | ||
@@ -72,5 +72,5 @@ | ||
}); | ||
var container; | ||
if(this.format === 'grid') { | ||
@@ -95,3 +95,3 @@ var rows = []; | ||
} | ||
// If there isn't a spot in any of the existing rows, start a new row | ||
@@ -107,3 +107,3 @@ if(found === false) { | ||
} | ||
rows[found].editors.push({ | ||
@@ -119,3 +119,3 @@ key: key, | ||
}); | ||
// Make almost full rows width 12 | ||
@@ -140,7 +140,7 @@ // Do this by increasing all editors' sizes proprotionately | ||
} | ||
// layout hasn't changed | ||
if(this.layout === JSON.stringify(rows)) return false; | ||
this.layout = JSON.stringify(rows); | ||
// Layout the form | ||
@@ -154,3 +154,3 @@ container = document.createElement('div'); | ||
var editor = this.editors[key]; | ||
if(editor.options.hidden) editor.container.style.display = 'none'; | ||
@@ -170,3 +170,3 @@ else this.theme.setGridColumnSize(editor.container,rows[i].editors[j].width); | ||
container.appendChild(row); | ||
if(editor.options.hidden) editor.container.style.display = 'none'; | ||
@@ -185,3 +185,3 @@ else self.theme.setGridColumnSize(editor.container,12); | ||
var matched = this.schema.properties[key]? true : false; | ||
// Any matching patternProperties should be merged in | ||
@@ -199,3 +199,3 @@ if(this.schema.patternProperties) { | ||
} | ||
// Hasn't matched other rules, use additionalProperties schema | ||
@@ -205,3 +205,3 @@ if(!matched && this.schema.additionalProperties && typeof this.schema.additionalProperties === "object") { | ||
} | ||
return schema; | ||
@@ -265,3 +265,3 @@ }, | ||
} | ||
// Sort editors by propertyOrder | ||
@@ -312,3 +312,3 @@ this.property_order = Object.keys(this.editors); | ||
this.container.style.position = 'relative'; | ||
// Edit JSON modal | ||
@@ -335,3 +335,3 @@ this.editjson_holder = this.theme.getModal(); | ||
this.editjson_holder.appendChild(this.editjson_cancel); | ||
// Manage Properties modal | ||
@@ -361,3 +361,3 @@ this.addproperty_holder = this.theme.getModal(); | ||
} | ||
self.addObjectProperty(self.addproperty_input.value); | ||
@@ -376,4 +376,4 @@ if(self.editors[self.addproperty_input.value]) { | ||
this.addproperty_holder.appendChild(spacer); | ||
// Description | ||
@@ -384,7 +384,7 @@ if(this.schema.description) { | ||
} | ||
// Validation error placeholder area | ||
this.error_holder = document.createElement('div'); | ||
this.container.appendChild(this.error_holder); | ||
// Container for child editor area | ||
@@ -438,3 +438,3 @@ this.editor_holder = this.theme.getIndentedPanel(); | ||
} | ||
// Collapse button disabled | ||
@@ -447,3 +447,3 @@ if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") { | ||
} | ||
// Edit JSON Button | ||
@@ -458,3 +458,3 @@ this.editjson_button = this.getButton('JSON','edit','Edit JSON'); | ||
this.editjson_controls.appendChild(this.editjson_holder); | ||
// Edit JSON Buttton disabled | ||
@@ -467,3 +467,3 @@ if(this.schema.options && typeof this.schema.options.disable_edit_json !== "undefined") { | ||
} | ||
// Object Properties Button | ||
@@ -480,3 +480,3 @@ this.addproperty_button = this.getButton('Properties','edit','Object Properties'); | ||
} | ||
// Fix table cell ordering | ||
@@ -500,3 +500,3 @@ if(this.options.table_row) { | ||
this.hideAddProperty(); | ||
// Position the form directly beneath the button | ||
@@ -506,9 +506,9 @@ // TODO: edge detection | ||
this.editjson_holder.style.top = this.editjson_button.offsetTop + this.editjson_button.offsetHeight+"px"; | ||
// Start the textarea with the current value | ||
this.editjson_textarea.value = JSON.stringify(this.getValue(),null,2); | ||
// Disable the rest of the form while editing JSON | ||
this.disable(); | ||
this.editjson_holder.style.display = ''; | ||
@@ -521,3 +521,3 @@ this.editjson_button.disabled = false; | ||
if(!this.editing_json) return; | ||
this.editjson_holder.style.display = 'none'; | ||
@@ -529,3 +529,3 @@ this.enable(); | ||
if(!this.editjson_holder) return; | ||
try { | ||
@@ -596,3 +596,3 @@ var json = JSON.parse(this.editjson_textarea.value); | ||
self.addproperty_checkboxes[key] = checkbox; | ||
return checkbox; | ||
@@ -603,3 +603,3 @@ }, | ||
this.hideEditJSON(); | ||
// Position the form directly beneath the button | ||
@@ -609,6 +609,6 @@ // TODO: edge detection | ||
this.addproperty_holder.style.top = this.addproperty_button.offsetTop + this.addproperty_button.offsetHeight+"px"; | ||
// Disable the rest of the form while editing JSON | ||
this.disable(); | ||
this.adding_property = true; | ||
@@ -622,6 +622,6 @@ this.addproperty_button.disabled = false; | ||
if(!this.adding_property) return; | ||
this.addproperty_holder.style.display = 'none'; | ||
this.enable(); | ||
this.adding_property = false; | ||
@@ -637,3 +637,3 @@ }, | ||
delete this.editors[property]; | ||
this.refreshValue(); | ||
@@ -645,6 +645,6 @@ this.layoutEditors(); | ||
var self = this; | ||
// Property is already added | ||
if(this.editors[name]) return; | ||
// Property was added before and is cached | ||
@@ -663,4 +663,4 @@ if(this.cached_editors[name]) { | ||
var schema = self.getPropertySchema(name); | ||
// Add the property | ||
@@ -676,3 +676,3 @@ var editor = self.jsoneditor.getEditorClass(schema); | ||
self.editors[name].preBuild(); | ||
if(!prebuild_only) { | ||
@@ -685,6 +685,6 @@ var holder = self.theme.getChildEditorHolder(); | ||
} | ||
self.cached_editors[name] = self.editors[name]; | ||
} | ||
// If we're only prebuilding the editors, don't refresh values | ||
@@ -735,3 +735,3 @@ if(!prebuild_only) { | ||
var self = this; | ||
for(var i in this.editors) { | ||
@@ -751,3 +751,3 @@ if(!this.editors.hasOwnProperty(i)) continue; | ||
var can_add = false, can_remove = false, num_props = 0, i, show_modal = false; | ||
// Get number of editors | ||
@@ -758,6 +758,6 @@ for(i in this.editors) { | ||
} | ||
// Determine if we can add back removed properties | ||
can_add = this.canHaveAdditionalProperties() && !(typeof this.schema.maxProperties !== "undefined" && num_props >= this.schema.maxProperties); | ||
if(this.addproperty_checkboxes) { | ||
@@ -767,13 +767,13 @@ this.addproperty_list.innerHTML = ''; | ||
this.addproperty_checkboxes = {}; | ||
// Check for which editors can't be removed or added back | ||
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; | ||
} | ||
if(typeof this.schema.minProperties !== "undefined" && num_props <= this.schema.minProperties) { | ||
@@ -797,7 +797,7 @@ this.addproperty_checkboxes[i].disabled = this.addproperty_checkboxes[i].checked; | ||
} | ||
if(this.canHaveAdditionalProperties()) { | ||
show_modal = true; | ||
} | ||
// Additional addproperty checkboxes not tied to a current editor | ||
@@ -810,3 +810,3 @@ for(i in this.schema.properties) { | ||
} | ||
// If no editors can be added or removed, hide the modal button | ||
@@ -840,3 +840,3 @@ if(!show_modal) { | ||
value = value || {}; | ||
if(typeof value !== "object" || Array.isArray(value)) value = {}; | ||
@@ -867,3 +867,3 @@ | ||
}); | ||
this.refreshValue(); | ||
@@ -870,0 +870,0 @@ this.layoutEditors(); |
@@ -120,2 +120,3 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({ | ||
'golang', | ||
'groovy', | ||
'handlebars', | ||
@@ -122,0 +123,0 @@ 'haskell', |
@@ -45,3 +45,3 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({ | ||
this.width = tmp.getNumColumns() + 2; | ||
if(!this.options.compact) { | ||
@@ -122,3 +122,3 @@ this.title = this.theme.getHeader(this.getTitle()); | ||
}); | ||
ret.preBuild(); | ||
@@ -136,3 +136,3 @@ if(!ignore) { | ||
} | ||
return ret; | ||
@@ -165,3 +165,3 @@ }, | ||
} | ||
var serialized = JSON.stringify(value); | ||
@@ -200,3 +200,3 @@ if(serialized === this.serialized) return; | ||
self.onChange(); | ||
// TODO: sortable | ||
@@ -206,6 +206,6 @@ }, | ||
var self = this; | ||
// If we currently have minItems items in the array | ||
var minItems = this.schema.minItems && this.schema.minItems >= this.rows.length; | ||
var need_row_buttons = false; | ||
@@ -234,3 +234,3 @@ $each(this.rows,function(i,editor) { | ||
} | ||
if(editor.moveup_button) { | ||
@@ -240,3 +240,3 @@ need_row_buttons = true; | ||
}); | ||
// Show/hide controls column in table | ||
@@ -257,5 +257,5 @@ $each(this.rows,function(i,editor) { | ||
} | ||
var controls_needed = false; | ||
if(!this.value.length) { | ||
@@ -266,8 +266,8 @@ this.delete_last_row_button.style.display = 'none'; | ||
} | ||
else if(this.value.length === 1 || this.hide_delete_buttons) { | ||
else if(this.value.length === 1) { | ||
this.table.style.display = ''; | ||
this.remove_all_rows_button.style.display = 'none'; | ||
// If there are minItems items in the array, hide the delete button beneath the rows | ||
if(minItems || this.hide_delete_buttons) { | ||
// If there are minItems items in the array, or configured to hide the delete_last_row button, hide the delete button beneath the rows | ||
if(minItems || this.hide_delete_last_row_buttons) { | ||
this.delete_last_row_button.style.display = 'none'; | ||
@@ -282,9 +282,15 @@ } | ||
this.table.style.display = ''; | ||
// If there are minItems items in the array, hide the delete button beneath the rows | ||
if(minItems || this.hide_delete_buttons) { | ||
if(minItems || this.hide_delete_last_row_buttons) { | ||
this.delete_last_row_button.style.display = 'none'; | ||
} | ||
else { | ||
this.delete_last_row_button.style.display = ''; | ||
controls_needed = true; | ||
} | ||
if(minItems || this.hide_delete_all_rows_buttons) { | ||
this.remove_all_rows_button.style.display = 'none'; | ||
} | ||
else { | ||
this.delete_last_row_button.style.display = ''; | ||
this.remove_all_rows_button.style.display = ''; | ||
@@ -303,3 +309,3 @@ controls_needed = true; | ||
} | ||
if(!controls_needed) { | ||
@@ -332,3 +338,3 @@ this.controls.style.display = 'none'; | ||
if(!this.hide_delete_buttons) { | ||
self.rows[i].delete_button = this.getButton('','delete','Delete'); | ||
self.rows[i].delete_button = this.getButton('','delete',this.translate('button_delete_row_title_short')); | ||
self.rows[i].delete_button.className += ' delete'; | ||
@@ -354,5 +360,5 @@ self.rows[i].delete_button.setAttribute('data-i',i); | ||
if(i && !this.hide_move_buttons) { | ||
self.rows[i].moveup_button = this.getButton('','moveup','Move up'); | ||
self.rows[i].moveup_button = this.getButton('','moveup',this.translate('button_move_up_title')); | ||
self.rows[i].moveup_button.className += ' moveup'; | ||
@@ -376,5 +382,5 @@ self.rows[i].moveup_button.setAttribute('data-i',i); | ||
} | ||
if(!this.hide_move_buttons) { | ||
self.rows[i].movedown_button = this.getButton('','movedown','Move down'); | ||
self.rows[i].movedown_button = this.getButton('','movedown',this.translate('button_move_down_title')); | ||
self.rows[i].movedown_button.className += ' movedown'; | ||
@@ -404,3 +410,3 @@ self.rows[i].movedown_button.setAttribute('data-i',i); | ||
this.collapsed = false; | ||
this.toggle_button = this.getButton('','collapse','Collapse'); | ||
this.toggle_button = this.getButton('','collapse',this.translate('button_collapse')); | ||
if(this.title_controls) { | ||
@@ -439,7 +445,7 @@ this.title_controls.appendChild(this.toggle_button); | ||
// Add "new row" and "delete last" buttons below editor | ||
this.add_row_button = this.getButton(this.getItemTitle(),'add','Add '+this.getItemTitle()); | ||
this.add_row_button = this.getButton(this.getItemTitle(),'add',this.translate('button_add_row_title',[this.getItemTitle()])); | ||
this.add_row_button.addEventListener('click',function(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
self.addRow(); | ||
@@ -452,7 +458,7 @@ self.refreshValue(); | ||
this.delete_last_row_button = this.getButton('Last '+this.getItemTitle(),'delete','Delete Last '+this.getItemTitle()); | ||
this.delete_last_row_button = this.getButton(this.translate('button_delete_last',[this.getItemTitle()]),'delete',this.translate('button_delete_last_title',[this.getItemTitle()])); | ||
this.delete_last_row_button.addEventListener('click',function(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
var rows = self.getValue(); | ||
@@ -465,7 +471,7 @@ rows.pop(); | ||
this.remove_all_rows_button = this.getButton('All','delete','Delete All'); | ||
this.remove_all_rows_button = this.getButton(this.translate('button_delete_all'),'delete',this.translate('button_delete_all_title')); | ||
this.remove_all_rows_button.addEventListener('click',function(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
self.setValue([]); | ||
@@ -472,0 +478,0 @@ self.onChange(true); |
@@ -1,6 +0,6 @@ | ||
/*! JSON Editor v0.7.23 - JSON Schema -> HTML Editor | ||
/*! JSON Editor v0.7.25 - JSON Schema -> HTML Editor | ||
* By Jeremy Dorn - https://github.com/jdorn/json-editor/ | ||
* Released under the MIT license | ||
* | ||
* Date: 2015-09-27 | ||
* Date: 2016-04-12 | ||
*/ | ||
@@ -7,0 +7,0 @@ |
@@ -70,3 +70,3 @@ // Base Foundation theme | ||
input.group.className += ' error'; | ||
if(!input.errmsg) { | ||
@@ -79,3 +79,3 @@ input.insertAdjacentHTML('afterend','<small class="error"></small>'); | ||
} | ||
input.errmsg.textContent = text; | ||
@@ -227,1 +227,63 @@ }, | ||
}); | ||
JSONEditor.defaults.themes.foundation6 = JSONEditor.defaults.themes.foundation5.extend({ | ||
getIndentedPanel: function() { | ||
var el = document.createElement('div'); | ||
el.className = 'callout secondary'; | ||
return el; | ||
}, | ||
getButtonHolder: function() { | ||
var el = document.createElement('div'); | ||
el.className = 'button-group tiny'; | ||
el.style.marginBottom = 0; | ||
return el; | ||
}, | ||
getFormInputLabel: function(text) { | ||
var el = this._super(text); | ||
el.style.display = 'block'; | ||
return el; | ||
}, | ||
getFormControl: function(label, input, description) { | ||
var el = document.createElement('div'); | ||
el.className = 'form-control'; | ||
if(label) el.appendChild(label); | ||
if(input.type === 'checkbox') { | ||
label.insertBefore(input,label.firstChild); | ||
} | ||
else if (label) { | ||
label.appendChild(input); | ||
} else { | ||
el.appendChild(input); | ||
} | ||
if(description) label.appendChild(description); | ||
return el; | ||
}, | ||
addInputError: function(input,text) { | ||
if(!input.group) return; | ||
input.group.className += ' error'; | ||
if(!input.errmsg) { | ||
var errorEl = document.createElement('span'); | ||
errorEl.className = 'form-error is-visible'; | ||
input.group.getElementsByTagName('label')[0].appendChild(errorEl); | ||
input.className = input.className + ' is-invalid-input'; | ||
input.errmsg = errorEl; | ||
} | ||
else { | ||
input.errmsg.style.display = ''; | ||
input.className = ''; | ||
} | ||
input.errmsg.textContent = text; | ||
}, | ||
removeInputError: function(input) { | ||
if(!input.errmsg) return; | ||
input.className = input.className.replace(/ is-invalid-input/g,''); | ||
if(input.errmsg.parentNode) { | ||
input.errmsg.parentNode.removeChild(input.errmsg); | ||
} | ||
}, | ||
}); |
@@ -211,8 +211,20 @@ JSONEditor.Validator = Class.extend({ | ||
if(schema.multipleOf || schema.divisibleBy) { | ||
valid = value / (schema.multipleOf || schema.divisibleBy); | ||
if(valid !== Math.floor(valid)) { | ||
var divisor = schema.multipleOf || schema.divisibleBy; | ||
// Vanilla JS, prone to floating point rounding errors (e.g. 1.14 / .01 == 113.99999) | ||
valid = (value/divisor === Math.floor(value/divisor)); | ||
// Use math.js is available | ||
if(window.math) { | ||
valid = window.math.mod(window.math.bignumber(value), window.math.bignumber(divisor)).equals(0); | ||
} | ||
// Use decimal.js is available | ||
else if(window.Decimal) { | ||
valid = (new window.Decimal(value)).mod(new window.Decimal(divisor)).equals(0); | ||
} | ||
if(!valid) { | ||
errors.push({ | ||
path: path, | ||
property: schema.multipleOf? 'multipleOf' : 'divisibleBy', | ||
message: this.translate('error_multipleOf', [schema.multipleOf || schema.divisibleBy]) | ||
message: this.translate('error_multipleOf', [divisor]) | ||
}); | ||
@@ -224,14 +236,25 @@ } | ||
if(schema.hasOwnProperty('maximum')) { | ||
if(schema.exclusiveMaximum && value >= schema.maximum) { | ||
errors.push({ | ||
path: path, | ||
property: 'maximum', | ||
message: this.translate('error_maximum_excl', [schema.maximum]) | ||
}); | ||
// Vanilla JS, prone to floating point rounding errors (e.g. .999999999999999 == 1) | ||
valid = schema.exclusiveMaximum? (value < schema.maximum) : (value <= schema.maximum); | ||
// Use math.js is available | ||
if(window.math) { | ||
valid = window.math[schema.exclusiveMaximum?'smaller':'smallerEq']( | ||
window.math.bignumber(value), | ||
window.math.bignumber(schema.maximum) | ||
); | ||
} | ||
else if(!schema.exclusiveMaximum && value > schema.maximum) { | ||
// Use Decimal.js if available | ||
else if(window.Decimal) { | ||
valid = (new window.Decimal(value))[schema.exclusiveMaximum?'lt':'lte'](new window.Decimal(schema.maximum)); | ||
} | ||
if(!valid) { | ||
errors.push({ | ||
path: path, | ||
property: 'maximum', | ||
message: this.translate('error_maximum_incl', [schema.maximum]) | ||
message: this.translate( | ||
(schema.exclusiveMaximum?'error_maximum_excl':'error_maximum_incl'), | ||
[schema.maximum] | ||
) | ||
}); | ||
@@ -243,14 +266,25 @@ } | ||
if(schema.hasOwnProperty('minimum')) { | ||
if(schema.exclusiveMinimum && value <= schema.minimum) { | ||
errors.push({ | ||
path: path, | ||
property: 'minimum', | ||
message: this.translate('error_minimum_excl', [schema.minimum]) | ||
}); | ||
// Vanilla JS, prone to floating point rounding errors (e.g. .999999999999999 == 1) | ||
valid = schema.exclusiveMinimum? (value > schema.minimum) : (value >= schema.minimum); | ||
// Use math.js is available | ||
if(window.math) { | ||
valid = window.math[schema.exclusiveMinimum?'larger':'largerEq']( | ||
window.math.bignumber(value), | ||
window.math.bignumber(schema.minimum) | ||
); | ||
} | ||
else if(!schema.exclusiveMinimum && value < schema.minimum) { | ||
// Use Decimal.js if available | ||
else if(window.Decimal) { | ||
valid = (new window.Decimal(value))[schema.exclusiveMinimum?'gt':'gte'](new window.Decimal(schema.minimum)); | ||
} | ||
if(!valid) { | ||
errors.push({ | ||
path: path, | ||
property: 'minimum', | ||
message: this.translate('error_minimum_incl', [schema.minimum]) | ||
message: this.translate( | ||
(schema.exclusiveMinimum?'error_minimum_excl':'error_minimum_incl'), | ||
[schema.minimum] | ||
) | ||
}); | ||
@@ -275,3 +309,3 @@ } | ||
if(schema.minLength) { | ||
if((value+"").length < schema.minLength) { | ||
if((value+"").length < schema.minLength) { | ||
errors.push({ | ||
@@ -291,3 +325,3 @@ path: path, | ||
property: 'pattern', | ||
message: this.translate('error_pattern') | ||
message: this.translate('error_pattern', [schema.pattern]) | ||
}); | ||
@@ -294,0 +328,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1055691
75
15132
1233