* Renamed Node.getPath to Node.getNodePath, and renamed Node.getFieldsPath to Node.getPath

* Fixed Node.getPath for Arrays
This commit is contained in:
jos 2016-04-04 21:44:08 +02:00
parent 8f7b656c3c
commit f18d4519f8
2 changed files with 10 additions and 7 deletions

View File

@ -54,7 +54,7 @@ Node.prototype._updateEditability = function () {
var editable = this.editor.options.onEditable({ var editable = this.editor.options.onEditable({
field: this.field, field: this.field,
value: this.value, value: this.value,
path: this.getFieldsPath() path: this.getPath()
}); });
if (typeof editable === 'boolean') { if (typeof editable === 'boolean') {
@ -73,11 +73,14 @@ Node.prototype._updateEditability = function () {
* Get the path of this node * Get the path of this node
* @return {String[]} Array containing the path to this node * @return {String[]} Array containing the path to this node
*/ */
Node.prototype.getFieldsPath = function () { Node.prototype.getPath = function () {
var node = this; var node = this;
var path = []; var path = [];
while (node) { while (node) {
var field = node.field != undefined ? node.field : node.index; var field = (!node.parent || node.parent.type != 'array')
? node.field
: node.index;
if (field !== undefined) { if (field !== undefined) {
path.unshift(field); path.unshift(field);
} }
@ -372,8 +375,8 @@ Node.prototype.getLevel = function() {
* Get path of the root node till the current node * Get path of the root node till the current node
* @return {Node[]} Returns an array with nodes * @return {Node[]} Returns an array with nodes
*/ */
Node.prototype.getPath = function() { Node.prototype.getNodePath = function() {
var path = this.parent ? this.parent.getPath() : []; var path = this.parent ? this.parent.getNodePath() : [];
path.push(this); path.push(this);
return path; return path;
}; };

View File

@ -988,8 +988,8 @@ treemode.select = function (nodes) {
* @private * @private
*/ */
treemode._findTopLevelNodes = function (start, end) { treemode._findTopLevelNodes = function (start, end) {
var startPath = start.getPath(); var startPath = start.getNodePath();
var endPath = end.getPath(); var endPath = end.getNodePath();
var i = 0; var i = 0;
while (i < startPath.length && startPath[i] === endPath[i]) { while (i < startPath.length && startPath[i] === endPath[i]) {
i++; i++;