This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
forked from felipelerena/FlightDeck
/
API.Tree.js
101 lines (74 loc) · 2.52 KB
/
API.Tree.js
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
API.Page = new Class({
Implements: Options,
options: {
filename: '',
path: ''
},
initialize: function(options) {
this.setOptions(options);
if (!this.options.path) this.options.path = this.options.filename;
},
getID: function() {
return 'Page-' + this.options.filename.replace(/\//g, '-');
}
});
FlightDeck = Class.refactor(FlightDeck, {
options: {
file_selected_class: 'UI_File_Selected',
file_listing_class: 'tree',
file_normal_class: 'UI_File_Normal'
},
initialize: function(options) {
this.previous(options);
var actions = { add: false, edit: false, remove: false },
that = this;
API.Tree = new FileTree('PackTree', {
checkDrag: Function.from(false),
editable: false,
actions: actions
});
API.Tree.collapse = new FileTree.Collapse('PackTree', {});
var top_branch = API.Tree.addBranch({
'rel': 'directory',
'title': 'Docs',
'id': 'lib_branch',
'class': 'top_branch nodrag'
}, null, { actions: actions, collapsed: false });
API.Tree.collapse.prepare();
doc_list.forEach(function(page) {
var p = API.pages[page.filename] = new API.Page(page);
var el = API.Tree.addPath(p, Object.merge({
target: top_branch
}, actions));
API.Tree.collapse.prepare();
el.store('page', p);
if (p.options.selected) {
this.setSelectedFile(el);
}
}, this);
$('PackTree').addEvent('click:relay(li:not(top_branch) > .holder > .label)', function(e, label) {
var page = label.getParent('li').retrieve('page');
if(page) {
that.setSelectedFile(label.getParent('li'));
window.location.href = page.options.get_url;
}
});
},
setSelectedFile: function(el) {
var options = this.options;
$$('.'+options.file_listing_class+' li')
.removeClass(options.file_selected_class)
.addClass(options.file_normal_class);
el.removeClass(options.file_normal_class)
.addClass(options.file_selected_class);
//also be sure to expand all parent folders
var tree = API.Tree;
node = el;
if (node.getElement('li')) {
tree.collapse.expand(node);
}
while (node = node.getParent('li')) {
tree.collapse.expand(node);
}
}
});