Skip to content

Commit b197c76

Browse files
Added adding classes per node. Auto add leaf class to leaves.
1 parent 2c08504 commit b197c76

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ There is a short-form for listing nodes children (as used for "children" above),
6666
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
6767
long-form, where is branch is an object, then you can also attach "data" to a branch.
6868

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

71+
$scope.my_data = [{
72+
label: 'Languages',
73+
children: ['Jade','Less','Coffeescript']
74+
classes: ["special", "red"]
75+
}]
76+
77+
Each element without children, or leaf, is automatically given a leaf class.
7078

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

dist/abn_tree_directive.js

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

src/abn_tree_directive.coffee

+5
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
#
198201
if 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)