add search bar
This commit is contained in:
parent
ec7319b5a8
commit
6f974cbf7b
3 changed files with 43 additions and 4 deletions
|
@ -63,6 +63,10 @@ button {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type="text"] {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 640px) {
|
@media only screen and (max-width: 640px) {
|
||||||
aside {
|
aside {
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -82,7 +86,7 @@ button {
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
width: 80vw;
|
width: 85vw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,35 @@ const deepestNodeOpened = (path, options) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const searchFiles = (query, parent, currentFile) => {
|
||||||
|
const children = parent.querySelectorAll("li");
|
||||||
|
|
||||||
|
if (query === "") {
|
||||||
|
children.forEach((item) => {
|
||||||
|
item.style.display = "";
|
||||||
|
if (
|
||||||
|
item.classList.contains("directory") &&
|
||||||
|
!item.classList.contains("collapsed")
|
||||||
|
) {
|
||||||
|
item.classList.add("collapsed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
uncollapse(currentFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
children.forEach((item) => {
|
||||||
|
if (item.innerText.toLowerCase().includes(query.toLowerCase())) {
|
||||||
|
item.style.display = "";
|
||||||
|
uncollapse(item);
|
||||||
|
console.log(query, item.innerText);
|
||||||
|
} else {
|
||||||
|
item.style.display = "none";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
// Build the filetree
|
// Build the filetree
|
||||||
const fileTreeElement = document.getElementsByTagName("aside")[0];
|
const fileTreeElement = document.getElementsByTagName("aside")[0];
|
||||||
|
@ -97,21 +126,26 @@ window.addEventListener("load", () => {
|
||||||
if (infoURL.length > 1) {
|
if (infoURL.length > 1) {
|
||||||
const fullpath = infoURL[1].substring(2);
|
const fullpath = infoURL[1].substring(2);
|
||||||
const path = fullpath.substring(0, fullpath.lastIndexOf("/"));
|
const path = fullpath.substring(0, fullpath.lastIndexOf("/"));
|
||||||
const last_openeded = deepestNodeOpened(
|
const currently_open = deepestNodeOpened(
|
||||||
path.split("/"),
|
path.split("/"),
|
||||||
fileTreeElement.querySelector("ul").childNodes
|
fileTreeElement.querySelector("ul").childNodes
|
||||||
);
|
);
|
||||||
|
uncollapse(currently_open);
|
||||||
|
|
||||||
// Bold opened file
|
// Bold opened file
|
||||||
const opened_file = fullpath.split("/").at(-1);
|
const opened_file = fullpath.split("/").at(-1);
|
||||||
last_openeded.querySelector("ul").childNodes.forEach((el) => {
|
currently_open.querySelector("ul").childNodes.forEach((el) => {
|
||||||
if (el.innerText === opened_file) {
|
if (el.innerText === opened_file) {
|
||||||
el.style.fontWeight = "bold";
|
el.style.fontWeight = "bold";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uncollapse(last_openeded);
|
// Search bar hook
|
||||||
|
document.getElementById("searchBar").addEventListener("input", (e) => {
|
||||||
|
searchFiles(e.target.value, fileTreeElement, currently_open);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Responsive menu
|
// Responsive menu
|
||||||
let menuOpen = false;
|
let menuOpen = false;
|
||||||
const button = document.getElementsByTagName("button")[0];
|
const button = document.getElementsByTagName("button")[0];
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
<button type="button">Ouvrir le menu</button>
|
<button type="button">Ouvrir le menu</button>
|
||||||
<aside>
|
<aside>
|
||||||
|
<input type="text" id="searchBar" placeholder="Recherche..." autofocus />
|
||||||
<span data-json="{{filetree}} "></span>
|
<span data-json="{{filetree}} "></span>
|
||||||
</aside>
|
</aside>
|
||||||
<main>
|
<main>
|
||||||
|
|
Loading…
Reference in a new issue