Basic cours support #44

Merged
Anri merged 67 commits from cours into main 2024-04-01 18:11:49 +02:00
Showing only changes of commit fcc146842c - Show all commits

View file

@ -8,16 +8,24 @@ const buildFileTree = (parent, data, location) => {
const ul = document.createElement("ul"); const ul = document.createElement("ul");
data.forEach((item) => { data.forEach((item) => {
const li = document.createElement("li"); const li = document.createElement("li");
li.textContent = item.name;
li.classList.add(item.is_dir ? "directory" : "file"); li.classList.add(item.is_dir ? "directory" : "file");
if (item.is_dir) { if (item.is_dir) {
// Directory
li.textContent = item.name;
li.classList.add("collapsed"); li.classList.add("collapsed");
li.addEventListener("click", function (e) { li.addEventListener("click", function (e) {
if (e.target === li) { if (e.target === li) {
li.classList.toggle("collapsed"); 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); ul.appendChild(li);