Skip to content

Commit 2d93753

Browse files
author
nick
committed
added dist
1 parent 714149c commit 2d93753

File tree

3 files changed

+240
-0
lines changed

3 files changed

+240
-0
lines changed

dist/abn_tree_directive.js

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
var module;
2+
3+
module = angular.module('angularBootstrapNavTree', []);
4+
5+
module.directive('abnTree', function($timeout) {
6+
return {
7+
restrict: 'E',
8+
templateUrl: '../dist/abn_tree_template.html',
9+
scope: {
10+
treeData: '=',
11+
onSelect: '&',
12+
initialSelection: '='
13+
},
14+
link: function(scope, element, attrs) {
15+
var expand_all, expand_level, for_each_branch, on_treeData_change, select_branch, selected_branch, unselect_all;
16+
if (attrs.iconExpand == null) {
17+
attrs.iconExpand = 'icon-plus';
18+
}
19+
if (attrs.iconCollapse == null) {
20+
attrs.iconCollapse = 'icon-minus';
21+
}
22+
if (attrs.iconLeaf == null) {
23+
attrs.iconLeaf = 'icon-chevron-right';
24+
}
25+
if (attrs.expandLevel == null) {
26+
attrs.expandLevel = '3';
27+
}
28+
expand_level = parseInt(attrs.expandLevel, 10);
29+
scope.header = attrs.header;
30+
if (!scope.treeData) {
31+
alert('no treeData defined for the tree!');
32+
}
33+
if (scope.treeData.length == null) {
34+
if (treeData.label != null) {
35+
scope.treeData = [treeData];
36+
} else {
37+
alert('treeData should be an array of root branches');
38+
}
39+
}
40+
for_each_branch = function(f) {
41+
var do_f, root_branch, _i, _len, _ref, _results;
42+
do_f = function(branch, level) {
43+
var child, _i, _len, _ref, _results;
44+
f(branch, level);
45+
if (branch.children != null) {
46+
_ref = branch.children;
47+
_results = [];
48+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
49+
child = _ref[_i];
50+
_results.push(do_f(child, level + 1));
51+
}
52+
return _results;
53+
}
54+
};
55+
_ref = scope.treeData;
56+
_results = [];
57+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
58+
root_branch = _ref[_i];
59+
_results.push(do_f(root_branch, 1));
60+
}
61+
return _results;
62+
};
63+
for_each_branch(function(branch) {
64+
if (branch.children) {
65+
if (branch.children.length > 0) {
66+
return branch.children = branch.children.map(function(e) {
67+
if (typeof e === 'string') {
68+
return {
69+
label: e,
70+
children: []
71+
};
72+
} else {
73+
return e;
74+
}
75+
});
76+
}
77+
} else {
78+
return branch.children = [];
79+
}
80+
});
81+
for_each_branch(function(b, level) {
82+
b.level = level;
83+
b.expanded = b.level < expand_level;
84+
return b.uid = "" + Math.random();
85+
});
86+
expand_all = function() {
87+
return for_each_branch(function(branch) {
88+
return branch.expanded = true;
89+
});
90+
};
91+
unselect_all = function() {
92+
return for_each_branch(function(branch) {
93+
return branch.selected = false;
94+
});
95+
};
96+
selected_branch = null;
97+
select_branch = function(branch) {
98+
if (branch !== selected_branch) {
99+
unselect_all();
100+
branch.selected = true;
101+
selected_branch = branch;
102+
if (branch.onSelect != null) {
103+
return $timeout(function() {
104+
return branch.onSelect(branch);
105+
});
106+
} else {
107+
if (scope.onSelect != null) {
108+
return scope.onSelect({
109+
branch: branch
110+
});
111+
}
112+
}
113+
}
114+
};
115+
scope.user_clicks_branch = function(branch) {
116+
if (branch !== selected_branch) {
117+
return select_branch(branch);
118+
}
119+
};
120+
scope.tree_rows = [];
121+
on_treeData_change = function() {
122+
var add_all, root_branch, _i, _len, _ref, _results;
123+
scope.tree_rows = [];
124+
add_all = function(level, branch, visible) {
125+
var child, child_visible, tree_icon, _i, _len, _ref, _results;
126+
if (branch.expanded == null) {
127+
branch.expanded = false;
128+
}
129+
if (branch.children.length === 0) {
130+
tree_icon = attrs.iconLeaf;
131+
} else {
132+
if (branch.expanded) {
133+
tree_icon = attrs.iconCollapse;
134+
} else {
135+
tree_icon = attrs.iconExpand;
136+
}
137+
}
138+
scope.tree_rows.push({
139+
level: level,
140+
branch: branch,
141+
label: branch.label,
142+
tree_icon: tree_icon,
143+
visible: visible
144+
});
145+
if (branch.children != null) {
146+
_ref = branch.children;
147+
_results = [];
148+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
149+
child = _ref[_i];
150+
child_visible = visible && branch.expanded;
151+
_results.push(add_all(level + 1, child, child_visible));
152+
}
153+
return _results;
154+
}
155+
};
156+
_ref = scope.treeData;
157+
_results = [];
158+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
159+
root_branch = _ref[_i];
160+
_results.push(add_all(1, root_branch, true));
161+
}
162+
return _results;
163+
};
164+
if (attrs.initialSelection != null) {
165+
for_each_branch(function(b) {
166+
if (b.label === attrs.initialSelection) {
167+
return select_branch(b);
168+
}
169+
});
170+
}
171+
return scope.$watch('treeData', on_treeData_change, true);
172+
}
173+
};
174+
});

dist/abn_tree_style.css

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
ul.nav.nav-list.abn-tree i.indented {
2+
padding: 2px;
3+
}
4+
.abn-tree-animate-enter {
5+
transition: 150ms linear all;
6+
position: relative;
7+
display: block;
8+
opacity: 0;
9+
max-height: 0px;
10+
}
11+
.abn-tree-animate-enter.abn-tree-animate-enter-active {
12+
opacity: 1;
13+
max-height: 30px;
14+
}
15+
.abn-tree-animate-leave {
16+
transition: 150ms linear all;
17+
position: relative;
18+
display: block;
19+
max-height: 30px;
20+
opacity: 1;
21+
}
22+
.abn-tree-animate-leave.abn-tree-animate-leave-active {
23+
max-height: 0px;
24+
opacity: 0;
25+
}
26+
ul.nav.nav-list.abn-tree .level-1 .indented {
27+
position: relative;
28+
left: 0px;
29+
}
30+
ul.nav.nav-list.abn-tree .level-2 .indented {
31+
position: relative;
32+
left: 20px;
33+
}
34+
ul.nav.nav-list.abn-tree .level-3 .indented {
35+
position: relative;
36+
left: 40px;
37+
}
38+
ul.nav.nav-list.abn-tree .level-4 .indented {
39+
position: relative;
40+
left: 60px;
41+
}
42+
ul.nav.nav-list.abn-tree .level-5 .indented {
43+
position: relative;
44+
left: 80px;
45+
}
46+
ul.nav.nav-list.abn-tree .level-6 .indented {
47+
position: relative;
48+
left: 80px;
49+
}
50+
ul.nav.nav-list.abn-tree .level-7 .indented {
51+
position: relative;
52+
left: 100px;
53+
}
54+
ul.nav.nav-list.abn-tree .level-8 .indented {
55+
position: relative;
56+
left: 120px;
57+
}
58+
ul.nav.nav-list.abn-tree .level-9 .indented {
59+
position: relative;
60+
left: 140px;
61+
}

dist/abn_tree_template.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
<ul class="nav nav-list abn-tree">
3+
<li ng-show="header" class="nav-header">{{ header }}</li>
4+
<li ng-repeat="row in tree_rows | filter:{visible:true} track by row.branch.uid" ng-animate="'abn-tree-animate'" ng-class="'level-' + {{ row.level }} + (row.branch.selected ? ' active':'')" class="abn-tree-row"><a ng-click="user_clicks_branch(row.branch)"><i ng-class="row.tree_icon" ng-click="row.branch.expanded = !row.branch.expanded" class="indented tree-icon"> </i><span class="indented tree-label">{{ row.label }}</span></a></li>
5+
</ul>

0 commit comments

Comments
 (0)