forked from mbraak/jqTree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1595 lines (1388 loc) · 57.3 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 lang="en">
<head>
<meta charset="utf-8">
<title>jqTree</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="extra/bower_components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="extra/bower_components/bootstrap/dist/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="jqtree.css">
<link rel="stylesheet" href="extra/bower_components/prism/themes/prism-okaidia.css">
<link rel="stylesheet" href="extra/documentation.css">
</head>
<body>
<div class="jumbotron" id="jqtree">
<div class="container">
<h1>jqTree</h1>
<p>
<strong class="title">JqTree</strong> is a jQuery widget for displaying a <strong>tree structure</strong> in html
<br>
It supports <strong>json data</strong>, loading via <strong>ajax</strong> and <strong>drag-and-drop</strong>.
</p>
<p>
<a class="btn btn-primary" href="https://github.com/mbraak/jqTree/tarball/master">Download jqTree</a>
</p>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="bs-sidebar hidden-print" id="menu" role="complementary">
<a href="#jqtree"><h2>jqTree</h2></a>
<ul class="nav bs-sidenav">
<li>
<a href="#introduction">General</a>
<ul class="nav">
<li><a href="#introduction">Introduction</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#demo">Demo</a></li>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#downloads">Downloads</a></li>
<li><a href="#tutorial">Tutorial</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#changelog">Changelog</a></li>
</ul>
</li>
<li>
<a href="#tree-options">Tree options</a>
<ul class="nav">
<li><a href="#tree-options-autoescape">autoEscape</a></li>
<li><a href="#tree-options-autoopen">autoOpen</a></li>
<li><a href="#tree-options-closedIcon">closedIcon</a></li>
<li><a href="#tree-options-data">data</a></li>
<li><a href="#tree-options-datafilter">dataFilter</a></li>
<li><a href="#tree-options-data-url">dataUrl</a></li>
<li><a href="#tree-options-draganddrop">dragAndDrop</a></li>
<li><a href="#tree-options-keyboardsupport">keyboardSupport</a></li>
<li><a href="#tree-options-oncanmove">onCanMove</a></li>
<li><a href="#tree-options-oncanmoveto">onCanMoveTo</a></li>
<li><a href="#tree-options-oncanselectnode">onCanSelectNode</a></li>
<li><a href="#tree-options-oncreateli">onCreateLi</a></li>
<li><a href="#tree-options-onismovehandle">onIsMoveHandle</a></li>
<li><a href="#tree-options-onloadfailed">onLoadFailed</a></li>
<li><a href="#tree-options-openedIcon">openedIcon</a></li>
<li><a href="#tree-options-openfolderdelay">openFolderDelay</a></li>
<li><a href="#tree-options-savestate">saveState</a></li>
<li><a href="#tree-options-selectable">selectable</a></li>
<li><a href="#tree-options-slide">slide</a></li>
<li><a href="#tree-options-usecontextmenu">useContextMenu</a></li>
</ul>
</li>
<li>
<a href="#functions">Functions</a>
<ul class="nav">
<li><a href="#functions-addnodeafter">addNodeAfter</a></li>
<li><a href="#functions-addnodebefore">addNodeBefore</a></li>
<li><a href="#functions-addparentnode">addParentNode</a></li>
<li><a href="#functions-appendnode">appendNode</a></li>
<li><a href="#functions-closenode">closeNode</a></li>
<li><a href="#functions-getnodebyid">getNodeById</a></li>
<li><a href="#functions-getselectednode">getSelectedNode</a></li>
<li><a href="#functions-getstate">getState</a></li>
<li><a href="#functions-gettree">getTree</a></li>
<li><a href="#functions-loadData">loadData</a></li>
<li><a href="#functions-loaddatafromurl">loadDataFromUrl</a></li>
<li><a href="#functions-movenode">moveNode</a></li>
<li><a href="#functions-opennode">openNode</a></li>
<li><a href="#functions-reload">reload</a></li>
<li><a href="#functions-removenode">removeNode</a></li>
<li><a href="#functions-selectnode">selectNode</a></li>
<li><a href="#functions-scrolltonode">scrollToNode</a></li>
<li><a href="#functions-setoption">setOption</a></li>
<li><a href="#functions-setstate">setState</a></li>
<li><a href="#functions-toggle">toggle</a></li>
<li><a href="#functions-tojson">toJson</a></li>
<li><a href="#functions-updatenode">updateNode</a></li>
</ul>
</li>
<li>
<a href="#events">Events</a>
<ul class="nav">
<li><a href="#event-tree-click">tree.click</a></li>
<li><a href="#event-tree-close">tree.close</a></li>
<li><a href="#event-tree-contextmenu">tree.contextmenu</a></li>
<li><a href="#event-tree-dblclick">tree.dblclick</a></li>
<li><a href="#event-tree-init">tree.init</a></li>
<li><a href="#event-tree-move">tree.move</a></li>
<li><a href="#event-tree-open">tree.open</a></li>
<li><a href="#event-tree-select">tree.select</a></li>
</ul>
</li>
<li>
<a href="#multiple-selection">Multiple selection</a>
<ul class="nav">
<li><a href="#multiple-selection-add-to-selection">addToSelection</a></li>
<li><a href="#multiple-selection-get-selected-nodes">getSelectedNodes</a></li>
<li><a href="#multiple-selection-is-node-selected">isNodeSelected</a></li>
<li><a href="#multiple-selection-remove-from-selection">remove­From­Selection</a></li>
</ul>
</li>
<li>
<a href="#node-functions">Node functions</a>
<ul class="nav">
<li><a href="#node-functions-children">children</a></li>
<li><a href="#node-functions-getdata">getData</a></li>
<li><a href="#node-functions-getlevel">getLevel</a></li>
<li><a href="#node-functions-getnextsibling">getNextSibling</a></li>
<li><a href="#node-functions-getprevioussibling">getPreviousSibling</a></li>
<li><a href="#node-functions-parent">parent</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="col-md-9" id="main">
<h4 id="introduction">Introduction</h4>
<p>
JqTree is a jQuery widget for displaying a <strong>tree structure</strong> in html. It supports
<strong>json data</strong>, loading via <strong>ajax</strong> and <strong>drag-and-drop</strong>.
</p>
<p>
<a href="https://github.com/mbraak/jqTree">
<img src="https://badge.fury.io/bo/jqtree.png" alt="Bower version">
</a>
</p>
<h4 id="features">Features</h4>
<ul>
<li>Create a tree from JSON data</li>
<li>Load data using ajax</li>
<li>Drag and drop</li>
<li>Saves the state</li>
<li>Keyboard support</li>
<li>Lazy loading</li>
<li>Works on ie8+, firefox 3.6+, chrome and safari</li>
<li>Written in Coffeescript</li>
</ul>
<p>
The project is <a href="https://github.com/mbraak/jqTree">hosted on github</a>,
has a <a href="test/test.html">test suite</a>.
</p>
<h4 id="demo">Demo</h4>
<div class="row">
<div class="col-md-6">
<pre class="demo-code"><code class="language-javascript">var data = [
{
label: 'node1',
children: [
{ label: 'child1' },
{ label: 'child2' }
]
},
{
label: 'node2',
children: [
{ label: 'child3' }
]
}
];
$('#tree1').tree({
data: data,
autoOpen: true,
dragAndDrop: true
});
</code></pre>
</div>
<div class="col-md-6">
<div id="tree1"></div>
</div>
</div>
<h4 id="requirements">Requirements</h4>
<ul>
<li><a href="http://jquery.com">jQuery</a> 1.5+ or 2.0</li>
</ul>
<h4 id="downloads">Downloads</h4>
<ul>
<li>All (version 0.21): <a href="https://github.com/mbraak/jqTree/tarball/master">jqTree.tar.gz</a></li>
<li>Javascript: <a href="tree.jquery.js">tree.jquery.js</a></li>
<li>Css: <a href="jqtree.css">jqtree.css</a></li>
<li>Image: <a href="jqtree-circle.png">jqtree-circle.png</a></li>
</ul>
<h4 id="tutorial">Tutorial</h4>
<p>
Include <a href="http://code.jquery.com/jquery.min.js">jQuery</a>.
</p>
<pre><code class="language-markup"><script src="jquery.min.js"></script></code></pre>
<p>Include tree.jquery.js:</p>
<pre><code class="language-markup"><script src="tree.jquery.js"></script></code></pre>
<p>Include jqtree.css:</p>
<pre><code class="language-markup"><link rel="stylesheet" href="jqtree.css"></code></pre>
<p>
Optionally, for saveState include <a href="https://github.com/carhartl/jquery-cookie">jquery-cookie</a>:
</p>
<pre><code class="language-markup"><script src="jquery.cookie.js"></script></code></pre>
<p>Create a div.</p>
<pre><code class="language-markup"><div id="tree1"></div></code></pre>
<p>Create tree data.</p>
<pre><code class="language-javascript">var data = [
{
label: 'node1',
children: [
{ label: 'child1' },
{ label: 'child2' }
]
},
{
label: 'node2',
children: [
{ label: 'child3' }
]
}
];
</code></pre>
<p>Create tree widget.</p>
<pre><code class="language-javascript">$(function() {
$('#tree1').tree({
data: data
});
});
</code></pre>
<p>Alternatively, get the data from the server.</p>
<pre><code class="language-javascript">$.getJSON(
'/some_url/',
function(data) {
$('#tree1').tree({
data: data
});
}
);
</code></pre>
<h4 id="examples">Examples</h4>
<ul>
<li><a href="examples/load_json_data.html">Example 1 - load json data</a></li>
<li><a href="examples/load_json_data_from_server.html">Example 2 - load json data from the server</a></li>
<li><a href="examples/drag_and_drop.html">Example 3 - drag and drop</a></li>
<li><a href="examples/save_state.html">Example 4 - save the state</a></li>
<li><a href="examples/load_on_demand.html">Example 5 - load nodes on demand from the server</a></li>
<li><a href="examples/autoescape.html">Example 6 - autoEscape</a></li>
<li><a href="examples/autoscroll.html">Example 7 - autoscroll</a></li>
<li><a href="examples/multiple_select.html">Example 8 - multiple select</a></li>
<li><a href="examples/custom_html.html">Example 9 - custom html</a></li>
<li><a href="examples/icon_buttons.html">Example 10 - use icon toggle buttons</a></li>
</ul>
<h4 id="changelog">Changelog</h4>
<h4>0.21 (june 7 2014) version</h4>
<ul>
<li>Issue 263: Improve styling of toggle button</li>
<li>Issue 266: Make it possible to use html for toggle buttons</li>
<li>Issue 262: updateNode on first level makes node disappear (thanks to Miloš Đekić)</li>
<li>Issue 260: Exempt 'select' elements from keyboard navigation (thanks to Eli Flanagan)</li>
<li>Issue 270: Fixed error 'selected_single_node is not defined' (thanks to Bryan Smith)</li>
<li>Issue 279: .jqtree-moving removed when loading subtree (thanks to Marc-Stefan Cassola)</li>
<li>Issue 280: CSS3 Circle and style optimization (thanks to Marc-Stefan Cassola)</li>
<li>Issue 283: Added function getNodesByProperty (thanks to Cedrik Vanderhaegen)</li>
<li>Issue 292: Save state if multiple nodes are selected (thanks to MykhailoP)</li>
<li>Issue 294: Handle click on input element in tree (thanks to Naeco33)</li>
</ul>
<h4>0.20 (march 9 2014)</h4>
<ul>
<li>Issue 235: Added setOption function</li>
<li>Issue 241: Prevent duplicate event call after re-initalization</li>
<li>Issue 246: Check if folder must be opened while moving node (thanks to Dave Gardner)</li>
<li>Issue 247: Improve performance of updateNode (thanks to Gordon Woodhull)</li>
<li>Issue 250: Improve performance of creating dom elements (thanks to Carlos Scheidegger)</li>
<li>Issue 252: BorderDropHint has wrong height for border-box box-sizing (thanks to simshaun)</li>
<li>Issue 253: Added reload function</li>
<li>Issue 256: Toggler button is underlined</li>
<li>Issue 257: Make it possible to open a lazily loaded folder using the keyboard</li>
<li>Issue 258: Correctly unselect children if a node is reloaded</li>
</ul>
<h4>0.19 (december 8 2013)</h4>
<ul>
<li>Issue 225: Fixes TypeError when removing nodes without ids that aren't selected (thanks to Marcus McCurdy)</li>
<li>Issue 222: scrollToNode does not consider direct parent</li>
<li>Issue 228: add property click_event to tree.click and tree.dblclick events (thanks to Gordon Woodhull)</li>
<li>Added option openFolderDelay: the delay for opening a folder during drag-and-drop (thanks to Jason Diamond)</li>
</ul>
<h4>0.18 (september 17 2013)</h4>
<ul>
<li>Issue 132: Skip keyboard handling if focus is on input element (thanks to Bingeling)</li>
<li>Issue 179 and 180: Added dataFilter option to filter the returned data from jQuery.ajax (thanks to Cheton Wu and Tony Dilger)</li>
<li>Issue 184: If the node id is 0, the id mapping is incorrect (thanks to Ika Wu)</li>
<li>Issue 190: The function selectNode should not toggle (thanks to Gordon Woodhull)</li>
<li>Issue 192: Added keyboardSupport option (thanks to Ika Wu)</li>
<li>Issue 181: Added tree.dblclick event (thanks to eskaigualker)</li>
<li>Issue 196: localStorage doesn't work in Safari private browsing (thanks to thebagg)</li>
<li>Issue 203: Adding deselected_node attribute to event object of tree.select event (thanks to tedtoer)</li>
</ul>
<h4>0.17 (july 14 2013)</h4>
<ul>
<li>Issue 132: Added keyboard support</li>
<li>Issue 154: Calling loadDataFromUrl should not trigger tree.init event (thanks to Davide Bellini)</li>
<li>Issue 158: Index not updated on updateNode (thanks to Sam Mousa)</li>
<li>Issue 159: Cannot reselect node after unselecting it (thanks to Comanche)</li>
<li>Issue 162: Added getPreviousSibling and getNextSibling functions (thanks to Dimaninc)</li>
<li>Issue 169: Added touch support (thanks to Comanche)</li>
<li>Issue 171: Added functions getState and setState</li>
<li>Issue 175: Make it possible to install jqTree using bower (thanks to Adam Miskiewicz)</li>
</ul>
<h4>0.16 (may 17 2013)</h4>
<ul>
<li>Issue 62: Added functions for multiple select</li>
<li>Issue 125: Add option for overriding TRIANGLE_RIGHT and TRIANGLE_DOWN (thanks to Sam D)</li>
<li>Issue 126: Event tree.open event fires after first tree.select on top level node</li>
<li>Issue 129: Allow native context menu to be display (thanks to Charles Bourasseau)</li>
<li>Issue 130: Selectable not implemented (thanks to Sam D)</li>
<li>Issue 133: loadDataFromUrl doesn't work when only parent_node and callback are passed in (thanks to Simone Deponti)</li>
<li>Issue 134: selectNode from inside tree.init breaks on loadData (thanks to Sam D)</li>
<li>Issue 145: Auto-open nodes with drag n drop when drag not enabled for that node (thanks to Daniel Powell)</li>
<li>Issue 146: Added function scrollToNode (thanks to Davide Bellini)</li>
</ul>
<h4>0.15 (march 16 2013)</h4>
<ul>
<li>Issue 100: Clicking on the jqtree-element element will trigger click event</li>
<li>Issue 102: Add original event to tree.move event</li>
<li>Issue 103: Added getLevel function to Node class</li>
<li>Issue 104: The addNodeBefore method must return the new node</li>
<li>Issue 105: Added nodeClass option</li>
<li>Issue 112: Fix call to iterate in removeNode (thanks to Ingemar Ådahl)</li>
<li>Issue 113: Added onLoadFailed option (thanks to Shuhei Kondo)</li>
<li>Issue 118: Deselect a node when click and already selected</li>
<li>Issue 119: Make it easier to reload a subtree</li>
<li>Issue 121: Unselect node if it's reloaded by loadDataFromUrl</li>
</ul>
<h4>0.14 (december 2 2012)</h4>
<h6>Api changes</h6>
<ul>
<li>Removed parameter <strong>must_open_parents</strong> from function <strong>selectNode</strong>.</li>
<li>Changed <strong>slide</strong> parameter in functions <strong>openNode</strong> and <strong>closeNode</strong>.</li>
</ul>
<h6>Issues</h6>
<ul>
<li>Issue 80: Support more options for loading data from the server. E.g. the 'post' method (thanks to Rodrigo Rosenfeld Rosas)</li>
<li>Issue 81: getSelectedNode must return false if node is removed</li>
<li>Issue 82: Autoscroll for drag-and-drop</li>
<li>Issue 84: Fix correct type param in $.ajax() (thanks to Rodrigo Rosenfeld Rosas)</li>
<li>Issue 85: Option to turn slide animation on or off</li>
<li>Issue 86: The openNode function must automatically open parents</li>
<li>Issue 87: Remove the must_open_parents parameter from the selectNode function</li>
<li>Issue 88: selectNode must also work if selectable option is false</li>
<li>Issue 89: Clicking in title with img or em does not work</li>
<li>Issue 96: Added jqtree_common class to avoid css clashes (thanks to Yaniv Iny)</li>
</ul>
<h4>0.13 (october 10 2012)</h4>
<ul>
<li>Issue 54: Added tree.select event</li>
<li>Issue 63: Fixed contextmenu event</li>
<li>Issue 67: Use unicode characters for triangle buttons (thanks to Younès)</li>
<li>Issue 70: Load data from the server using the loadData function</li>
<li>Issue 78: Drag and drop is trigger happy</li>
</ul>
<h4>0.12 (august 14 2012)</h4>
<ul>
<li>Issue 46: Added tree.refresh event</li>
<li>Issue 47: Function 'selectNode' must properly open the parent nodes</li>
<li>Issue 49: Make sure that widget functions can be called in the 'tree.init' event</li>
<li>Issue 50: Add namespace to css classes</li>
<li>Issue 51: closeNode to collapse tree doesn't work</li>
<li>Issue 55: Load-on-demand from the server</li>
<li>Issue 58: Added updateNode function</li>
<li>Issue 59: Added moveNode function</li>
<li>Issue 60: Use native JSON.stringify function</li>
</ul>
<h4>0.11 (july 8 2012)</h4>
<ul>
<li>Autoescape text</li>
<li>Added autoEscape option</li>
<li>Issue 33: appendNode does not correctly refresh the tree</li>
<li>Issue 34: unset internal pointer to previously selected node on DOM deselect</li>
<li>Issue 38: Correctly check if browser has support for localstorage</li>
<li>Issue 41: Open nodes are not displayed correctly in ie7</li>
</ul>
<h4>0.10 (june 10 2012)</h4>
<ul>
<li>Optimized getNodeById</li>
<li>Issue #18 and #26: Made comparison in getNodeById less strict</li>
<li>Added function prependNode</li>
<li>Added 'data-url' option</li>
<li>Added removeNode function</li>
<li>Issue #24: Tree with jquery ui Dialog: expand causes resize and move problem</li>
<li>Added Travis ci support</li>
<li>Added addNodeAfter, addNodeBefore and addParentNode</li>
<li>Renamed icons.png to jqtree-icons.png</li>
<li>selectNode with empty node deselects the current node</li>
</ul>
<h4>0.9 (may 9 2012)</h4>
<ul>
<li>Issue 15: 'tree.open' event is not triggered when dragging nodes</li>
<li>Issue 18: Allow moveNode to be canceled through ev.preventDefault()</li>
<li>Use sprite for images</li>
<li>Added function closeNode</li>
<li>Added support for localstorage</li>
<li>Implemented alternative data format</li>
</ul>
<h4>0.8 (april 18 2012)</h4>
<ul>
<li>Replace jquery.ui widget with SimpleWidget</li>
<li>Added 'previous_parent' to 'tree.move' event</li>
<li>Add posibility to load subtree</li>
<li>Added 'tree.open' and 'tree.close' events</li>
</ul>
<h3 id="tree-options">Tree options</h3>
<h4 id="tree-options-autoescape">autoEscape</h4>
<p>
Determine if text is autoescaped. The default is true.
</p>
<h4 id="tree-options-autoopen">autoOpen</h4>
<p>
Open nodes initially.
</p>
<ul>
<li>
<strong>true</strong>: open all nodes.
</li>
<li>
<strong>false (default)</strong>: do nothing
</li>
<li><strong>n</strong>: open n levels</li>
</ul>
<p>
Open all nodes initially:
</p>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
autoOpen: true
});
</code></pre>
<p>
Open first level nodes:
</p>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
autoOpen: 0
});
</code></pre>
<h4 id="tree-options-closedIcon">closedIcon</h4>
<p>
A character or symbol to display on closed nodes. The default is '&#x25ba;' (►)
</p>
<pre><code class="language-javascript">$('#tree1').tree({
closedIcon: '+'
});
</code></pre>
<h4 id="tree-options-data">data</h4>
<p>
Define the contents of the tree. The data is a nested array of objects. This option is required.
<br>
It looks like this:
</p>
<pre><code class="language-javascript">var data = [
{
label: 'node1',
children: [
{ label: 'child1' },
{ label: 'child2' }
]
},
{
label: 'node2',
children: [
{ label: 'child3' }
]
}
];
$('#tree1').tree({data: data});
</code></pre>
<ul>
<li>label: label of a node (required)</li>
<li>children: array of child nodes (optional)</li>
</ul>
<p>
You can also include other data in the objects. You can later access this data.
<br>
For example, to add an id:
</p>
<pre><code class="language-javascript">{
label: 'node1',
id: 1
}
</code></pre>
<h4 id="tree-options-datafilter">dataFilter</h4>
<p>
Process the tree data from the server.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
url: '/my/data/',
dataFilter: function(data) {
// Example:
// the server puts the tree data in 'my_tree_data'
return data['my_tree_data'];
}
});
</code></pre>
<h4 id="tree-options-data-url">dataUrl</h4>
<p>
Load the node data from this url.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
dataUrl: '/example_data.json'
});
</code></pre>
<p>
You can also set the <strong>data-url</strong> attribute on the dom element:
</p>
<pre><code class="language-markup"><div id="tree1" data-url="/example_data.json"></div>
<script>
$('#tree1').tree();
</script>
</code></pre>
<h4 id="tree-options-draganddrop">dragAndDrop</h4>
<p>
Turn on dragging and dropping of nodes.
</p>
<ul>
<li><strong>true</strong>: turn on drag and drop</li>
<li><strong>false (default)</strong>: do not allow drag and drop</li>
</ul>
<p>
Example: turn on drag and drop.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
dragAndDrop: true
});
</code></pre>
<h4 id="tree-options-keyboardsupport">keyboardSupport</h4>
<p>
Enable or disable keyboard support. Default is enabled.
</p>
<p>
Example: disable keyboard support.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
keyboardSupport: false
});
</code></pre>
<h4 id="tree-options-oncanmove">onCanMove</h4>
<p>
You can override this function to determine if a node can be moved.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
dragAndDrop: true,
onCanMove: function(node) {
if (! node.parent.parent) {
// Example: Cannot move root node
return false;
}
else {
return true;
}
}
});
</code></pre>
<h4 id="tree-options-oncanmoveto">onCanMoveTo</h4>
<p>
You can override this function to determine if a node can be moved to a certain position.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
dragAndDrop: true,
onCanMoveTo: function(moved_node, target_node, position) {
if (target_node.is_menu) {
// Example: can move inside menu, not before or after
return (position == 'inside');
}
else {
return true;
}
}
});
</code></pre>
<h4 id="tree-options-oncanselectnode">onCanSelectNode</h4>
<p>
You can set a function to override if a node can be selected. The function gets a node as parameter, and must return true or false.
<br />
For this to work, the option 'selectable' must be 'true'.
</p>
<pre><code class="language-javascript">// Example: nodes with children cannot be selected
$('#tree1').tree({
data: data,
selectable: true
onCanSelectNode: function(node) {
if (node.children.length == 0) {
// Nodes without children can be selected
return true;
}
else {
// Nodes with children cannot be selected
return false;
}
}
});
</code></pre>
<h4 id="tree-options-oncreateli">onCreateLi</h4>
<p>
The function is called for each created node. You can use this to define extra html.
</p>
<pre><code class="language-javascript">$('#tree1).tree({
data: data,
onCreateLi: function(node, $li) {
// Add 'icon' span before title
$li.find('.jqtree-title').before('<span class="icon"></span>');
}
});
</code></pre>
<h4 id="tree-options-onismovehandle">onIsMoveHandle</h4>
<p>
You can override this function to determine if a dom element can be used to move a node.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
onIsMoveHandle: function($element) {
// Only dom elements with 'jqtree-title' class can be used
// as move handle.
return ($element.is('.jqtree-title'));
}
});
</code></pre>
<h4 id="tree-options-onloadfailed">onLoadFailed</h4>
<p>
When loading the data by ajax fails, then the option <strong>onLoadFailed</strong> is called.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
url: '/my/data/',
onLoadFailed: function(response) {
//
}
});
</code></pre>
<h4 id="tree-options-openedIcon">openedIcon</h4>
<p>
A character or symbol to display on opened nodes. The default is '&#x25bc;' (▼)
</p>
<pre><code class="language-javascript">$('#tree1').tree({
openedIcon: '-'
});
</code></pre>
<h4 id="tree-options-openfolderdelay">openFolderDelay</h4>
<p>
Set the delay for opening a folder during drag-and-drop. The delay is in milliseconds. The default is 500 ms.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
url: '/my/data/',
openFolderDelay: 1000
});
</code></pre>
<h4 id="tree-options-savestate">saveState</h4>
<p>
Save and restore the state of the tree automatically. Saves in a cookie which nodes are opened and selected.
<br>
The state is saved in localstorage. In browsers that do not support localstorage, the state is saved in a cookie.
For this to work, please include <a href="https://github.com/carhartl/jquery-cookie">jquery-cookie</a>.
</p>
<p>
For this to work, you should give each node in the tree data an id field:
</p>
<pre><code class="language-javascript">{
label: 'node1',
id: 123,
childen: [
label: 'child1',
id: 124
]
}
</code></pre>
<ul>
<li><strong>true</strong>: save and restore state in a cookie</li>
<li><strong>false (default)</strong>: do nothing</li>
<li><strong>string</strong>: save state and use this name to store in a cookie</li>
</ul>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
saveState: true
});
</code></pre>
<p>
Example: save state in key 'tree1':
</p>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
saveState: 'tree1'
});
</code></pre>
<h4 id="tree-options-selectable">selectable</h4>
<p>
Turn on selection of nodes.
</p>
<ul>
<li><strong>true (default)</strong>: turn on selection of nodes</li>
<li><strong>false</strong>: turn off selection of nodes</li>
</ul>
<p>
Example: turn off selection of nodes.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
data: data,
selectable: false
});
</code></pre>
<h4 id="tree-options-slide">slide</h4>
<p>
Turn slide animation on or off. Default is true.
</p>
<pre><code class="language-javascript">$('#tree1').tree({
slide: false
});
</code></pre>
<h4 id="tree-options-usecontextmenu">useContextMenu</h4>
<p>
Bind the context menu event (true/false).
</p>
<p>
<strong>true</strong> (default)
<br>
A right mouse-click will trigger a <a href="#event-tree-contextmenu">tree.contextmenu</a> event. This overrides the native contextmenu of the browser.
</p>
<p>
<strong>false</strong>
<br>
A right mouse-click will trigger the native contextmenu of the browser.
</p>
<h3 id="functions">Functions</h3>
<h4 id="functions-addnodeafter">addNodeAfter</h4>
<p>
<strong>function addNodeAfter(new_node_info, existing_node);</strong>
</p>
<p>
Add a new node after this existing node.
</p>
<pre><code class="language-javascript">var node1 = $('#tree1', 'getNodeByName', 'node1');
$('#tree1').tree(
'addNodeAfter',
{
label: 'new_node',
id: 456
},
node1
);
</code></pre>
<h4 id="functions-addnodebefore">addNodeBefore</h4>
<p>
<strong>function addNodeBefore(new_node_info, existing_node);</strong>
</p>
<p>
Add a new node before this existing node.
</p>
<h4 id="functions-appendnode">appendNode</h4>
<p>
<strong>function appendNode(new_node_info, parent_node);</strong>
</p>
<p>
Add a node to this parent node. If <strong>parent_node</strong> is empty, then the new node becomes a root node.
</p>
<pre><code class="language-javascript">var parent_node = $tree.tree('getNodeById', 123);
$tree.tree(
'appendNode',
{
label: 'new_node',
id: 456
},
parent_node
);
</code></pre>
<p>
To add a root node, leave *parent_node* empty:
</p>
<pre><code class="language-javascript">$tree.tree(
'appendNode',
{
label: 'new_node',
id: 456
}
);
</code></pre>
<h4 id="functions-closenode">closeNode</h4>
<p>
<strong>function closeNode(node);</strong>
<br>
<strong>function closeNode(node, slide);</strong>
</p>
<p>
Close this node. The node must have child nodes.
<br>
Parameter <strong>slide</strong>: close the node using a slide animation (default is true).
</p>
<pre><code class="language-javascript">var node = $tree.tree('getNodeById', 123);
$tree.tree('closeNode', node);
</code></pre>
<p>
To close the node without the slide animation, call with <strong>slide</strong> parameter is false.
</p>
<pre><code class="language-javascript">$tree.tree('closeNode', node, false);</code></pre>
<h4 id="functions-getnodebyid">getNodeById</h4>
<p>
<strong>function getNodeById(id);</strong>
<br>
Get a tree node by node-id. This assumes that you have given the nodes in the data a unique id.
</p>
<pre><code class="language-javascript">var $tree = $('#tree1');
var data = [
{ id: 10, name: 'n1' },
{ id: 11, name: 'n2' }
];
$tree.tree({
data: data
});
var node = $tree.tree('getNodeById', 10);
</code></pre>
<h4 id="functions-getselectednode">getSelectedNode</h4>
<p>
Get the selected node. Returns the row data or false.
</p>
<pre><code class="language-javascript">var node = $tree.tree('getSelectedNode');</code></pre>
<h4 id="functions-getstate">getState</h4>
<p>
<strong>function getState();</strong>
</p>
<p>
Get the state of tree: which nodes are open and which one is selected?
</p>
<h4 id="functions-gettree">getTree</h4>
<p>
<strong>function getTree();</strong>
</p>
<p>
Get the root node of the tree.
</p>
<h4 id="functions-loadData">loadData</h4>
<p>
<strong>function loadData(data);</strong>
<br>
<strong>function loadData(data, parent_node);</strong>
<br>
</p>
<p>
Load data in the tree. The data is array of nodes.
<br>
You can <strong>replace the whole tree</strong> or you can <strong>load a subtree</strong>.
</p>
<pre><code class="language-javascript">// Assuming the tree exists
var new_data = [
{
label: 'node1',
children: [
{ label: 'child1' },
{ label: 'child2' }
]
},
{
label: 'node2',
children: [
{ label: 'child3' }
]
}
];
$('#tree1').tree('loadData', new_data);
</code></pre>
<p>
Load a subtree:
</p>
<pre><code class="language-javascript">// Get node by id (this assumes that the nodes have an id)
var node = $('#tree1').tree('getNodeById', 100);
// Add new nodes
var data = [
{ label: 'new node' },
{ label: 'another new node' }
];
$('#tree1').tree('loadData', data, node);
</code></pre>
<h4 id="functions-loaddatafromurl">loadDataFromUrl</h4>
<p>
<strong>function loadDataFromUrl(url);</strong>
<br>
<strong>function loadDataFromUrl(url, parent_node);</strong>
<br>
<strong>function loadDataFromUrl(parent_node);</strong>
</p>
<p>
Load data in the tree from an url using ajax. You can <strong>replace the whole tree</strong> or you can <strong>load a subtree</strong>.
</p>
<pre><code class="language-javascript">$('#tree1').tree('loadDataFromUrl', '/category/tree/');</code></pre>
<p>
Load a subtree:
</p>
<pre><code class="language-javascript">var node = $('#tree1').tree('getNodeById', 123);
$('#tree1').tree('loadDataFromUrl', '/category/tree/123', node);