diff --git a/docs/api.md b/docs/api.md index c1534ac..adafe71 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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 diff --git a/src/js/JSONEditor.js b/src/js/JSONEditor.js index e455d37..db84ed5 100644 --- a/src/js/JSONEditor.js +++ b/src/js/JSONEditor.js @@ -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' ]; /** diff --git a/src/js/Node.js b/src/js/Node.js index 4d45ad6..9e2d34a 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -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()) { diff --git a/src/js/treemode.js b/src/js/treemode.js index 7f5ff51..bd5ebf7 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -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) {