forked from mbraak/jqTree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.jquery.coffee
1540 lines (1188 loc) · 41.1 KB
/
tree.jquery.coffee
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
###
Copyright 2012 Marco Braak
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
###
@Tree = {}
$ = @jQuery
# Standard javascript indexOf. Implemented here because not all browsers support it.
indexOf = (array, item) ->
if array.indexOf
# The browser supports indexOf
return array.indexOf(item)
else
# Do our own indexOf
for value, i in array
if value == item
return i
return -1
@Tree.indexOf = indexOf
# JSON.stringify function; copied from json2
if not (@JSON? and @JSON.stringify? and typeof @JSON.stringify == 'function')
json_escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
json_meta = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
}
json_quote = (string) ->
json_escapable.lastIndex = 0
if json_escapable.test(string)
return '"' + string.replace(json_escapable, (a) ->
c = json_meta[a]
return (
if typeof c is 'string' then c
else '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4)
)
) + '"'
else
return '"' + string + '"'
json_str = (key, holder) ->
value = holder[key]
switch typeof value
when 'string'
return json_quote(value)
when 'number'
return if isFinite(value) then String(value) else 'null'
when 'boolean', 'null'
return String(value)
when 'object'
if not value
return 'null'
partial = []
if Object::toString.apply(value) is '[object Array]'
for v, i in value
partial[i] = json_str(i, value) or 'null'
return (
if partial.length is 0 then '[]'
else '[' + partial.join(',') + ']'
)
for k of value
if Object::hasOwnProperty.call(value, k)
v = json_str(k, value)
if v
partial.push(json_quote(k) + ':' + v)
return (
if partial.length is 0 then '{}'
else '{' + partial.join(',') + '}'
)
if not @JSON?
@JSON = {}
@JSON.stringify = (value) ->
return json_str(
'',
{'': value}
)
# Escape a string for HTML interpolation; copied from underscore js
html_escape = (string) ->
return (''+string)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/\//g,'/')
Position =
getName: (position) ->
return Position.strings[position - 1]
nameToIndex: (name) ->
for i in [1..Position.strings.length]
if Position.strings[i - 1] == name
return i
return 0
Position.BEFORE = 1
Position.AFTER = 2
Position.INSIDE = 3
Position.NONE = 4
Position.strings = ['before', 'after', 'inside', 'none']
@Tree.Position = Position
class Node
constructor: (o) ->
@setData(o)
@children = []
@parent = null
setData: (o) ->
if typeof o != 'object'
@name = o
else
for key, value of o
if key == 'label'
# todo: node property is 'name', but we use 'label' here
@name = value
else
@[key] = value
# Init Node from data without making it the root of the tree
initFromData: (data) ->
addNode = (node_data) =>
@setData(node_data)
if node_data.children
addChildren(node_data.children)
addChildren = (children_data) =>
for child in children_data
node = new Node('')
node.initFromData(child)
@addChild(node)
return null
addNode(data)
return null
###
Create tree from data.
Structure of data is:
[
{
label: 'node1',
children: [
{ label: 'child1' },
{ label: 'child2' }
]
},
{
label: 'node2'
}
]
###
loadFromData: (data) ->
@children = []
for o in data
node = new Node(o)
@addChild(node)
if typeof o == 'object' and o.children
node.loadFromData(o.children)
return null
###
Add child.
tree.addChild(
new Node('child1')
);
###
addChild: (node) ->
@children.push(node)
node._setParent(this)
###
Add child at position. Index starts at 0.
tree.addChildAtPosition(
new Node('abc'),
1
);
###
addChildAtPosition: (node, index) ->
@children.splice(index, 0, node)
node._setParent(this)
_setParent: (parent) ->
@parent = parent
@tree = parent.tree
@tree.addNodeToIndex(this)
###
Remove child.
tree.removeChild(tree.children[0]);
###
removeChild: (node) ->
@children.splice(
@getChildIndex(node),
1
)
@tree.removeNodeFromIndex(node)
###
Get child index.
var index = getChildIndex(node);
###
getChildIndex: (node) ->
return $.inArray(node, @children)
###
Does the tree have children?
if (tree.hasChildren()) {
//
}
###
hasChildren: ->
return @children.length != 0
isFolder: ->
return @hasChildren() or @load_on_demand
###
Iterate over all the nodes in the tree.
Calls callback with (node, level).
The callback must return true to continue the iteration on current node.
tree.iterate(
function(node, level) {
console.log(node.name);
// stop iteration after level 2
return (level <= 2);
}
);
###
iterate: (callback) ->
_iterate = (node, level) =>
if node.children
for child in node.children
result = callback(child, level)
if @hasChildren() and result
_iterate(child, level + 1)
return null
_iterate(this, 0)
return null
###
Move node relative to another node.
Argument position: Position.BEFORE, Position.AFTER or Position.Inside
// move node1 after node2
tree.moveNode(node1, node2, Position.AFTER);
###
moveNode: (moved_node, target_node, position) ->
if moved_node.isParentOf(target_node)
# Node is parent of target node. This is an illegal move
return
moved_node.parent.removeChild(moved_node)
if position == Position.AFTER
target_node.parent.addChildAtPosition(
moved_node,
target_node.parent.getChildIndex(target_node) + 1
)
else if position == Position.BEFORE
target_node.parent.addChildAtPosition(
moved_node,
target_node.parent.getChildIndex(target_node)
)
else if position == Position.INSIDE
# move inside as first child
target_node.addChildAtPosition(moved_node, 0)
###
Get the tree as data.
###
getData: ->
getDataFromNodes = (nodes) =>
data = []
for node in nodes
tmp_node = {}
for k, v of node
if (
k not in ['parent', 'children', 'element', 'tree'] and
Object.prototype.hasOwnProperty.call(node, k)
)
tmp_node[k] = v
if node.hasChildren()
tmp_node.children = getDataFromNodes(node.children)
data.push(tmp_node)
return data
return getDataFromNodes(@children)
getNodeByName: (name) ->
result = null
@iterate(
(node) ->
if node.name == name
result = node
return false
else
return true
)
return result
addAfter: (node_info) ->
if not @parent
return null
else
node = new Node(node_info)
child_index = @parent.getChildIndex(this)
@parent.addChildAtPosition(node, child_index + 1)
return node
addBefore: (node_info) ->
if not @parent
return null
else
node = new Node(node_info)
child_index = @parent.getChildIndex(this)
@parent.addChildAtPosition(node, child_index)
addParent: (node_info) ->
if not @parent
return null
else
new_parent = new Node(node_info)
new_parent._setParent(@tree)
original_parent = @parent
for child in original_parent.children
new_parent.addChild(child)
original_parent.children = []
original_parent.addChild(new_parent)
return new_parent
remove: ->
if @parent
@parent.removeChild(this)
@parent = null
append: (node_info) ->
node = new Node(node_info)
@addChild(node)
return node
prepend: (node_info) ->
node = new Node(node_info)
@addChildAtPosition(node, 0)
return node
isParentOf: (node) ->
parent = node.parent
while parent
if parent == this
return true
parent = parent.parent
return false
class Tree extends Node
constructor: (o) ->
super(o, null, true)
@id_mapping = {}
@tree = this
getNodeById: (node_id) ->
return @id_mapping[node_id]
addNodeToIndex: (node) ->
if node.id
@id_mapping[node.id] = node
removeNodeFromIndex: (node) ->
if node.id
delete @id_mapping[node.id]
@Tree.Tree = Tree
TRIANGLE_RIGHT = '►' # ► BLACK RIGHT-POINTING POINTER http://www.fileformat.info/info/unicode/char/25ba/index.htm
TRIANGLE_DOWN = '▼' # ▼ BLACK DOWN-POINTING TRIANGLE http://www.fileformat.info/info/unicode/char/25bc/index.htm
class JqTreeWidget extends MouseWidget
defaults:
autoOpen: false # true / false / int (open n levels starting at 0)
saveState: false # true / false / string (cookie name)
dragAndDrop: false
selectable: false
onCanSelectNode: null
onSetStateFromStorage: null
onGetStateFromStorage: null
onCreateLi: null
onIsMoveHandle: null
onCanMove: null # Can this node be moved? function(node)
onCanMoveTo: null # Can this node be moved to this position? function(moved_node, target_node, position)
autoEscape: true
dataUrl: null
toggle: (node) ->
if node.is_open
@closeNode(node)
else
@openNode(node)
getTree: ->
return @tree
selectNode: (node, must_open_parents) ->
@select_node_handler.selectNode(node, must_open_parents)
getSelectedNode: ->
return @selected_node or false
toJson: ->
return JSON.stringify(
@tree.getData()
)
loadData: (data_or_url, parent_node, on_finished) ->
if typeof data_or_url == 'string'
data_url = data_or_url
@_loadDataFromServer(data_url, parent_node, on_finished)
else
data = data_or_url
@_loadData(data, parent_node)
if on_finished
on_finished()
_loadData: (data, parent_node) ->
@_triggerEvent('tree.load_data', tree_data: data)
if not parent_node
@_initTree(data)
else
subtree = new Node('')
subtree._setParent(parent_node.tree)
subtree.loadFromData(data)
for child in subtree.children
parent_node.addChild(child)
@_refreshElements(parent_node.parent)
if @is_dragging
@dnd_handler.refreshHitAreas()
_loadDataFromServer: (data_url, parent_node, on_finished) ->
if not data_url
return
if parent_node
folder_element = new FolderElement(parent_node, this)
$li = folder_element.getLi()
$li.addClass('jqtree-loading')
else
$li = null
$.ajax(
url: data_url
cache: false
success: (response) =>
if $.isArray(response) or typeof response == 'object'
data = response
else
data = $.parseJSON(response)
if $li
$li.removeClass('loading')
@_loadData(data, parent_node)
if on_finished
on_finished()
)
getNodeById: (node_id) ->
return @tree.getNodeById(node_id)
getNodeByName: (name) ->
return @tree.getNodeByName(name)
openNode: (node, skip_slide) ->
@_openNode(node, skip_slide)
_openNode: (node, skip_slide, on_finished) ->
if node.isFolder()
if node.load_on_demand
@_loadFolderOnDemand(node, skip_slide, on_finished)
else
folder_element = new FolderElement(node, this)
folder_element.open(on_finished, skip_slide)
@_saveState()
_loadFolderOnDemand: (node, skip_slide, on_finished) ->
node.load_on_demand = false
@loadData(
@_getDataUrl(node),
node,
=>
@_openNode(node, skip_slide, on_finished)
)
closeNode: (node, skip_slide) ->
if node.isFolder()
new FolderElement(node, this).close(skip_slide)
@_saveState()
isDragging: ->
return @is_dragging
refreshHitAreas: ->
@dnd_handler.refreshHitAreas()
addNodeAfter: (new_node_info, existing_node) ->
new_node = existing_node.addAfter(new_node_info)
@_refreshElements(existing_node.parent)
return new_node
addNodeBefore: (new_node_info, existing_node) ->
new_node = existing_node.addBefore(new_node_info)
@_refreshElements(existing_node.parent)
return new_node
addParentNode: (new_node_info, existing_node) ->
new_node = existing_node.addParent(new_node_info)
@_refreshElements(new_node.parent)
return new_node
removeNode: (node) ->
parent = node.parent
if parent
node.remove()
@_refreshElements(parent.parent)
appendNode: (new_node_info, parent_node) ->
if not parent_node
parent_node = @tree
# Is the parent already a root node?
is_already_root_node = parent_node.isFolder()
node = parent_node.append(new_node_info)
if is_already_root_node
# Refresh the parent
@_refreshElements(parent_node)
else
# Refresh the parent of the parent. This must be done so the parent gets a toggler button
@_refreshElements(parent_node.parent)
return node
prependNode: (new_node_info, parent_node) ->
if not parent_node
parent_node = @tree
node = parent_node.prepend(new_node_info)
@_refreshElements(parent_node)
return node
updateNode: (node, data) ->
node.setData(data)
@_refreshElements(node.parent)
@select_node_handler.selectCurrentNode()
moveNode: (node, target_node, position) ->
position_index = Position.nameToIndex(position)
@tree.moveNode(node, target_node, position_index)
@_refreshElements()
getStateFromStorage: ->
return @save_state_handler.getStateFromStorage()
_init: ->
super()
@element = @$el
@selected_node = null
@mouse_delay = 300
@save_state_handler = new SaveStateHandler(this)
@select_node_handler = new SelectNodeHandler(this)
@dnd_handler = new DragAndDropHandler(this)
@_initData()
@element.click($.proxy(@_click, this))
@element.bind('contextmenu', $.proxy(@_contextmenu, this))
_deinit: ->
@element.empty()
@element.unbind()
@tree = null
super()
_initData: ->
if @options.data
@loadData(@options.data)
else
@loadData(@_getDataUrl())
_getDataUrl: (node) ->
data_url = @options.dataUrl or @element.data('url')
if $.isFunction(data_url)
return data_url(node)
else
if node
data_url += "?node=#{ node.id }"
return data_url
_initTree: (data) ->
@tree = new Tree()
@tree.loadFromData(data)
@_openNodes()
@_refreshElements()
@select_node_handler.selectCurrentNode()
@_triggerEvent('tree.init')
_openNodes: ->
if @options.saveState
if @save_state_handler.restoreState()
return
if @options.autoOpen is false
return
else if @options.autoOpen is true
max_level = -1
else
max_level = parseInt(@options.autoOpen)
@tree.iterate((node, level) ->
node.is_open = true
return (level != max_level)
)
_refreshElements: (from_node=null) ->
escapeIfNecessary = (value) =>
if @options.autoEscape
return html_escape(value)
else
return value
createUl = (is_root_node) =>
if is_root_node
class_string = ' class="jqtree-tree"'
else
class_string = ''
return $("<ul#{ class_string }></ul>")
createLi = (node) =>
if node.isFolder()
$li = createFolderLi(node)
else
$li = createNodeLi(node)
if @options.onCreateLi
@options.onCreateLi(node, $li)
return $li
createNodeLi = (node) =>
escaped_name = escapeIfNecessary(node.name)
return $("<li><div><span class=\"jqtree-title\">#{ escaped_name }</span></div></li>")
createFolderLi = (node) =>
getButtonClasses = ->
classes = ['jqtree-toggler']
if not node.is_open
classes.push('jqtree-closed')
return classes.join(' ')
getFolderClasses = ->
classes = ['jqtree-folder']
if not node.is_open
classes.push('jqtree-closed')
return classes.join(' ')
button_classes = getButtonClasses()
folder_classes = getFolderClasses()
escaped_name = escapeIfNecessary(node.name)
if node.is_open
button_char = TRIANGLE_DOWN
else
button_char = TRIANGLE_RIGHT
return $(
"<li class=\"#{ folder_classes }\"><div><a class=\"#{ button_classes }\">#{ button_char }</a><span class=\"jqtree-title\">#{ escaped_name }</span></div></li>"
)
doCreateDomElements = ($element, children, is_root_node, is_open) ->
$ul = createUl(is_root_node)
$element.append($ul)
for child in children
$li = createLi(child)
$ul.append($li)
child.element = $li[0]
$li.data('node', child)
if child.hasChildren()
doCreateDomElements($li, child.children, false, child.is_open)
return null
if from_node and from_node.parent
is_root_node = false
node_element = @_getNodeElementForNode(from_node)
node_element.getUl().remove()
$element = node_element.$element
else
from_node = @tree
$element = @element
$element.empty()
is_root_node = true
doCreateDomElements($element, from_node.children, is_root_node, is_root_node)
@_triggerEvent('tree.refresh')
_click: (e) ->
if e.ctrlKey
return
$target = $(e.target)
if $target.is('.jqtree-toggler')
node = @_getNode($target)
if node
@toggle(node)
e.preventDefault()
e.stopPropagation()
else if $target.is('div') or $target.is('span')
node = @_getNode($target)
if node
@_triggerEvent('tree.click', node: node)
@selectNode(node)
_getNode: ($element) ->
$li = $element.closest('li')
if $li.length == 0
return null
else
return $li.data('node')
_getNodeElementForNode: (node) ->
if node.isFolder()
return new FolderElement(node, this)
else
return new NodeElement(node, this)
_getNodeElement: ($element) ->
node = @_getNode($element)
if node
return @_getNodeElementForNode(node)
else
return null
_contextmenu: (e) ->
$div = $(e.target).closest('ul.jqtree-tree div')
if $div.length
node = @_getNode($div)
if node
e.preventDefault()
e.stopPropagation()
@_triggerEvent(
'tree.contextmenu',
node: node
click_event: e
)
return false
_saveState: ->
if @options.saveState
@save_state_handler.saveState()
_mouseCapture: (event) ->
if @options.dragAndDrop
return @dnd_handler.mouseCapture(event)
else
return false
_mouseStart: (event) ->
if @options.dragAndDrop
return @dnd_handler.mouseStart(event)
else
return false
_mouseDrag: (event) ->
if @options.dragAndDrop
return @dnd_handler.mouseDrag(event)
else
return false
_mouseStop: ->
if @options.dragAndDrop
return @dnd_handler.mouseStop()
else
return false
_triggerEvent: (event_name, values) ->
event = $.Event(event_name)
$.extend(event, values)
@element.trigger(event)
return event
testGenerateHitAreas: (moving_node) ->
@dnd_handler.current_item = @_getNodeElementForNode(moving_node)
@dnd_handler.generateHitAreas()
return @dnd_handler.hit_areas
SimpleWidget.register(JqTreeWidget, 'tree')
class GhostDropHint
constructor: (node, $element, position) ->
@$element = $element
@node = node
@$ghost = $('<li class="jqtree-ghost"><span class="jqtree-circle"></span><span class="jqtree-line"></span></li>')
if position == Position.AFTER
@moveAfter()
else if position == Position.BEFORE
@moveBefore()
else if position == Position.INSIDE
if node.isFolder() and node.is_open
@moveInsideOpenFolder()
else
@moveInside()
remove: ->
@$ghost.remove()
moveAfter: ->
@$element.after(@$ghost)
moveBefore: ->
@$element.before(@$ghost)
moveInsideOpenFolder: ->
$(@node.children[0].element).before(@$ghost)
moveInside: ->
@$element.after(@$ghost)
@$ghost.addClass('jqtree-inside')
class BorderDropHint
constructor: ($element) ->
$div = $element.children('div')
width = $element.width() - 4
@$hint = $('<span class="jqtree-border"></span>')
$div.append(@$hint)
@$hint.css({
width: width,
height: $div.height() - 4
})
remove: ->
@$hint.remove()
class NodeElement
constructor: (node, tree_widget) ->
@init(node, tree_widget)
init: (node, tree_widget) ->
@node = node
@tree_widget = tree_widget
@$element = $(node.element)
getUl: ->
return @$element.children('ul:first')
getSpan: ->
return @$element.children('div').find('span.jqtree-title')
getLi: ->
return @$element
addDropHint: (position) ->
if position == Position.INSIDE
return new BorderDropHint(@$element)
else
return new GhostDropHint(@node, @$element, position)
select: ->
@getLi().addClass('jqtree-selected')
deselect: ->
@getLi().removeClass('jqtree-selected')
class FolderElement extends NodeElement
open: (on_finished, skip_slide) ->
if not @node.is_open
@node.is_open = true
$button = @getButton()
$button.removeClass('jqtree-closed')
$button.html(TRIANGLE_DOWN)
doOpen = =>
@getLi().removeClass('jqtree-closed')
if on_finished
on_finished()
@tree_widget._triggerEvent('tree.open', node: @node)