Skip to content

Commit d720298

Browse files
author
Stefan Mohr
committed
Conflicts: source/controllers/nodeCtrl.js
2 parents 90f87ea + 8541a2e commit d720298

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "angular-ui-tree",
33
"version": "2.9.0",
44
"description": "An AngularJS UI component that can sort nested lists, provides drag & drop support and doesn't depend on jQuery",
5+
"license": "MIT",
56
"repository": {
67
"type": "git",
78
"url": "https://github.com/angular-ui-tree/angular-ui-tree"

source/angular-ui-tree.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
}
1414

1515
.angular-ui-tree-nodes {
16-
display: block;
1716
position: relative;
1817
margin: 0;
1918
padding: 0;
@@ -25,7 +24,6 @@
2524
}
2625

2726
.angular-ui-tree-node, .angular-ui-tree-placeholder {
28-
display: block;
2927
position: relative;
3028
margin: 0;
3129
padding: 0;

source/controllers/nodeCtrl.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@
112112
return 1;
113113
};
114114

115-
function countSubDepth(scope) {
115+
/**
116+
* Returns the depth of the deepest subtree under this node
117+
* @param scope a TreeNodesController scope object
118+
* @returns Depth of all nodes *beneath* this node. If scope belongs to a leaf node, the
119+
* result is 0 (it has no subtree).
120+
*/
121+
function countSubTreeDepth(scope) {
116122
var thisLevelDepth = 0,
117123
childNodes = scope.childNodes(),
118124
childNode,
@@ -121,16 +127,16 @@
121127
if (!childNodes || childNodes.length === 0) {
122128
return 0;
123129
}
124-
for (i = 0; i < childNodes.length; i++) {
130+
for (i = childNodes.length - 1; i >= 0 ; i--) {
125131
childNode = childNodes[i],
126-
childDepth = 1 + countSubDepth(childNode);
132+
childDepth = 1 + countSubTreeDepth(childNode);
127133
thisLevelDepth = Math.max(thisLevelDepth, childDepth);
128134
}
129135
return thisLevelDepth;
130136
}
131137

132138
$scope.maxSubDepth = function () {
133-
return $scope.$childNodesScope ? countSubDepth($scope.$childNodesScope) : 0;
139+
return $scope.$childNodesScope ? countSubTreeDepth($scope.$childNodesScope) : 0;
134140
};
135141
}
136142
]);

0 commit comments

Comments
 (0)