Adds ability to hide sort and transform options (#588)

* adds ability to hide sort and transform buttons

* adds new options to API doc

* cover context-menu sort, transform options; remove negations

* update readme wordings
This commit is contained in:
Tanmay Rajani 2018-10-19 00:12:02 +05:30 committed by Jos de Jong
parent 9c23ca9791
commit 6403c0bd17
4 changed files with 55 additions and 39 deletions

View File

@ -340,7 +340,6 @@ Constructs a new JSONEditor.
The default language comes from the browser navigator, but you can force a specific language. So use here string as 'en' or 'pt-BR'. Built-in languages: `en`, `pt-BR`. Other translations can be specified via the option `languages`.
- `{Object} languages`
You can override existing translations or provide a new translation for a specific language. To do it provide an object at languages with language and the keys/values to be inserted. For example:
@ -363,6 +362,13 @@ Constructs a new JSONEditor.
The container element where modals (like for sorting and filtering) are attached: an overlay will be created on top
of this container, and the modal will be created in the center of this container.
- `{boolean} enableSort`
Enable sorting of arrays and object properties. Only applicable for mode 'tree'. True by default.
- `{boolean} enableTransform`
Enable filtering, sorting, and transforming JSON using a [JMESPath](http://jmespath.org/) query. Only applicable for mode 'tree'. True by default.
### Methods

View File

@ -167,7 +167,7 @@ JSONEditor.VALID_OPTIONS = [
'colorPicker', 'onColorPicker',
'timestampTag',
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation',
'sortObjectKeys', 'navigationBar', 'statusBar', 'languages', 'language'
'sortObjectKeys', 'navigationBar', 'statusBar', 'languages', 'language', 'enableSort', 'enableTransform'
];
/**

View File

@ -4168,6 +4168,7 @@ Node.prototype.showContextMenu = function (anchor, onClose) {
}
if (this._hasChilds()) {
if (this.editor.options.enableSort) {
items.push({
text: translate('sort'),
title: translate('sortTitle', {type: this.type}),
@ -4177,7 +4178,9 @@ Node.prototype.showContextMenu = function (anchor, onClose) {
showSortModal(node, anchor)
}
});
}
if (this.editor.options.enableTransform) {
items.push({
text: translate('transform'),
title: translate('transformTitle', {type: this.type}),
@ -4188,6 +4191,7 @@ Node.prototype.showContextMenu = function (anchor, onClose) {
}
});
}
}
if (this.parent && this.parent._hasChilds()) {
if (items.length) {

View File

@ -163,7 +163,9 @@ treemode._setOptions = function (options) {
}
},
timestampTag: true,
onEvent: null
onEvent: null,
enableSort: true,
enableTransform: true
};
// copy all options
@ -1001,6 +1003,7 @@ treemode._createFrame = function () {
this.menu.appendChild(collapseAll);
// create sort button
if (this.options.enableSort) {
var sort = document.createElement('button');
sort.type = 'button';
sort.className = 'jsoneditor-sort';
@ -1010,8 +1013,10 @@ treemode._createFrame = function () {
showSortModal(editor.node, anchor)
};
this.menu.appendChild(sort);
}
// create transform button
if (this.options.enableTransform) {
var transform = document.createElement('button');
transform.type = 'button';
transform.title = translate('transformTitleShort');
@ -1021,6 +1026,7 @@ treemode._createFrame = function () {
showTransformModal(editor.node, anchor)
};
this.menu.appendChild(transform);
}
// create undo/redo buttons
if (this.history) {