diff options
Diffstat (limited to 'public/js/script.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; +} |