diff options
author | Arnaud CHESNAY <arnaud.chesnay@etu.univ-nantes.fr> | 2017-09-27 09:06:27 +0200 |
---|---|---|
committer | Arnaud CHESNAY <arnaud.chesnay@etu.univ-nantes.fr> | 2017-09-27 09:06:27 +0200 |
commit | be836b55b4f8bc541b49c392d91954fb855529b8 (patch) | |
tree | 670312eebc189f1e737536c098f47c8c4befd940 /public/js | |
parent | first commit (diff) |
push website
Diffstat (limited to 'public/js')
-rw-r--r-- | public/js/script.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/public/js/script.js b/public/js/script.js new file mode 100644 index 0000000..bfa2899 --- /dev/null +++ b/public/js/script.js @@ -0,0 +1,35 @@ +$(document).ready(function() { + $.get('/data', function(data) { + $('#tree').append(addDirectory(data)); + + $('a').click(function(e) { + $('.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; +} |