blob: cbc422140fe9b0e12c5c3f29078c2595c74bb7b5 (
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
42
43
44
45
46
|
$(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);
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
});
});
$('.directory').find('ul').hide();
$('.directory').click(function(e) {
e.stopPropagation();
$(this).children('ul').slideToggle();
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
});
});
});
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.tabIndex = 0
li.appendChild(addDirectory(item));
li.classList.add("directory");
}
ul.appendChild(li);
});
return ul;
}
|