diff --git a/static/js/cours.js b/static/js/cours.js index a28b4dd..a52fb94 100644 --- a/static/js/cours.js +++ b/static/js/cours.js @@ -8,16 +8,24 @@ const buildFileTree = (parent, data, location) => { const ul = document.createElement("ul"); data.forEach((item) => { const li = document.createElement("li"); - li.textContent = item.name; li.classList.add(item.is_dir ? "directory" : "file"); if (item.is_dir) { + // Directory + li.textContent = item.name; li.classList.add("collapsed"); li.addEventListener("click", function (e) { if (e.target === li) { li.classList.toggle("collapsed"); } }); + } else { + // File + const url = window.location.href.split("?")[0]; + const a = document.createElement("a"); + a.text = item.name; + a.href = `${url}?q=${location}${item.name}`; + li.appendChild(a); } ul.appendChild(li);