This commit is contained in:
parent
23079f4418
commit
fcc146842c
1 changed files with 9 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue