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:
parent
9c23ca9791
commit
6403c0bd17
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -4168,25 +4168,29 @@ Node.prototype.showContextMenu = function (anchor, onClose) {
|
|||
}
|
||||
|
||||
if (this._hasChilds()) {
|
||||
items.push({
|
||||
text: translate('sort'),
|
||||
title: translate('sortTitle', {type: this.type}),
|
||||
className: 'jsoneditor-sort-asc',
|
||||
click: function () {
|
||||
var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
|
||||
showSortModal(node, anchor)
|
||||
}
|
||||
});
|
||||
if (this.editor.options.enableSort) {
|
||||
items.push({
|
||||
text: translate('sort'),
|
||||
title: translate('sortTitle', {type: this.type}),
|
||||
className: 'jsoneditor-sort-asc',
|
||||
click: function () {
|
||||
var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
|
||||
showSortModal(node, anchor)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
items.push({
|
||||
text: translate('transform'),
|
||||
title: translate('transformTitle', {type: this.type}),
|
||||
className: 'jsoneditor-transform',
|
||||
click: function () {
|
||||
var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
|
||||
showTransformModal(node, anchor)
|
||||
}
|
||||
});
|
||||
if (this.editor.options.enableTransform) {
|
||||
items.push({
|
||||
text: translate('transform'),
|
||||
title: translate('transformTitle', {type: this.type}),
|
||||
className: 'jsoneditor-transform',
|
||||
click: function () {
|
||||
var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
|
||||
showTransformModal(node, anchor)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.parent && this.parent._hasChilds()) {
|
||||
|
|
|
@ -163,7 +163,9 @@ treemode._setOptions = function (options) {
|
|||
}
|
||||
},
|
||||
timestampTag: true,
|
||||
onEvent: null
|
||||
onEvent: null,
|
||||
enableSort: true,
|
||||
enableTransform: true
|
||||
};
|
||||
|
||||
// copy all options
|
||||
|
@ -1001,26 +1003,30 @@ treemode._createFrame = function () {
|
|||
this.menu.appendChild(collapseAll);
|
||||
|
||||
// create sort button
|
||||
var sort = document.createElement('button');
|
||||
sort.type = 'button';
|
||||
sort.className = 'jsoneditor-sort';
|
||||
sort.title = translate('sortTitleShort');
|
||||
sort.onclick = function () {
|
||||
var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
|
||||
showSortModal(editor.node, anchor)
|
||||
};
|
||||
this.menu.appendChild(sort);
|
||||
if (this.options.enableSort) {
|
||||
var sort = document.createElement('button');
|
||||
sort.type = 'button';
|
||||
sort.className = 'jsoneditor-sort';
|
||||
sort.title = translate('sortTitleShort');
|
||||
sort.onclick = function () {
|
||||
var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
|
||||
showSortModal(editor.node, anchor)
|
||||
};
|
||||
this.menu.appendChild(sort);
|
||||
}
|
||||
|
||||
// create transform button
|
||||
var transform = document.createElement('button');
|
||||
transform.type = 'button';
|
||||
transform.title = translate('transformTitleShort');
|
||||
transform.className = 'jsoneditor-transform';
|
||||
transform.onclick = function () {
|
||||
var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
|
||||
showTransformModal(editor.node, anchor)
|
||||
};
|
||||
this.menu.appendChild(transform);
|
||||
if (this.options.enableTransform) {
|
||||
var transform = document.createElement('button');
|
||||
transform.type = 'button';
|
||||
transform.title = translate('transformTitleShort');
|
||||
transform.className = 'jsoneditor-transform';
|
||||
transform.onclick = function () {
|
||||
var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
|
||||
showTransformModal(editor.node, anchor)
|
||||
};
|
||||
this.menu.appendChild(transform);
|
||||
}
|
||||
|
||||
// create undo/redo buttons
|
||||
if (this.history) {
|
||||
|
|
Loading…
Reference in New Issue