blob: 432fcf543f938f770dab1d1c3769a8ce9bd6f69e (
plain)
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
|
$(document).ready(function() {
$.get('/data', function(data) {
$('#tree').append(addDirectory(data));
$('a').click(function(e) {
e.preventDefault();
e.stopPropagation();
$.get(this.href, function(data) {
$('#md').html(data);
});
});
$('.directory').find('ul').hide();
$('.directory').click(function(e) {
e.stopPropagation();
$(this).children('ul').slideToggle();
});
});
});
function addDirectory(data) {
var ul = document.createElement('ul');
data.children.forEach(function(item) {
var li = document.createElement('li');
var text = document.createTextNode(item.name);
if (item.type === "file") {
var a = document.createElement('a');
a.appendChild(text);
a.href = item.path;
li.appendChild(a);
li.classList.add("file");
} else {
li.appendChild(text);
li.appendChild(addDirectory(item));
li.classList.add("directory");
}
ul.appendChild(li);
});
return ul;
}
|