aboutsummaryrefslogtreecommitdiff
path: root/public/js/script.js
blob: a7026faeca818f006aba9336df59289cb24e1783 (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
$(document).ready(function() {
    $.get('/data', function(data) {
        $('#tree').append(addDirectory(data));

        $('a').click(function(e) {
            $('#md').empty();
            $('.spinner').show();
            e.preventDefault();
            $.get(this.href, function(data) {
                $('.spinner').hide();
                $('#md').html(data);
            });
        });
    });
    $('.spinner').hide();
});

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);
        } else {
            li.appendChild(text);
            li.appendChild(addDirectory(item));
        }
        ul.appendChild(li);
    });
    return ul;
}