From be836b55b4f8bc541b49c392d91954fb855529b8 Mon Sep 17 00:00:00 2001 From: Arnaud CHESNAY Date: Wed, 27 Sep 2017 09:06:27 +0200 Subject: push website --- public/js/script.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 public/js/script.js (limited to 'public/js/script.js') 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; +} -- cgit v1.2.3-54-g00ecf