Skip to content

Commit 866c573

Browse files
Added support for both Bootstrap 2 and Bootstrap 3
1 parent 47b154c commit 866c573

28 files changed

+20790
-124
lines changed

Gruntfile.coffee

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,29 @@ module.exports = (grunt)->
1111
pretty:true
1212
files:
1313
'dist/abn_tree_template.html':'src/abn_tree_template.jade'
14-
'test/test_abn_tree.html':'src/test_abn_tree.jade'
14+
15+
#
16+
# Generate 2 test pages:
17+
# one for Bootstrap 2
18+
# one for Bootstrap 3
19+
#
1520

16-
less:
17-
dev:
21+
bs2:
22+
files:
23+
'test/bs2_test_page.html':'src/test_page.jade'
1824
options:
19-
compress:false
25+
pretty:true
26+
data:
27+
bs:"2"
28+
29+
bs3:
2030
files:
21-
'dist/abn_tree_style.css':'src/abn_tree_style.less'
31+
'test/bs3_test_page.html':'src/test_page.jade'
32+
options:
33+
pretty:true
34+
data:
35+
bs:"3"
36+
2237

2338

2439
coffee:
@@ -27,7 +42,7 @@ module.exports = (grunt)->
2742
bare:true
2843
files:
2944
'dist/abn_tree_directive.js':'src/abn_tree_directive.coffee'
30-
'test/test_abn_tree.js':'src/test_abn_tree.coffee'
45+
'test/test_page.js':'src/test_page.coffee'
3146

3247

3348
watch:
@@ -36,22 +51,23 @@ module.exports = (grunt)->
3651
tasks:['jade']
3752
options:
3853
livereload:true
39-
less:
40-
files:['**/*.less']
41-
tasks:['less']
54+
55+
css:
56+
files:['**/*.css']
57+
tasks:[]
4258
options:
4359
livereload:true
4460

61+
4562
coffee:
4663
files:['**/*.coffee']
4764
tasks:['coffee']
4865
options:
4966
livereload:true
5067

5168
grunt.loadNpmTasks 'grunt-contrib-jade'
52-
grunt.loadNpmTasks 'grunt-contrib-less'
5369
grunt.loadNpmTasks 'grunt-contrib-coffee'
5470
grunt.loadNpmTasks 'grunt-contrib-watch'
5571

56-
grunt.registerTask 'default', ['jade','less','coffee']
72+
grunt.registerTask 'default', ['jade','coffee','watch']
5773

Gruntfile.js

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@ angular-bootstrap-nav-tree
44

55
This is a Tree directive for Angular JS apps that use Bootstrap CSS.
66

7-
example: http://nickperkinslondon.github.io/angular-bootstrap-nav-tree/test/test_abn_tree.html
7+
example: http://nickperkinslondon.github.io/angular-bootstrap-nav-tree/test/bs2_test_page.html
88

99
The style is completely Bootstrap because the tree is actually just a Bootstrap "nav" list, with a few changes: Indentation is added, expand/collapse icons are added, and Angular CSS animations are used during expand/collapse.
1010

11+
<abn-tree> now works with either Bootsrap 2, or Bootstrap 3!
12+
1113
The normal Glyphicons work well, but they appear black instead of blue. Alternatively, you can use the Font Awesome icons, which look even better, and match the blue color of the text.
1214

1315
You can change the icons used by specifying them in html attributes.
1416

15-
This tree is developed in CoffeeScript, Jade, and Less, but you don't need to be using any of those to use this tree -- you just have to be using Angular and Bootsrap.
17+
This tree is developed using CoffeeScript and Jade, but you don't need to be using either of those to use this tree -- you just have to be using Angular and Bootsrap.
1618

1719

1820
How to use it:
1921
Just include the 3 files from "dist":
2022

2123
abn_tree_directive.js
22-
abn_tree_style.css
2324
abn_tree_template.html
25+
abn_tree.css
2426

2527
NOTE: you will have to adjust the "templateUrl" in the directive js, to adjust for your directory structure.
2628

@@ -35,12 +37,11 @@ At a miniumum, you must supply `tree-data` :
3537
But there are other attributes to customize the tree:
3638

3739
<abn-tree
38-
header="This is the example tree"
3940
tree-data="example_treedata"
4041
icon-leaf="icon-file"
4142
icon-expand="icon-plus-sign"
4243
icon-contract="icon-minus-sign"
43-
on-select="my_default_handler(branch)"
44+
on-select="my_tree_handler(branch)"
4445
expand-level="2"
4546
initial-selection="Vegetable">
4647
></abn-tree>
@@ -53,13 +54,16 @@ The data to create the tree is defined in your controller, and could be as simpl
5354
children: ['Jade','Less','Coffeescript']
5455
}]
5556

56-
If you you this short-form for listing elements, then your "on-select" function will have to act based only upon the "branch.label". If you use the long-form, where is branch is an object, then you can also attach "data" to a branch.
57+
There is a long-form for elements, in which each node is an object with a "label", and optionally other stuff like "data", and "children".
58+
There is a short-form for listing nodes children (as used for "children" above), where the "children" is just a list of strings.
59+
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
60+
long-form, where is branch is an object, then you can also attach "data" to a branch.
5761

5862

5963

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

62-
$scope.my_default_hander = function(branch){...}
66+
$scope.my_tree_hander = function(branch){...}
6367

6468

6569
Or, you can put a custom "on-select" function on an individual branch:
@@ -70,8 +74,7 @@ Or, you can put a custom "on-select" function on an individual branch:
7074
children: ['Jade','Less','Coffeescript']
7175
}]
7276

73-
Each branch can have a "data" element which you can use to hold whatever data you want. It is not touched by the tree, and it is available to your "on-select" functions as "branch.data". In the example, in the "test" folder, this technique is used in "my_default_handler" to add extra info to "Dog","Cat", and "Hippo".
77+
Each branch can have a "data" element which you can use to hold whatever data you want. It is not touched by the tree, and it is available to your "on-select" function as "branch.data". In the example, in the "test" folder, this technique is used in "my_tree_handler" to add extra info to "Dog","Cat", and "Hippo".
7478

7579
Warning: If you attach extra attributes directly to a branch (instead of to "branch.data"), they could conflict with the internal workings of the tree, which adds branch attributes at runtime, like "expanded" and "selected".
7680

77-

src/abn_tree_style.less renamed to dist/abn_tree.css

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,75 @@
1-
ul.nav.nav-list.abn-tree i.indented {
2-
padding:2px;
3-
}
4-
//ul.nav.nav-list.abn-tree i.indented:hover {
5-
// border-radius: 3px;
6-
// color: black;
7-
// background: blue;
8-
//}
1+
/*
2+
abn-tree.css
3+
4+
style for the angular-bootstrap-nav-tree
5+
for both Bootstrap 2 and Bootstrap 3
6+
7+
*/
8+
9+
ul.abn-tree li.abn-tree-row {
10+
padding: 0px;
11+
margin:0px;
12+
}
13+
14+
ul.abn-tree li.abn-tree-row a {
15+
padding: 3px 10px;
16+
}
17+
18+
ul.abn-tree i.indented {
19+
padding: 2px;
20+
}
21+
922
.abn-tree-animate-enter {
1023
transition: 150ms linear all;
1124
position: relative;
1225
display: block;
1326
opacity: 0;
14-
max-height: 0px;
27+
max-height:0px;
1528
}
1629
.abn-tree-animate-enter.abn-tree-animate-enter-active {
1730
opacity: 1;
18-
max-height: 30px;
31+
max-height:30px;
1932
}
33+
2034
.abn-tree-animate-leave {
2135
transition: 150ms linear all;
2236
position: relative;
2337
display: block;
38+
height:30px;
2439
max-height: 30px;
2540
opacity: 1;
2641
}
27-
.abn-tree-animate-leave.abn-tree-animate-leave-active {
28-
max-height: 0px;
42+
.abn-tree-animate-leave.abn-tree-animate-leave-active {
43+
height: 0px;
44+
max-height:0px;
2945
opacity: 0;
3046
}
31-
ul.nav.nav-list.abn-tree .level-1 .indented {
47+
48+
49+
.abn-tree {
50+
cursor: pointer;
51+
}
52+
ul.nav.abn-tree .level-1 .indented {
3253
position: relative;
3354
left: 0px;
3455
}
35-
ul.nav.nav-list.abn-tree .level-2 .indented {
56+
ul.nav.abn-tree .level-2 .indented {
3657
position: relative;
3758
left: 20px;
3859
}
39-
ul.nav.nav-list.abn-tree .level-3 .indented {
60+
ul.nav.abn-tree .level-3 .indented {
4061
position: relative;
4162
left: 40px;
4263
}
43-
ul.nav.nav-list.abn-tree .level-4 .indented {
64+
ul.nav.abn-tree .level-4 .indented {
4465
position: relative;
4566
left: 60px;
4667
}
47-
ul.nav.nav-list.abn-tree .level-5 .indented {
68+
ul.nav.abn-tree .level-5 .indented {
4869
position: relative;
4970
left: 80px;
5071
}
51-
ul.nav.nav-list.abn-tree .level-6 .indented {
72+
ul.nav.abn-tree .level-6 .indented {
5273
position: relative;
5374
left: 80px;
5475
}

dist/abn_tree_directive.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ module.directive('abnTree', function($timeout) {
2929
scope.header = attrs.header;
3030
if (!scope.treeData) {
3131
alert('no treeData defined for the tree!');
32+
debugger;
33+
return;
3234
}
3335
if (scope.treeData.length == null) {
3436
if (treeData.label != null) {
3537
scope.treeData = [treeData];
3638
} else {
3739
alert('treeData should be an array of root branches');
40+
debugger;
41+
return;
3842
}
3943
}
4044
for_each_branch = function(f) {

dist/abn_tree_template.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
<ul class="nav nav-list abn-tree">
3-
<li ng-show="header" class="nav-header">{{ header }}</li>
2+
<ul class="nav nav-list nav-pills nav-stacked abn-tree">
43
<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>
54
</ul>

src/abn_tree_directive.coffee

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module = angular.module 'angularBootstrapNavTree',[]
33

44
module.directive 'abnTree',($timeout)->
55
restrict:'E'
6-
templateUrl:'../dist/abn_tree_template.html' # FIXME?
6+
templateUrl: '../dist/abn_tree_template.html'
7+
78
scope:
89
treeData:'='
910
onSelect:'&'
@@ -24,11 +25,16 @@ module.directive 'abnTree',($timeout)->
2425
# check args
2526
if !scope.treeData
2627
alert 'no treeData defined for the tree!'
28+
debugger
29+
return
30+
2731
if !scope.treeData.length?
2832
if treeData.label?
2933
scope.treeData = [ treeData ]
3034
else
3135
alert 'treeData should be an array of root branches'
36+
debugger
37+
return
3238

3339

3440
#

src/abn_tree_template.jade

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11

2-
ul.nav.nav-list.abn-tree
3-
4-
li.nav-header(ng-show="header") {{ header }}
2+
ul.nav.nav-list.nav-pills.nav-stacked.abn-tree
53

64
li.abn-tree-row(
75
ng-repeat='row in tree_rows | filter:{visible:true} track by row.branch.uid'

0 commit comments

Comments
 (0)