Skip to content

Commit 7fb14dd

Browse files
Merge pull request #41 from rahatarmanahmed/master
Added adding classes per node. Auto add leaf class to leaves.
2 parents 403849a + 6535320 commit 7fb14dd

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,20 @@ There is a short-form for listing nodes children (as used for "children" above),
6464
If you use the short-form for listing elements, then your "on-select" function will have to act based only upon the "branch.label". If you use the
6565
long-form, where is branch is an object, then you can also attach "data" to a branch.
6666

67+
If you would like to add classes to a certain node, give it an array of classes like so:
6768

69+
$scope.my_data = [{
70+
label: 'Languages',
71+
children: ['Jade','Less','Coffeescript']
72+
classes: ["special", "red"]
73+
}]
74+
75+
Each element without children, or leaf, is automatically given a leaf class. If you would like to force certain nodes not to be leaves (won't get leaf class and will show expand/collapse icons), set noLeaf to true in a long-form listing like so:
76+
77+
{
78+
label: 'Coffeescript',
79+
noLeaf: true
80+
}
6881

6982
You can supply a single default "on-select" function for the whole tree -- it will be called whenever a branch is selected:
7083

dist/abn_tree_directive.js

+11-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/abn_tree_directive.coffee

+6-1
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,17 @@ module.directive 'abnTree',['$timeout',($timeout)->
190190
if not branch.expanded?
191191
branch.expanded = false
192192

193+
if not branch.classes?
194+
branch.classes = []
195+
193196
#
194197
# icons can be Bootstrap or Font-Awesome icons:
195198
# they will be rendered like:
196199
# <i class="icon-plus"></i>
197200
#
198-
if not branch.children or branch.children.length == 0
201+
if not branch.noLeaf and (not branch.children or branch.children.length == 0)
199202
tree_icon = attrs.iconLeaf
203+
branch.classes.push "leaf" if "leaf" not in branch.classes
200204
else
201205
if branch.expanded
202206
tree_icon = attrs.iconCollapse
@@ -211,6 +215,7 @@ module.directive 'abnTree',['$timeout',($timeout)->
211215
level : level
212216
branch : branch
213217
label : branch.label
218+
classes : branch.classes
214219
tree_icon : tree_icon
215220
visible : visible
216221

src/abn_tree_template.jade

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ul.nav.nav-list.nav-pills.nav-stacked.abn-tree
44
li.abn-tree-row(
55
ng-repeat='row in tree_rows | filter:{visible:true} track by row.branch.uid'
66
ng-animate="'abn-tree-animate'"
7-
ng-class="'level-' + {{ row.level }} + (row.branch.selected ? ' active':'')"
7+
ng-class="'level-' + {{ row.level }} + (row.branch.selected ? ' active':'') + ' ' +row.classes.join(' ')"
88
)
99

1010
a(ng-click="user_clicks_branch(row.branch)")

0 commit comments

Comments
 (0)