diff --git a/docs/api.md b/docs/api.md index f908455..b0877a5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -233,16 +233,15 @@ Constructs a new JSONEditor. a JSON field or value. In case of field event, node information will be - `{field: String, path: [{name: String, type: String}]}`. + `{field: string, path: {string|number}[]}`. In case of value event, node information will be - `{field: String, path: [{name: String, type: String}], value: String}` + `{field: string, path: {string|number}[], value: string}` signature should be: ```js /** * @param {Node} the Node where event has been triggered - identified by {field: String, path: [{name: String, type: String}] [, - value: String]}` + identified by {field: string, path: {string|number}[] [, value: string]}` * @param {event} the event fired */ function onEvent(node, event) { diff --git a/src/js/Node.js b/src/js/Node.js index cd8a5da..f4b7019 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -90,7 +90,8 @@ Node.prototype._updateEditability = function () { /** * Get the path of this node - * @return {String[]} Array containing the path to this node + * @return {{string|number}[]} Array containing the path to this node. + * Element is a number if is the index of an array, a string otherwise. */ Node.prototype.getPath = function () { var node = this; @@ -2378,6 +2379,11 @@ Node.prototype.onEvent = function (event) { node = this, expandable = this._hasChilds(); + + if (typeof this.editor.options.onEvent === 'function') { + this._onEvent(event); + } + // check if mouse is on menu or on dragarea. // If so, highlight current row and its childs if (target == dom.drag || target == dom.menu) { @@ -2550,10 +2556,6 @@ Node.prototype.onEvent = function (event) { if (type == 'keydown') { this.onKeyDown(event); } - - if (typeof this.editor.options.onEvent === 'function') { - this._onEvent(event); - } }; /** @@ -2561,7 +2563,7 @@ Node.prototype.onEvent = function (event) { * value. * Information provided depends on the element, value is only included if * event occurs in a JSON value: - * {field: String, path: [{name: String, type: String}] [, value: String]} + * {field: string, path: {string|number}[] [, value: string]} * @param {Event} event * @private */