-
Notifications
You must be signed in to change notification settings - Fork 36
/
aciTree.html
1854 lines (1703 loc) · 94.2 KB
/
aciTree.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 http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="index, follow">
<title>aciTree demo - A javascript treeview control with jQuery</title>
<meta name="description" content="A demo to show you how aciTree can be used, check the plugin page to see all the functions exposed by the API">
<meta name="keywords" content="aciTree, treeview, control, tree view, javascript, jQuery">
<link rel="stylesheet" type="text/css" href="css/aciTree.css" media="all">
<link rel="stylesheet" type="text/css" href="css/demo.css" media="all">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.aciPlugin.min.js"></script>
<script type="text/javascript" src="js/jquery.aciSortable.min.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.dom.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.core.js"></script>
<!--<script type="text/javascript" src="js/jquery.aciTree.aria.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.en_EN.js"></script>-->
<script type="text/javascript" src="js/jquery.aciTree.utils.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.selectable.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.checkbox.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.radio.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.column.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.editable.js"></script>
<script type="text/javascript" src="js/jquery.aciTree.sortable.js"></script>
<!--<script type="text/javascript" src="js/jquery.aciTree.persist.js"></script>
<script type="text/javascript" src="js/jstorage.min.js"></script>-->
</head>
<body>
<div>
<p>Here you have a simple implementation of a file system treeview with the most features available to be changed at the runtime from the interface
(see the treeview/right form elements on the bottom of the page).</p>
<p>You can find a simple PHP implementation in the download (source code) but any server-side language can be used. aciTree needs the data in JSON
format and it's using AJAX to load the children of a inner node (once required).</p>
<p>Note: I recommend checking the code from the other demos as this page can be complex for someone new to aciTree. Also, do not forget to check the API docs
before you try using the methods and also check online on the plugin page for extra info (like the plugin init options and how to use the events).</p>
<a href="/en/aciTree-tree-view-with-jQuery" title="Back to home page">Back to home page</a>
<h2>Available aciTree treeview demos</h2>
<ul style="list-style-type:none;padding:0;line-height:30px">
<li>New to aciTree? try <a href="sample/index.html" target="_blank" title="aciTree treeview API usage samples">aciTree treeview API usage samples</a></li>
<li>using aciTree treeview with <a href="aciTree-checkbox.html" target="_blank" title="aciTree treeview with checkboxes">checkboxes</a></li>
<li>using aciTree treeview with <a href="aciTree-radio.html" target="_blank" title="aciTree treeview with radio-buttons">radio-buttons</a></li>
<li>aciTree treeview with <a href="/demo/aciTree.html" target="_blank" title="aciTree treeview with columns">multiple columns</a></li>
<li>updating aciTree treeview <a href="/demo/aciTree-column-width.html" target="_blank" title="aciTree treeview column width">columns width</a></li>
<li>save/restore aciTree treeview item states using <a href="/demo/aciTree_persist.html" target="_blank" title="aciTree treeview item states with local storage">local storage</a></li>
<li>aciTree treeview and <a href="/demo/aciTree_hash.html" target="_blank" title="aciTree treeview with aciFragment">URL fragments</a></li>
<li>aciTree treeview with <a href="aciTree-drag-drop.html" target="_blank" title="aciTree treeview DND sorting">drag & drop</a></li>
<li>using aciTree treeview with <a href="/demo/aciTree-tooltip.html" target="_blank" title="aciTree treeview with jQuery UI tooltips">jQuery UI tooltips</a></li>
<li>using aciTree treeview with <a href="/demo/aciTree-ui-dialog.html" target="_blank" title="aciTree treeview with jQuery UI dialogs">jQuery UI dialogs</a></li>
<li>using aciTree treeview with <a href="/demo/aciTree-ui-tabs.html" target="_blank" title="aciTree treeview with jQuery UI tabs">jQuery UI tabs</a></li>
<li>aciTree treeview with <a href="/demo/aciTree-custom-data.html" target="_blank" title="aciTree treeview custom data format">custom data format</a></li>
<li>aciTree treeview with <a href="/demo/aciTree-data-source.html" target="_blank" title="aciTree treeview multiple data sources">multiple data sources</a></li>
<li>aciTree treeview client-side <a href="/demo/aciTree-filter-search.html" target="_blank" title="aciTree treeview filter & search">filter & search</a></li>
<li>aciTree treeview and <a href="/demo/aciTree-full-size.html" target="_blank" title="aciTree treeview full size">full window width</a></li>
<li>aciTree treeview with a <a href="/demo/aciTree-context-menu.html" target="_blank" title="aciTree treeview context menu">context menu</a></li>
<li>(<span style="color:red">new</span>) aciTree treeview <a href="/aciTreeEditor/index.html" target="_blank" title="aciTree treeview Editor">editor</a></li>
</ul>
<p>Note: in the demo below - the node loading it's made with a delay so you can see the loading animation.
If you want you can remove the delay from the included <i>PHP</i> script.</p>
<p id="info">Hover over a tree item to show his info (using the aciTree API) ...</p>
<div id="tree" class="aciTree"><div class="eyes"></div><div>
<a style="font-size:10px" href="/source/php/niceJson.php?file=source/aciTree/php/aciTree.php?branch=" title="See the JSON data" target="_blank">see the JSON behind this tree</a>
<br>Anything here or just remove</div></div>
<div class="form">
<form action="" enctype="application/x-www-form-urlencoded" method="post" target="_self">
<table cellspacing="0" cellpadding="10" border="0"><tr><td width="300">
<p>Filter: <input type="text" id="filter" value=""> (<span style="color:blue">note</span>)</p>
<p>Use Animations: <label><input type="radio" name="animate" value="1"> Yes</label>
<label><input type="radio" name="animate" value="0"> No</label></p>
<p>Expand All: <label><input type="radio" name="expand" value="1"> Yes</label>
<label><input type="radio" name="expand" value="0"> No</label></p>
<p>Collapse All: <label><input type="radio" name="collapse" value="1"> Yes</label>
<label><input type="radio" name="collapse" value="0"> No</label></p>
<p>Unique on Open: <label><input type="radio" name="unique" value="1"> Yes</label>
<label><input type="radio" name="unique" value="0"> No</label></p>
<p>Empty on Close: <label><input type="radio" name="empty" value="1"> Yes</label>
<label><input type="radio" name="empty" value="0"> No</label></p>
<p>Selectable: <label><input type="radio" name="selectable" value="1"> Yes</label>
<label><input type="radio" name="selectable" value="0"> No</label></p>
<p>Multi-Selectable <label><input type="radio" name="multiSelectable" value="1"> Yes</label>
<label><input type="radio" name="multiSelectable" value="0"> No</label></p>
<p>Full Row: <label><input type="radio" name="fullRow" value="1"> Yes</label>
<label><input type="radio" name="fullRow" value="0"> No</label></p>
<p>Text Selection: <label><input type="radio" name="textSelection" value="1"> Enabled</label>
<label><input type="radio" name="textSelection" value="0"> Disabled</label></p>
<p>Sortable: <label><input type="radio" name="sortable" value="1"> Enabled</label>
<label><input type="radio" name="sortable" value="0"> Disabled</label></p>
<p>Checkboxes: <label><input type="radio" name="checkbox" value="1"> Yes</label>
<label><input type="radio" name="checkbox" value="0"> No</label></p>
<p>Chain Checkboxes: <label><input type="radio" name="checkboxChain" value="true"> Yes</label>
<label><input type="radio" name="checkboxChain" value="-1"> Update Parents</label>
<label><input type="radio" name="checkboxChain" value="1"> Update Children </label>
<label><input type="radio" name="checkboxChain" value="false"> No</label></p>
<p>Checkbox Break: <label><input type="radio" name="checkboxBreak" value="1"> Yes</label>
<label><input type="radio" name="checkboxBreak" value="0"> No</label></p>
<p>Checkbox-Only Click: <label><input type="radio" name="checkboxClick" value="1"> Yes</label>
<label><input type="radio" name="checkboxClick" value="0"> No</label></p>
<p>Radio Buttons: <label><input type="radio" name="radio" value="1"> Yes</label>
<label><input type="radio" name="radio" value="0"> No</label></p>
<p>Chain Radio Buttons: <label><input type="radio" name="radioChain" value="1"> Yes</label>
<label><input type="radio" name="radioChain" value="0"> No</label></p>
<p>Radio Button Break: <label><input type="radio" name="radioBreak" value="1"> Yes</label>
<label><input type="radio" name="radioBreak" value="0"> No</label></p>
<p>Radio-Only Click: <label><input type="radio" name="radioClick" value="1"> Yes</label>
<label><input type="radio" name="radioClick" value="0"> No</label></p>
<p>Editable: <label><input type="radio" name="editable" value="1"> Yes</label>
<label><input type="radio" name="editable" value="0"> No</label></p>
<p><input id="destroy" type="button" value="Destroy">
<input id="init" type="button" value="Init with AJAX"></p>
<p><input id="init_data" type="button" value="Init from Data">
<input id="init_huge" type="button" value="Init Huge">
<input id="clear_log" type="button" value="Clear Log"></p>
<p id="selected">Select a Tree item or the Tree itself (<span style="color:red">note</span>)!</p>
<p>Mode: <label><input type="radio" name="addMode" value="before"> Add Before</label>
<label><input type="radio" name="addMode" value="after" checked="checked"> Add After</label></p>
<p><input id="addFile" type="button" value="Add File">
<input id="addFolder" type="button" value="Add Folder">
<input id="addChilds" type="button" value="Add Children"></p>
<p><input id="unload" type="button" value="Unload Folder/Tree">
<input id="load" type="button" value="Load Folder/Tree"></p>
<p><input id="setFile" type="button" value="Set as File">
<input id="setFolder" type="button" value="Set as Folder">
<input id="remove" type="button" value="Remove"></p>
</td><td>
<!--<input id="reloadJs" type="button" value="Reload JS">-->
<p>Size: <label><input type="radio" name="esize" value="small"> Smaller</label>
<label><input type="radio" name="esize" value="big"> Bigger</label></p>
<p>Node Button: <label><input type="radio" name="nodebtn" value="square"> Square</label>
<label><input type="radio" name="nodebtn" value="arrow"> Arrow</label></p>
<p>Show Branches: <label><input type="radio" name="branches" value="1"> Yes</label>
<label><input type="radio" name="branches" value="0"> No</label></p>
<p>Direction: <label><input type="radio" name="direction" value="1"> LTR</label>
<label><input type="radio" name="direction" value="0"> RTL</label></p>
<p>Odd/Even Rows: <label><input type="radio" name="oddeven" value="1"> Yes</label>
<label><input type="radio" name="oddeven" value="0"> No</label></p>
<p>Set Icon: <select id="setIcon"><option value="">-- choose --</option>
<option value="file">File</option><option value="folder">Folder</option><option value="remove">Remove</option></select></p>
<p>Set Checkbox: <select id="setCheckbox"><option value="">-- choose --</option>
<option value="yes">Yes</option><option value="No">No</option></select></p>
<p>Set Radio: <select id="setRadio"><option value="">-- choose --</option>
<option value="yes">Yes</option><option value="No">No</option></select></p>
<p>Item: <input id="disable" type="button" value="Disable">
<input id="enable" type="button" value="Enable">
(<span style="color:blue">note</span>) <input id="hide" type="button" value="Hide"> <input id="show" type="button" value="Show">
<input id="hideshow" type="button" value="Toggle"></p>
<p>Node: <input id="open" type="button" value="Open"> <input id="close" type="button" value="Close">
<input id="toggle" type="button" value="Toggle"></p>
<p>Burn some CPU: <input id="addFile10k" type="button" value="Add 10k Files">
<input id="addFolder10k" type="button" value="Add 10k Folders"></p>
<p>Using 'branch': <input id="branch_open" type="button" value="Open All"> <input id="branch_close" type="button" value="Close All">
<input id="branch_toggle" type="button" value="Toggle All"></p>
<p>Search ID: <input type="text" name="item_id" value="/Item 1/document 1.txt" size="23"><input type="button" id="item_id_btn" value="@">
<input id="set_visible" type="button" value="Set Visible"></p>
<p>Search Params: <label><input type="checkbox" name="search_load" value="1"> Use Load</label></p>
<p><label>Item Content:</label>
<textarea name="item_cnt">a long item text haha this is a looooong text to be set for a item<br>with a brake...<br>more lines</textarea>
<input id="set_cnt" type="button" value="Set Content"></p>
<p>Move Item: <input id="move_up" type="button" value="Up"> <input id="move_down" type="button" value="Down">
<input id="move_first" type="button" value="First Position"> <input id="move_last" type="button" value="Last Position"></p>
<p>Move Before/After/As Child (by ID): <input type="text" name="move" value="/document a.txt" size="18"><input type="button" id="move_btn" value="@"> <br>
<input id="move_before" type="button" value="Move Before"> <input id="move_after" type="button" value="Move After">
<input id="move_child" type="button" value="As Child"></p>
<p>Set Index: <input type="text" name="index" value="0" size="23">
<input id="set_index" type="button" value="Set Index"></p>
<p>Swap Item (by ID): <input type="text" name="swap1" value="/document b.txt"><input type="button" id="swap1_btn" value="@"> <br> with
<input type="text" name="swap2" value="/Item 3"><input type="button" id="swap2_btn" value="@"> <input id="swap" type="button" value="Swap"></p>
<p>Cancel UI Tasks : <label><input type="radio" name="cancel_ui" value="1"> Yes</label>
<label><input type="radio" name="cancel_ui" value="0"> No</label></p>
<p>Cancel User-Defined Tasks : <label><input type="radio" name="cancel_user" value="1"> Yes</label>
<label><input type="radio" name="cancel_user" value="0"> No</label></p>
<p>Serialize (see the log):
<input id="serialize_checkbox" type="button" value="Checkbox">
<input id="serialize_radio" type="button" value="Radio">
<input id="serialize_json" type="button" value="Item Data"></p>
</td></tr></table>
</form>
</div>
<div class="log">Tree Log... <a class="clear_log" style="font-size:10px" href="#" title="Clear the LOG" target="_blank">clear log</a>
<div></div></div>
<div style="float:left"><p>Test JavaScript code performance:<br>(see the log for output)</p>
<textarea class="testarea" style="width:315px;height:200px">alert('children: ' + treeApi.children(null, true, true).length);</textarea>
<p><input type="button" name="testarea" value="Test"></p></div>
<p style="clear:both"><br><span style="color:red">Note</span>: the selected pink item does not have anything to do with the <i>selectable</i> option, it's there just to be able to 'select' the
entire tree (not only a item).<br>All item based functions are made - in this demo - to run against the pink selected item (and not the <i>real</i> selected item - when/if the
selectable option is used).</p>
<p><span style="color:blue">Note</span>: for this demo I have changed the default style from `display:none` for `.aciTreeHidden`
so you can have a chance to show again a hidden item. The `hidden` items will have a darker background.</p>
</div>
<script language="javascript" type="text/javascript">
$(function() {
// Tree API
var treeApi;
// if we want to init without one initial AJAX request :)
var rootData = [{
id: "\/Item 1",
label: "Item 1 - From rootData",
branch: [],
inode: true,
open: false,
icon: "folder",
random: 34
},
{
id: "\/Item 2",
label: "Item 2 - very long item text<br>with a brake",
branch: [],
inode: true,
open: false,
icon: "folder",
random: 9
},
{
id: "\/Item 3",
label: "Item 3",
branch: [],
inode: false,
open: false,
icon: "folder",
random: 26
},
{
id: "\/Item 4",
label: "Item 4",
branch: [],
inode: false,
open: false,
icon: "folder",
random: 71
},
{
id: "\/Item 5",
label: "Item 5",
branch: [],
inode: true,
open: false,
icon: "folder",
random: 93
},
{
id: "\/Item 6",
label: "Item 6",
branch: [],
inode: false,
open: false,
icon: "folder",
random: 14
},
{
id: "\/Item 7",
label: "Item 7",
branch: [],
inode: true,
open: false,
icon: "folder",
random: 49
},
{
id: "\/Item 8",
label: "Item 8",
branch: [],
inode: true,
open: false,
icon: "folder",
random: 99
},
{
id: "\/document a.txt",
label: "document a.txt",
branch: [],
inode: false,
open: false,
icon: "file",
random: 86
},
{
id: "\/document b.txt",
label: "document b.txt",
branch: [],
inode: false,
open: false,
icon: "file",
random: 76
},
{
id: "\/document c.txt",
label: "document c.txt",
branch: [],
inode: false,
open: false,
icon: "file",
random: 11
}];
// the tree container
var theTree = $('#tree');
// init the Tree
function initTree(type, ui, skip) {
treeApi = theTree.aciTree({
autoInit: false,
ajax: {
url: (type == 'huge') ? 'php/hugeTree.php?branch=' : 'php/aciTree.php?branch='/*,
// our custom data processing function (see jQuery.ajax)
converters: {
'text json': function(data) {
var json = $.parseJSON(data);
var recursive = function(item) {
item.inode = item.isFolder;
item.branch = item.childs;
for (var i in item.branch) {
recursive(item.branch[i]);
}
};
for (var i in json) {
recursive(json[i]);
}
return json;
}
}*/
},
rootData: (type == 'data') ? rootData : null,
itemHook: function(parent, item, itemData, level) {
// a custom item implementation to show the tree level
this.setLabel(item, {
label: itemData.label + ' (' + level + ')'
});
},
persist: 'mytree'/*,
columnData: [{
width: 80,
props: 'c1',
value: 'column #1'
}, {
width:80,
props: 'c2',
value: 'column #2'
}]*/
}).aciTree('api');
treeApi.init({
uid: (ui == 'ui') ? 'ui' : 'user-defined',
success: function() {
if (!skip) {
alert('The treeview control was init !');
}
},
fail: function() {
alert('Failed to init the treeview control !');
}
});
}
var log = $('.log div');
function alert(message) {
log.prepend('<p style="color:red">' + message + '</p>');
}
var eye = $('.eyes'), eyes = 0;
// a little animation :)
function showEyes() {
if (eyes > 2) {
eyes = 0;
}
eye.css('background-position', '0 -' + (eyes * 48) + 'px');
}
theTree.scroll(function() {
eye.css('top', $(this).scrollTop() + 'px');
});
var cancelUi = false, cancelUser = false;
// show tree events
theTree.on('acitree', function(event, api, item, eventName, options) {
if (options.uid == 'skip-log') {
return;
}
if (eventName.search(/^before/) != -1) {
// cancel if requested
if ((cancelUi && (options.uid == 'ui')) || (cancelUser && (options.uid != 'ui'))) {
if (item) {
log.prepend('<p>(canceled) ' + eventName + ' [' + api.getId(item) + '] [' + options.uid + ']</p>');
} else {
log.prepend('<p>(canceled) ' + eventName + ' [tree] [' + options.uid + ']</p>');
}
return false;
}
}
if (api.isLocked()) {
// prevent write to log on init/destroy
return;
}
switch (eventName) {
case 'idset':
log.prepend('<p>' + eventName + ' [' + api.getId(item) + '] old ID: [' + options.oldId + '] [' + options.uid + ']</p>');
break;
case 'labelset':
log.prepend('<p>' + eventName + ' [' + api.getId(item) + '] old label: [' + options.oldLabel + '] [' + options.uid + ']</p>');
break;
case 'swapped':
var item1 = options.item1;
var item2 = options.item2;
log.prepend('<p>' + eventName + ' [' + api.getId(item1) + '] <=> [' + api.getId(item2) + '] [' + options.uid + ']</p>');
if (!api.isVisible(item1) && !api.isVisible(item2)) {
// make one item visible (check by index, not a problem if not with the same parent ...
if (api.getIndex(item1) < api.getIndex(item2)) {
api.setVisible(item1);
} else {
api.setVisible(item2);
}
}
break;
case 'indexset':
log.prepend('<p>' + eventName + ' [' + api.getId(item) + '] old index: [' + options.oldIndex + '] [' + options.uid + ']</p>');
if (!api.isVisible(item)) {
// make it visible ;)
api.setVisible(item);
}
break;
case 'filtered':
log.prepend('<p>' + eventName + ' [' + options.search + '] first match: [' + api.getId(options.first) + '] [' + options.uid + ']</p>');
break;
case 'sorted':
log.prepend('<p>' + eventName + ' [' + api.getId(item) + '] moved inside [' + api.getId(api.parent(item)) + ']</p>');
break;
default:
if (item) {
log.prepend('<p>' + eventName + ' [' + api.getId(item) + '] [' + options.uid + ']</p>');
} else {
log.prepend('<p>' + eventName + ' [tree] [' + options.uid + ']</p>');
}
if (eventName == 'toggled') {
eyes++;
showEyes();
}
}
});
// do it ;-)
initTree(null, 'ui', true);
// a little debug info tool :)
function debug(item) {
var info = '';
info += 'getId: [' + treeApi.getId(item) + ']\n';
info += 'getLabel: "' + treeApi.getLabel(item) + '"\n';
info += 'level: ' + treeApi.level(item) + '\n';
info += 'getIndex: ' + treeApi.getIndex(item) + '\n';
info += 'isLeaf: ' + treeApi.isLeaf(item) + '\n';
info += 'isInode: ' + treeApi.isInode(item) + ' (open: ' + treeApi.isOpen(item) + ')\n';
info += 'wasLoad: ' + treeApi.wasLoad(item) + '\n';
info += 'hasParent: ' + treeApi.hasParent(item) + '\n';
info += 'parent: [' + treeApi.getId(treeApi.parent(item)) + ']\n';
info += 'path: [root] ';
treeApi.path(item).each(function() {
info += '[' + treeApi.getId($(this)) + '] ';
});
info += '\n';
info += 'hasSiblings: ' + treeApi.hasSiblings(item) + ' count: #' + treeApi.siblings(item).length + '\n';
info += 'hasPrev: ' + treeApi.hasPrev(item) + ' [' + treeApi.getId(treeApi.prev(item)) + ']\n';
info += 'hasNext: ' + treeApi.hasNext(item) + ' [' + treeApi.getId(treeApi.next(item)) + ']\n';
var children = treeApi.children(item);
info += 'hasChildren: ' + treeApi.hasChildren(item) + ' count: #' + children.length +
' inodes: #' + treeApi.inodes(children).length + ' (open: #' + treeApi.inodes(children, true).length +
' closed: #' + treeApi.inodes(children, false).length + ') leaves: #' + treeApi.leaves(children).length + '\n';
info += 'first [' + treeApi.getId(treeApi.first(item)) + '] isFirst: ' + treeApi.isFirst(item) + '\n';
info += 'last [' + treeApi.getId(treeApi.last(item)) + '] isLast: ' + treeApi.isLast(item) + '\n';
// the next are commented because of the low performance
//var allChildren = treeApi.children(null, true);
info += 'children: #' + children.length + /*' (total: #' + allChildren.length + ')' +*/ '\n';
/*info += 'visible: #' + treeApi.visible(children).length + ' in view: #' + treeApi.visible(children, true).length +
' (total: #' + treeApi.visible(allChildren).length + ' total in view: #' + treeApi.visible(allChildren, true).length + ')\n';*/
return info;
}
// keep the last element
var _g_tree = null;
// ensure info changes
window.setInterval(function() {
_g_tree = null;
}, 500);
// output some info
function getDebug(element) {
if (_g_tree == element) {
return;
}
_g_tree = element;
var item = treeApi.itemFrom(element);
if (!item.length) {
item = null;
}
$('#info').html(debug(item).replace(/\n/g, '<br>'));
}
// refresh on item 'mouseover'
theTree.on('mouseover', '.aciTreeLi', function(e) {
getDebug(e.target);
return false;
}).bind('mouseover', function(e) {
getDebug(e.target);
});
// get Tree init options
var options = theTree.aciTree('options');
// get string value from BOOL/numeric
function valueBoolNum(mixed) {
return (mixed === true) ? 'true' : ((mixed === false) ? 'false' : mixed);
}
// get BOOL/numeric value from string
function boolNumValue(string) {
return (string == 'true') ? true : ((string == 'false') ? false : parseInt(string));
}
$('#reloadJs').click(function() {
var script = $('script');
script.detach().each(function() {
var src = $(this).attr('src');
if (src) {
$('head').append('<' + 'script type="text/javascript" src="' + src + '"><' + '/script' + '>');
}
});
});
// init FORM based on options
$('[name=esize][value=' + (theTree.hasClass('aciTreeBig') ? 'big' : 'small') + ']').prop('checked', true);
$('[name=nodebtn][value=' + (theTree.hasClass('aciTreeArrow') ? 'arrow' : 'square') + ']').prop('checked', true);
$('[name=branches][value=' + (theTree.hasClass('aciTreeNoBranches') ? 0 : 1) + ']').prop('checked', true);
$('[name=animate][value=' + (options.show ? 1 : 0) + ']').prop('checked', true);
$('[name=expand][value=' + (options.expand ? 1 : 0) + ']').prop('checked', true);
$('[name=collapse][value=' + (options.collapse ? 1 : 0) + ']').prop('checked', true);
$('[name=empty][value=' + (options.empty ? 1 : 0) + ']').prop('checked', true);
$('[name=unique][value=' + (options.unique ? 1 : 0) + ']').prop('checked', true);
$('[name=selectable][value=' + (options.selectable ? 1 : 0) + ']').prop('checked', true);
$('[name=fullRow][value=' + (options.fullRow ? 1 : 0) + ']').prop('checked', true);
$('[name=textSelection][value=' + (options.textSelection ? 1 : 0) + ']').prop('checked', true);
$('[name=sortable][value=' + (options.sortable ? 1 : 0) + ']').prop('checked', true);
$('[name=multiSelectable][value=' + (options.multiSelectable ? 1 : 0) + ']').prop('checked', true);
$('[name=checkbox][value=' + (options.checkbox ? 1 : 0) + ']').prop('checked', true);
$('[name=radio][value=' + (options.radio ? 1 : 0) + ']').prop('checked', true);
$('[name=checkboxChain][value=' + valueBoolNum(options.checkboxChain) + ']').prop('checked', true);
$('[name=checkboxBreak][value=' + (options.checkboxBreak ? 1 : 0) + ']').prop('checked', true);
$('[name=checkboxClick][value=' + (options.checkboxClick ? 1 : 0) + ']').prop('checked', true);
$('[name=radioChain][value=' + (options.radioChain ? 1 : 0) + ']').prop('checked', true);
$('[name=radioBreak][value=' + (options.radioBreak ? 1 : 0) + ']').prop('checked', true);
$('[name=radioClick][value=' + (options.radioClick ? 1 : 0) + ']').prop('checked', true);
$('#setCheckbox').attr('disabled', !options.checkbox);
$('#setRadio').attr('disabled', !options.radio);
$('[name=direction][value=' + ((theTree.attr('dir') == 'rtl') ? 0 : 1) + ']').prop('checked', true);
$('[name=oddeven][value=' + (theTree.hasClass('aciTreeColors') ? 1 : 0) + ']').prop('checked', true);
$('[name=editable][value=' + (options.editable ? 1 : 0) + ']').prop('checked', true);
$('[name=cancel_ui][value=0]').prop('checked', true);
$('[name=cancel_user][value=0]').prop('checked', true);
// filter the tree
$('#filter').keyup(function() {
treeApi.filter(null, {
search: $(this).val()
});
});
// update options
$('[name=animate]').click(function() {
if ($(this).val() == 1) {
treeApi.option('show', {
props: {
'height': 'show'
},
duration: 'medium',
easing: 'linear'
});
treeApi.option('hide', {
props: {
'height': 'hide'
},
duration: 'medium',
easing: 'linear'
});
treeApi.option('view', {
duration: 'medium',
easing: 'linear'
});
} else {
treeApi.option('show', null);
treeApi.option('hide', null);
treeApi.option('view', null);
}
});
$('[name=esize]').click(function() {
theTree.toggleClass('aciTreeBig', $(this).val() == 'big');
});
$('[name=nodebtn]').click(function() {
theTree.toggleClass('aciTreeArrow', $(this).val() == 'arrow');
});
$('[name=branches]').click(function() {
theTree.toggleClass('aciTreeNoBranches', $(this).val() == 0);
});
$('[name=checkbox]').click(function() {
$('#setCheckbox').attr('disabled', $(this).val() != 1);
});
$('[name=radio]').click(function() {
$('#setRadio').attr('disabled', $(this).val() != 1);
});
$('[name=direction]').click(function() {
theTree.attr('dir', ($(this).val() == 1) ? 'ltr' : 'rtl');
});
$('[name=oddeven]').click(function() {
theTree.toggleClass('aciTreeColors', $(this).val() == 1);
});
$('[name=expand],[name=collapse],[name=empty],[name=unique],[name=selectable],[name=fullRow],[name=textSelection],[name=sortable],[name=checkbox],[name=radio],[name=checkboxBreak],[name=radioChain],[name=radioBreak],[name=editable],[name=checkboxClick],[name=radioClick],[name=multiSelectable]').click(function() {
var option = $(this).prop('name');
theTree.aciTree('option', option, $(this).val() == 1);
});
$('[name=checkboxChain]').click(function() {
var option = $(this).prop('name');
theTree.aciTree('option', option, boolNumValue($(this).val()));
$('[name=checkboxBreak]').prop('disabled', $(this).val() == 'false');
});
$('[name=radioChain]').click(function() {
$('[name=radioBreak]').prop('disabled', $(this).val() == '0');
});
$('[name=cancel_ui]').click(function() {
cancelUi = $(this).val() == 1;
});
$('[name=cancel_user]').click(function() {
cancelUser = $(this).val() == 1;
});
// FORM button functions
// update init options based on inputs
function updateOptions() {
$('[name=expand]:checked,[name=collapse]:checked,[name=empty]:checked,[name=unique]:checked,[name=selectable]:checked,[name=fullRow]:checked,[name=textSelection]:checked,[name=sortable]:checked,[name=checkbox]:checked,[name=radio]:checked,[name=checkboxBreak]:checked,[name=radioChain]:checked,[name=radioBreak]:checked,[name=editable]:checked,[name=checkboxClick]:checked,[name=radioClick]:checked,[name=multiSelectable]:checked').each(function() {
var option = $(this).prop('name');
$.fn.aciTree.defaults[option] = $(this).val() == 1;
});
$('[name=checkboxChain]:checked').each(function() {
var option = $(this).prop('name');
$.fn.aciTree.defaults[option] = boolNumValue($(this).val());
});
}
function warnInit(init) {
if (treeApi) {
if (treeApi.isLocked()) {
alert('Please wait until the treeview finishes the init/destroy !');
return true;
}
if (!init && !treeApi.wasInit()) {
alert('The treeview need to be init before continue !');
return true;
}
return false;
} else {
alert('Please wait until the treeview finishes the init !');
return true;
}
}
// check before we try to do something
$('[type=button]').not('#clear_log').click(function(e) {
var init = $(this).is('#init,#init_data,#init_huge');
if (warnInit(init)) {
// prevent API calls if not init
e.stopImmediatePropagation();
}
});
// check before we try to do something
$('select').change(function(e) {
if (warnInit()) {
$(this).val('');
// prevent API calls if not init
e.stopImmediatePropagation();
}
});
$('#destroy').click(function() {
theTree.aciTree('api').destroy({
uid: 'user-defined',
success: function() {
alert('Treeview control successfully destroyed !');
},
fail: function() {
alert('Failed to destroy the treeview control !');
}
});
});
$('#init').click(function() {
// update options
updateOptions();
initTree();
});
$('#init_data').click(function() {
// update options
updateOptions();
initTree('data');
});
$('#init_huge').click(function() {
// update options
updateOptions();
initTree('huge');
});
$('#clear_log,.clear_log').click(function() {
$('.log div').html('');
return false;
});
// keep the last selected
var _g_sel = null;
// selected state for the Tree
$(document).on('click', '#tree', function() {
theTree.find('.selected').removeClass('selected');
$(this).addClass('selected');
_g_sel = this;
});
// selected state for the Tree items
theTree.on('click', '.aciTreeItem', function(e) {
theTree.removeClass('selected').find('.selected').removeClass('selected');
$(this).addClass('selected');
_g_sel = this;
e.stopPropagation();
});
// few little helpers ->
// return TRUE if the treeview is selected
function checkIsTree() {
return _g_sel && (_g_sel == theTree[0]);
}
// return the selected item (if any)
function checkIsItem() {
if (_g_sel) {
var item = treeApi.itemFrom(_g_sel);
if (treeApi.isItem(item)) {
return item;
}
}
return null;
}
// test if the treeview or a item is selected, alert if not, return the item if selected
function requireSelection() {
var item = checkIsItem();
if (checkIsTree() || item) {
return item;
}
alert('Please select one item or the treeview itself (with a mouse click, will have a pink background after selection) !');
return null;
}
// test if a item is selected, alert if not, return the item if selected
function requireItem() {
var item = checkIsItem();
if (item) {
return item;
}
alert('Please select one item (with a mouse click, will have a pink background after selection) !');
return null;
}
// test if a inode item is selected, alert if not, return the item if selected
function requireInode() {
var item = checkIsItem();
if (item && treeApi.isInode(item)) {
return item;
}
alert('Please select one folder item (with a mouse click, will have a pink background after selection) !');
return null;
}
// test if a leaf item is selected, alert if not, return the item if selected
function requireLeaf() {
var item = checkIsItem();
if (item && treeApi.isLeaf(item)) {
return item;
}
alert('Please select one file item (with a mouse click, will have a pink background after selection) !');
return null;
}
// test if the treeview or the inode was loaded, alert if was loaded, return TRUE if was not loaded
function requestLoad() {
if (checkIsTree()) {
if (treeApi.wasLoad()) {
alert('The treeview was loaded already !');
} else {
return true;
}
} else {
var item = checkIsItem();
if (item && requireInode(item)) {
if (treeApi.wasLoad(item)) {
alert('The folder item was loaded already !');
} else {
return true;
}
} else {
requireSelection();
}
}
return false;
}
var leafIndex = 0;
// get new leaf item data
function newLeaf() {
var itemData = {
id: 'a_new_File_ID_' + leafIndex,
label: 'File name ' + leafIndex,
inode: false,
icon: 'file'
};
leafIndex++;
return itemData;
}
var inodeIndex = 0;
// get new inode item data
function newInode() {
var itemData = {
id: 'a_new_Folder_ID_' + inodeIndex,
label: 'Folder name ' + inodeIndex,
inode: null,
open: false,
icon: 'folder'
};
inodeIndex++;
return itemData;
}
// add one or more items (after or before a item)
function treeAddItem(item, itemData, skipLog) {
var before = $('[name=addMode]:checked').val() == 'before';
if (before) {
treeApi.before(item.first(), {
uid: (skipLog ? 'skip-log' : 'user-defined'),
success: function(item) {
alert('Item(s) successfully added before [' + this.getId(item) + '] !');
if (!this.isVisible(item)) {
this.setVisible(item);
}
},
fail: function(item) {
alert('Failed to add the item(s) before [' + this.getId(item) + '] !');
},
itemData: itemData
});
} else {
treeApi.after(item.last(), {
uid: (skipLog ? 'skip-log' : 'user-defined'),
success: function(item) {
alert('Item(s) successfully added after [' + this.getId(item) + '] !');
if (!this.isVisible(item)) {
this.setVisible(item);
}
},
fail: function(item) {
alert('Failed to add the item(s) after [' + this.getId(item) + '] !');
},
itemData: itemData
});
}
}
// <- few little helpers
// do something with the selected item ;-)
// set text fields value from the selected item
$('#item_id_btn,#move_btn,#swap1_btn,#swap2_btn').click(function() {
var item = requireItem();
if (item) {
$('input[name="' + $(this).attr('id').replace('_btn', '') + '"]').val(treeApi.getId(item));
}
});
// add a leaf to the treeview or to the selected inode
$('#addFile').click(function() {
if (checkIsTree()) {
// the treeview is selected, add a leaf on the first/last position
var children = treeApi.children();
if (children.length) {
// already has some items on ROOT
treeAddItem(children, newLeaf());
} else {
// no items on ROOT
treeApi.append(null, {
uid: 'user-defined',
success: function() {
alert('The file item was added on ROOT !');
},
fail: function() {
alert('Failed to add the file item on ROOT !');
},
itemData: newLeaf()
});
}
} else {
var item = requireSelection();
if (item) {
// a item is selected, add a leaf before/after it
treeAddItem(item, newLeaf());
}
}
});
// add a inode to the treeview or to the selected inode
$('#addFolder').click(function() {
if (checkIsTree()) {
// the treeview is selected, add a inode on the first/last position
var children = treeApi.children();
if (children.length) {
// already has some items on ROOT
treeAddItem(children, newInode());
} else {
// no items on ROOT
treeApi.append(null, {
uid: 'user-defined',
success: function() {
alert('The folder item was added on ROOT !');
},
fail: function() {
alert('Failed to add the folder item on ROOT !');
},
itemData: newInode()
});
}
} else {
var item = requireSelection();
if (item) {
// a item is selected, add a inode before/after it
treeAddItem(item, newInode());
}
}
});