forked from wix-incubator/angular-tree-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1549 lines (1489 loc) · 73.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<title>Angular Tree</title>
<script src="demo/jquery-2.2.2.js"></script>
<script src="demo/angular.1.2.29.js"></script>
<script src="demo/bootstrap.3.1.1.js"></script>
<script src="demo/ui-bootstrap-tpls.0.11.2.js"></script>
<script src="demo/prettify.1.0.1.js"></script>
<link href="demo/bootstrap.3.1.1.css" rel="stylesheet" type="text/css">
<link href="demo/prettify-style.css" rel="stylesheet" type="text/css">
<script src="angular-tree-control.js"></script>
<script src="context-menu.js"></script>
<link rel="stylesheet" type="text/css" href="css/tree-control.css">
<link rel="stylesheet" type="text/css" href="css/tree-control-attribute.css">
<style>
.header{padding-top: 50px; padding-bottom:50px; background-color: #444980;}
.head-container{width: 1140px; margin:auto;}
.header h1 {color: #fffffa; font-size: 60px}
.header h2 {color: #fffffa; font-size: 24px; font-style: normal}
.example-caption {color: #bbb; font-size: 12px}
.docs-body{width: 1140px; margin: auto auto 50px; }
.docs-footer{background-color: #F5F5F5; text-align: center; padding: 30px 0; border-top: #e5e5e5}
.tab-pane{background-color: #f8f8f8; border-right: 1px solid #ccc;border-left: 1px solid #ccc;border-bottom: 1px solid #ccc; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px }
.nav li.active a{background-color: #f8f8f8}
pre.code {border:none; background-color: #f8f8f8; padding: 10px; margin: 0; font-family: Consolas, 'Liberation Mono', Courier, monospace;}
.docs-sidenav { margin-top: 45px; margin-bottom: 0; }
.docs-sidenav > li > a {display: block; font-size: 13px; font-weight: 500; color: #999; padding: 4px 20px;}
.docs-sidenav > li.active > a {font-weight: 700; color: #563d7c; border-left: 2px solid #563d7c;padding-left: 18px;}
.docs-sidenav > li > a:hover {background-color: transparent; color: #563d7c; border-left: 1px solid #563d7c;padding-left: 19px;}
.type-hint-object {background:#999;}
.type-hint-boolean {background:rgb(18, 131, 39);}
.type-hint-function {background: rgb(36, 53, 131);}
.type-hint-number {background:rgb(189, 63, 66);}
.dropdown-menu li a.disabled { pointer-events: none; cursor: default; color:#bbb; }
</style>
</head>
<body ng-app="example">
<a href="https://github.com/wix/angular-tree-control"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
<div class="header">
<div class="head-container">
<h1>Angular Tree</h1>
<h2>The AngularJS tree component</h2>
</div>
</div>
<div class="row docs-body">
<div class="col-md-9">
<section id="classic" ng-controller="Classic">
<div class="page-header">
<h1>Basic Usage <small>(Classic style, default configuration)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="classic-html">
<treecontrol class="tree-classic"
tree-model="treedata"
on-selection="showSelected(node)">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>Classic style of the tree control, set using the class <code>tree-classic</code>.</p>
<p>Click on the folder icons to open and close the tree nodes. Click on the node label to select a node in the tree. A Second click on the node label will unselect the node.</p>
<p>The tree data is set using the <code>tree-model</code> attribute, which accepts either a node object or an array of node objects.
A Node object is a regular javascript object which has a <code>children</code> array property (children is the default name,
it can be overridden using the tree options). </p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="classic-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="classic-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="classic-js">
function Classic($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="as-attribute" ng-controller="AsAttribute">
<div class="page-header">
<h1>As an Attribute <small>(Alternative to a Custom Element)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="as-attribute-html">
<div treecontrol class="tree-classic"
tree-model="treedata"
on-selection="showSelected(node)">
label: {{node.label}} ({{node.id}})
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>Using the tree control as an attribute is as easy as using a div and adding a <code>treecontrol</code> attribute to it</p>
<p>Note that you have to include the <code>tree-control-attribute.css</code> file instead of the <code>tree-control.css</code>
as the CSS selectors are quite different between the two styles of usage.</p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="as-attribute-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="as-attribute-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="as-attribute-js">
function AsAttribute($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="labels-template" ng-controller="LabelsTemplate">
<div class="page-header">
<h1>Tree Label Templates <small>(Customize the tree labels)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="labels-template-html">
<treecontrol class="tree-classic"
tree-model="treedata"
on-selection="showSelected(node)">
<span style="color: {{getColor(node)}}">{{node.label}} - index: {{$index}}</span>
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>Taking control of the tree labels is as simple as with <code>ng-repeat</code> - you include a template in the tree control tag.</p>
<p>Special properties are exposed to the local scope of each template, including the current node as <code>node</code>.</p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
</div>
</div>
<table class="table table-bordered table-striped">
<thead><tr><td>Variable</td><td>Type</td><td>Details</td></tr></thead>
<tr><td><code>node</code></td><td><span class="label type-hint-object">Object</span></td><td>The current node the label represents.</td></tr>
<tr><td><code>$parentNode</code></td><td><span class="label type-hint-object">Object</span></td><td>The parent of the current node.</td></tr>
<tr><td><code>$index</code></td><td><span class="label type-hint-number">number</span></td><td>iterator offset of the repeated element under one parent node(0..length-1).</td></tr>
<tr><td><code>$first</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the repeated element is first in the iterator.</td></tr>
<tr><td><code>$middle</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the repeated element is between the first and last in the iterator.</td></tr>
<tr><td><code>$last</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the repeated element is last in the iterator.</td></tr>
<tr><td><code>$odd</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the iterator position $index is even (otherwise false).</td></tr>
<tr><td><code>$even</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the iterator position $index is odd (otherwise false).</td></tr>
<tr><td><code>$path</code></td><td><span class="label type-hint-function">function</span></td><td>a function that when called, returns the path to the current node.</td></tr>
</table>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="labels-template-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="labels-template-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="labels-template-js">
function LabelsTemplate($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.getColor = function(node) {
return ["#a40", "#04a", "#990", "#0a4"][node.i % 4];
};
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="parent" ng-controller="Parent">
<div class="page-header">
<h1>Tree Label Scope <small>(as a child of the controller scope)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="classic-html">
<treecontrol class="tree-classic"
tree-model="treedata"
on-selection="showSelected(node)">
<button ng-click="buttonClick($event, node)">Click Me!</button> label: {{node.label}} ({{node.id}} ) {{$index}}
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>The scope used to compile the tree labels is a child scope of the controller (used to compile the tree-control directive).
As such, in the tree label scope you have access to all the properties and methods defined in the controller scope.
This example shows how to access a method in the parent scope from the label template.</p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
<p>Last clicked: <code>{{lastClicked ? lastClicked.label : "N/A"}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="classic-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="classic-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="classic-js">
function Parent($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.lastClicked = null;
$scope.buttonClick = function($event, node) {
$scope.lastClicked = node;
$event.stopPropagation();
}
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="changing" ng-controller="Changing">
<div class="page-header">
<h1>Changing the live tree <small>(adding and removing nodes)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="changing-html">
<treecontrol class="tree-classic"
tree-model="treedata">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>You can modify the <code>tree-model</code> bound tree, and the tree will update with the new structure</p>
<p>For instance, adding nodes:</p>
<ul>
<li><a ng-click="addRoot()">Add a new root</a></li>
<li><a ng-click="addChildToSecondRoot()">Add a child to the 2nd node</a></li>
</ul>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="changing-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="changing-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="changing-js">
function Changing($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.addRoot = function() {
$scope.treedata.push({label: "New Root", id:"some id", children: []})
};
$scope.addChildToSecondRoot = function() {
$scope.treedata[1].children.push({label: "New Child", id:"some id", children: []})
};
}
</script>
</section>
<section id="selected" ng-controller="Selected">
<div class="page-header">
<h1>Selected Node Binding <small>(selected-node)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="selected-html">
<treecontrol class="tree-classic"
tree-model="treedata"
selected-node="selected">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>The <code>selected-node</code> attribute of <code>treecontrol</code> is bound to the currently selected node object of the tree.
Like any other Angular bound value, updating selected-node will set the tree selection, and clicking the tree (selecting a node) will
update back the selected-node.</p>
<p>Setting <code>selected-node</code> can also be used to set the default selected node of the tree.</p>
<p>Note that if using multiple selection, the selected nodes are bound to an Array property <code>selected-nodes</code> instead of <code>selected-node</code>.</p>
<p><a ng-click="selectNode(0)">select node 1</a><br>
<a ng-click="selectNode(1)">select node 2</a><br>
<a ng-click="selectNode(2)">select node 3</a><br>
<a ng-click="selectNode(3)">select node 4</a><br>
<a ng-click="clearSelected()">clear Selected</a></p>
<p>Selected node: <code>{{selected.label}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="selected-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="selected-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="selected-js">
function Selected($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.selected = $scope.treedata[2];
$scope.selectNode = function(num) {
$scope.selected = $scope.treedata[num];
};
$scope.clearSelected = function() {
$scope.selected = undefined;
}
}
</script>
</section>
<section id="expandedNodes" ng-controller="ExpandedNodes">
<div class="page-header">
<h1>Expanded Nodes Binding <small>(expanded-nodes)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="default-expanded-html">
<treecontrol class="tree-classic"
tree-model="treedata"
expanded-nodes="expandedNodes"
options="opts">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>The <code>expanded-nodes</code> attribute of <code>treecontrol</code> is bound to the currently selected node object of the tree.
Like any other Angular bound value, updating <code>expanded-nodes</code> will set the expanded nodes in the tree,
and expanding or contracting nodes in the tree will update the <code>expanded-nodes</code> property.</p>
<p>Setting <code>expanded-nodes</code> can also be used to set the default expanded nodes of the tree.</p>
<p><a ng-click="setExpanded()">Expand 2, 3 and 3.3 (only)</a></p>
<p>The currently expanded nodes:</p>
<ul>
<li ng-repeat="node in expandedNodes">{{node.label}}</li>
</ul>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="default-expanded-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="default-expanded-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="default-expanded-js">
function ExpandedNodes($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.expandedNodes = [$scope.treedata[1],
$scope.treedata[3],
$scope.treedata[3].children[2],
$scope.treedata[3].children[2].children[1]];
$scope.setExpanded = function() {
$scope.expandedNodes = [$scope.treedata[1],
$scope.treedata[2],
$scope.treedata[2].children[2]
];
};
}
</script>
</section>
<section id="events" ng-controller="Events">
<div class="page-header">
<h1>Events <small>(on-expand & on-selection)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="events-html">
<treecontrol class="tree-classic"
tree-model="treedata"
on-selection="showSelected(node, selected, $parentNode, $index, $first, $middle, $last, $odd, $even, $path)"
on-node-toggle="showToggle(node, expanded, $parentNode, $index, $first, $middle, $last, $odd, $even, $path)">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<P>The tree supports events for selection and expansion of nodes. The events are set using the <code>on-selection</code> and <code>on-node-toggle</code> attributes
which values are evaluated as angular expressions (like <code>ng-click</code> value). The expression can use the <code>node</code> and <code>selected</code> variables (for on-selection) or
the <code>node</code> and <code>expanded</code> variables (for on-node-toggle) for context of the clicked node and if it was selected / deselected or expanded / collapsed.</P>
<p>Note the events are fired only on the clicked node. If using the tree in single selection mode and one node is selected, when selecting a different node
only one on-selection event will be fired for the newly selected node. The old selected node will not be selected anymore without an on-selected event.</p>
<p>In order to prevent selection of branches (folders) in the tree, set the <code>options.dirSelectable</code> to <code>false</code>.
Clicking folder labels at this point will expand and contract the node.</p>
<p>Events fired:</p>
<ul id="events-listing">
</ul>
</div>
</div>
<table class="table table-bordered table-striped">
<thead><tr><td>Variable</td><td>Type</td><td>Details</td></tr></thead>
<tr><td><code>node</code></td><td><span class="label type-hint-object">Object</span></td><td>The current node the label represents.</td></tr>
<tr><td><code>$parentNode</code></td><td><span class="label type-hint-object">Object</span></td><td>The parent of the current node.</td></tr>
<tr><td><code>$index</code></td><td><span class="label type-hint-number">number</span></td><td>iterator offset of the repeated element under one parent node(0..length-1).</td></tr>
<tr><td><code>$first</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the repeated element is first in the iterator.</td></tr>
<tr><td><code>$middle</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the repeated element is between the first and last in the iterator.</td></tr>
<tr><td><code>$last</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the repeated element is last in the iterator.</td></tr>
<tr><td><code>$odd</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the iterator position $index is even (otherwise false).</td></tr>
<tr><td><code>$even</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the iterator position $index is odd (otherwise false).</td></tr>
<tr><td><code>$path</code></td><td><span class="label type-hint-function">function</span></td><td>a function that when called, returns the path to the current node.</td></tr>
<tr><td><code>selected</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the node is selected, false if it is de-selected. Only applies to the on-selection event.</td></tr>
<tr><td><code>expanded</code></td><td><span class="label type-hint-boolean">boolean</span></td><td>true if the node is expanding, false if the node is contracting. Only applies to the on-node-toggle event.</td></tr>
</table>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="events-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="events-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="events-js">
function Events($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.showToggle = function(node, expanded, $parentNode, $index, $first, $middle, $last, $odd, $even, $path) {
var parent = $parentNode?("child of: " + $parentNode.label):"root node";
var location = $first?"first":($last?"last":("middle node at index " + $index));
var oddEven = $odd?"odd":"even";
var path = $path().map(function(node) {return node.label});
$("#events-listing").append("<li>"+node.label+ (expanded?" expanded":" collapsed") +" (" + parent + ", " + location +", " + oddEven + ", ["+ path+"])</li>");
};
$scope.showSelected = function(node, selected, $parentNode, $index, $first, $middle, $last, $odd, $even, $path) {
var parent = $parentNode?("child of: " + $parentNode.label):"root node";
var location = $first?"first":($last?"last":("middle node at index " + $index));
var oddEven = $odd?"odd":"even";
var path = $path().map(function(node) {return node.label});
$("#events-listing").append("<li>"+node.label+ (selected?" selected":" deselected") +" (" + parent + ", " + location +", " + oddEven + ", ["+ path +"])</li>");
};
}
</script>
</section>
<section id="multi-selection" ng-controller="MultiSelection">
<div class="page-header">
<h1>Multi Selection <small>(options.multiSelect & selected-nodes)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="multi-selection-html">
<treecontrol class="tree-classic"
tree-model="treedata"
selected-nodes="selectedNodes"
on-selection="showSelected(node, selected)"
options="treeOptions">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<P>The tree control supports multi-selection using the <code>options.multiSelect</code> option and the <code>selected-nodes</code> attribute (instead of the <code>selected-node</code> attribute in single selection mode).
<code>selected-nodes</code> is expected to be an Array which will contain the selected nodes.
When using multi-selection, selecting a node adds it to the selected-nodes array and a second click remove it from the array.</p>
<div class="row">
<div class="col-md-6">
<p>Selected Nodes:</p>
<ul id="multi-selection-listing">
<li ng-repeat="node in selectedNodes">{{node.label}}</li>
</ul>
</div>
<div class="col-md-6">
<p>Selection Events:</p>
<ul id="multi-selection-events-listing">
</ul>
</div>
</div>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="multi-selection-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="multi-selection-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="multi-selection-js">
function MultiSelection($scope) {
$scope.treeOptions = {multiSelection: true};
$scope.treedata=createSubTree(3, 4, "");
$scope.selectedNodes = [];
$scope.showSelected = function(node, selected) {
$("#multi-selection-events-listing").append("<li>"+node.label+ (selected?" selected":" deselected") + "</li>");
};
}
</script>
</section>
<section id="dirSelection" ng-controller="DirSelection">
<div class="page-header">
<h1>Clicking Labels Expand & Collapse <small>(options.dirSelectable)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="dir-selection-html">
<treecontrol class="tree-classic"
tree-model="treedata"
options="opts"
on-selection="showSelected(node)">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>In order to prevent selection of branches (folders) in the tree, set the <code>options.dirSelectable</code> to <code>false</code>.
Clicking folder labels at this point will expand and contract the node.</p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="dir-selection-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="dir-selection-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="dir-selection-js">
function DirSelection($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.opts = {
dirSelectable: false
};
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="isSelectable" ng-controller="IsSelectable">
<div class="page-header">
<h1>Disabling Selection of Nodes <small>(options.isSelectable)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="dir-selection-html">
<treecontrol class="tree-classic"
tree-model="treedata"
options="opts"
on-selection="showSelected(node)">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>To restrict which nodes are selectable on the tree, define the <code>options.isSelectable(node)</code> function.</p>
<p>Example disables the selection of any node on or under the <code>Node 1</code> node</p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="dir-selection-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="dir-selection-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="dir-selection-js">
function IsSelectable($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.opts = {
isSelectable: function(node) {
return node.label.indexOf("Node 1") !== 0;
}
};
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="light" ng-controller="Light">
<div class="page-header">
<h1>Light Style <small>(Basic style, default configuration)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="light-html">
<treecontrol class="tree-light"
tree-model="treedata"
on-selection="showSelected(node)">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>Light style of the tree control, set using the class <code>tree-light</code>.</p>
<p>Click on the folder icons to open and close the tree nodes. Click on the node label to select a node in the tree.</p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="light-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="light-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="light-js">
function Light($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="dark" ng-controller="Dark">
<div class="page-header">
<h1>Dark Style <small>(Basic style, default configuration)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body" style="background-color: #555;">
<div class="example-caption">EXAMPLE:</div>
<div save-content="dark-html">
<!-- Note that the tree does not set the background color. We inject it from the wrapper div. -->
<div style="background-color: #555;">
<treecontrol class="tree-dark"
tree-model="treedata"
on-selection="showSelected(node)">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>Dark style of the tree control, set using the class <code>tree-dark</code>. The style does not include the background color, instead,
inject your own background color using a wrapper div element.</p>
<p>Click on the folder icons to open and close the tree nodes. Click on the node label to select a node in the tree.</p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="dark-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="dark-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="dark-js">
function Dark($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="boot" ng-controller="Boot">
<div class="page-header">
<h1>Bootstrap Style <small>(Basic style, default configuration)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body" style="background-color: #f5f5f5;">
<div class="example-caption">EXAMPLE:</div>
<div save-content="boot-html">
<!-- Note that the tree does not set the background color. We inject it from the wrapper div. -->
<div style="background-color: #f5f5f5;">
<treecontrol class="tree-boot"
tree-model="treedata"
on-selection="showSelected(node)">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>Bootstrap style of the tree control, set using the class <code>tree-boot</code>. The style does not include the background color, instead,
inject your own background color using a wrapper div element.</p>
<p>Click on the folder icons to open and close the tree nodes. Click on the node label to select a node in the tree.</p>
<p>Selected node: <code>{{selectedNode?selectedNode.label:"N/A"}}</code></p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="boot-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="boot-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="boot-js">
function Boot($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="file-style" ng-controller="FileStyle">
<div class="page-header">
<h1>File Style using Tree Label Templates <small>(Basic style, default configuration)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body" style="background-color: #555;">
<div class="example-caption">EXAMPLE:</div>
<div save-content="file-style-html">
<!-- Note that the tree does not set the background color. We inject it from the wrapper div. -->
<div style="background-color: #555;">
<treecontrol class="tree-dark"
tree-model="treedata"
on-selection="showSelected(node)">
<span ng-switch on="node.type">
<span ng-switch-when="folder" class="glyphicon glyphicon-folder-open" aria-hidden="true"></span>
<span ng-switch-when="pic" class="glyphicon glyphicon-picture" aria-hidden="true"></span>
<span ng-switch-when="doc" class="glyphicon glyphicon-file" aria-hidden="true"></span>
<span ng-switch-when="file" class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>
<span ng-switch-when="movie" class="glyphicon glyphicon-film" aria-hidden="true"></span>
<span ng-switch-when="email" class="glyphicon glyphicon-envelope" aria-hidden="true"></span>
<span ng-switch-when="home" class="glyphicon glyphicon-home" aria-hidden="true"></span>
<span ng-switch-when="trash" class="glyphicon glyphicon-trash" aria-hidden="true"></span>
</span> label: {{node.label}}
</treecontrol>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>When using the tree control to display file like structures it is required to display the file type on each of the nodes. To achive that
we have to use a second icon using the Tree Label Templates with a <code>ng-switch</code> or equivalent directive, as shown in this example.</p>
<p>The tree control does not support replacing the expand / contract icons with a file type icon - it is design decision we made as we designed
the tree control.</p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="file-style-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="file-style-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="file-style-js">
function FileStyle($scope) {
$scope.treedata=[
{label: "Documents", type: "folder", children: [
{label: "a picture", type: "pic"},
{label: "another picture", type: "pic"},
{label: "a doc", type: "doc"},
{label: "a file", type: "file"},
{label: "a movie", type: "movie"}
]},
{label: "My Computer", type: "folder", children: [
{label: "email", type: "email"},
{label: "home", type: "home"}
]},
{label: "trash", type: "trash"}
];
$scope.showSelected = function(sel) {
$scope.selectedNode = sel;
};
}
</script>
</section>
<section id="custom-css" ng-controller="CustomCss">
<div class="page-header">
<h1>Custom Css Classes <small>(options.injectClasses)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="custom-css-html">
<style>
.c-ul {border: 1px solid #abcdef;}
.c-li {background-color: #defacb}
.c-liSelected {background-color: #fedbca}
.c-iExpanded {border: 1px solid #77a}
.c-iCollapsed {border: 1px solid #7c7}
.c-iLeaf {border: 1px solid #a77}
treecontrol.tree-classic li .tree-label.c-label {color: #44c}
treecontrol.tree-classic li .tree-selected.c-labelSelected {background-color: yellow}
</style>
<treecontrol class="tree-classic"
tree-model="treedata"
options="opts">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>The <code>options.injectClasses</code> option allows to add custom CSS classes on the tree DOM. The selected classes are</p>
<ul>
<li><code>ul</code> - inject classes into the ul elements (branch elements)</li>
<li><code>li</code> - inject classes into the li elements (both branch and leaf elements)</li>
<li><code>liSelected</code> - inject classes into the li elements of the selected node</li>
<li><code>iExpanded</code> - inject classes into the 'i' element for the expanded nodes (the icon)</li>
<li><code>iCollapsed</code> - inject classes into the 'i' element for the collapsed nodes</li>
<li><code>iLeaf</code> - inject classes into the 'i' element for leaf nodes</li>
<li><code>label</code> - inject classes into the div element around the label</li>
<li><code>labelSelected</code> - inject classes into the div element around the label only when the node is selected</li>
</ul>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="custom-css-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="custom-css-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="custom-css-js">
function CustomCss($scope) {
$scope.treedata=createSubTree(3, 4, "");
$scope.opts = {
injectClasses: {
"ul": "c-ul",
"li": "c-li",
"liSelected": "c-liSelected",
"iExpanded": "c-iExpanded",
"iCollapsed": "c-iCollapsed",
"iLeaf": "c-iLeaf",
"label": "c-label",
"labelSelected": "c-labelSelected"
}
};
}
</script>
</section>
<section id="children" ng-controller="Children">
<div class="page-header">
<h1>Custom Children <small>(options.nodeChildren)</small></h1>
</div>
<div class="row">
<div class="col-md-6 show-grid">
<div class="panel panel-default">
<div class="panel-body">
<div class="example-caption">EXAMPLE:</div>
<div save-content="children-html">
<treecontrol class="tree-classic"
tree-model="treedata"
options="opts">
label: {{node.label}} ({{node.id}})
</treecontrol>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<p>Angular tree control assumes that the tree nodes have a <code>children</code> array property for the children of the node.
You can override the children property name using the tree <code>nodeChildren</code> property of the tree options.</p>
</div>
</div>
<div class="row">
<tabset>
<tab heading="Markup" >
<pre class="code" apply-content="children-html" highlight-lang="html"></pre>
</tab>
<tab heading="JavaScript">
<pre class="code" apply-content="children-js" highlight-lang="js"></pre>
</tab>
</tabset>
</div>
<script save-content="children-js">
function Children($scope) {
$scope.treedata=[
{id:"id1", label: "Node 1", links: [
{id:"id1.1", label: "Node 1.1", links: {}},
{id:"id1.2", label: "Node 1.1", links: {}}
]},
{id:"id2", label: "Node 2", links: []},
{id:"id3", label: "Node 3", links: []},
{id:"id4", label: "Node 4", links: []}
];
$scope.opts = {
nodeChildren: "links"