Minor fix in _findTopLevelNodes

This commit is contained in:
jos 2015-12-30 11:23:22 +01:00
parent ceeb5e3357
commit f88e3d6f0c
2 changed files with 44 additions and 37 deletions

View File

@ -47,7 +47,7 @@ Node.prototype._updateEditability = function () {
var editable = this.editor.options.onEditable({
field: this.field,
value: this.value,
path: this.path()
path: this.getFieldsPath()
});
if (typeof editable === 'boolean') {
@ -66,7 +66,7 @@ Node.prototype._updateEditability = function () {
* Get the path of this node
* @return {String[]} Array containing the path to this node
*/
Node.prototype.path = function () {
Node.prototype.getFieldsPath = function () {
var node = this;
var path = [];
while (node) {

View File

@ -687,38 +687,6 @@ treemode._onMultiSelectStart = function (event) {
};
/**
* deselect currently selected nodes
*/
treemode.deselect = function () {
if (this.multiselect.nodes) {
this.multiselect.nodes.forEach(function (node) {
node.setSelected(false);
});
}
};
/**
* select nodes
* @param {Node[] | Node} nodes
*/
treemode.select = function (nodes) {
if (!Array.isArray(nodes)) {
return this.select([nodes]);
}
if (nodes) {
this.deselect();
this.multiselect.nodes = nodes.slice(0);
var first = nodes[0];
nodes.forEach(function (node) {
node.setSelected(true, node === first);
});
}
};
treemode._onMultiSelect = function (event) {
event.preventDefault();
@ -756,6 +724,38 @@ treemode._onMultiSelectEnd = function (event) {
}
};
/**
* deselect currently selected nodes
*/
treemode.deselect = function () {
if (this.multiselect.nodes) {
this.multiselect.nodes.forEach(function (node) {
node.setSelected(false);
});
}
};
/**
* select nodes
* @param {Node[] | Node} nodes
*/
treemode.select = function (nodes) {
if (!Array.isArray(nodes)) {
return this.select([nodes]);
}
if (nodes) {
this.deselect();
this.multiselect.nodes = nodes.slice(0);
var first = nodes[0];
nodes.forEach(function (node) {
node.setSelected(true, node === first);
});
}
};
/**
* From two arbitrary selected nodes, find their shared parent node.
* From that parent node, select the two child nodes in the brances going to
@ -778,9 +778,16 @@ treemode._findTopLevelNodes = function (start, end) {
if (!startChild || !endChild) {
// startChild or endChild are each others parents
startChild = root;
endChild = root;
root = root.parent
if (root.parent) {
startChild = root;
endChild = root;
root = root.parent
}
else {
// we have selected the root node (which doesn't have a parent)
startChild = root.childs[0];
endChild = root.childs[root.childs.length - 1];
}
}
if (root && startChild && endChild) {