mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-12-31 23:22:23 +00:00
docs: add search widget to options page
This commit is contained in:
parent
fca55e1db1
commit
a9c6ab86f6
3 changed files with 60 additions and 1 deletions
|
@ -62,7 +62,8 @@ in
|
||||||
# Copy anchor scripts to the script directory in document root.
|
# Copy anchor scripts to the script directory in document root.
|
||||||
cp -vt "$dest"/script \
|
cp -vt "$dest"/script \
|
||||||
${./static/script}/anchor-min.js \
|
${./static/script}/anchor-min.js \
|
||||||
${./static/script}/anchor-use.js
|
${./static/script}/anchor-use.js \
|
||||||
|
${./static/script}/search.js
|
||||||
|
|
||||||
substituteInPlace ./options.md \
|
substituteInPlace ./options.md \
|
||||||
--subst-var-by OPTIONS_JSON ./config-options.json
|
--subst-var-by OPTIONS_JSON ./config-options.json
|
||||||
|
@ -100,6 +101,7 @@ in
|
||||||
--script highlightjs/loader.js \
|
--script highlightjs/loader.js \
|
||||||
--script script/anchor-use.js \
|
--script script/anchor-use.js \
|
||||||
--script script/anchor-min.js \
|
--script script/anchor-min.js \
|
||||||
|
--script script/search.js \
|
||||||
--toc-depth 2 \
|
--toc-depth 2 \
|
||||||
--section-toc-depth 1 \
|
--section-toc-depth 1 \
|
||||||
manual.md \
|
manual.md \
|
||||||
|
|
39
docs/static/script/search.js
vendored
Normal file
39
docs/static/script/search.js
vendored
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
// The search widget should only be visible if we're in the options page. Else, we
|
||||||
|
// want it hidden.
|
||||||
|
if (window.location.pathname.endsWith("options.html")) {
|
||||||
|
const searchBar = document.createElement("div");
|
||||||
|
searchBar.id = "search-bar";
|
||||||
|
searchBar.innerHTML = `
|
||||||
|
<input type="text" id="search-input" placeholder="Search options by ID..." />
|
||||||
|
<div id="search-results"></div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.body.prepend(searchBar);
|
||||||
|
|
||||||
|
const dtElements = document.querySelectorAll("dt");
|
||||||
|
const ddElements = document.querySelectorAll("dd");
|
||||||
|
|
||||||
|
if (dtElements.length === 0 || ddElements.length === 0) {
|
||||||
|
console.warn(
|
||||||
|
"No <dt> or <dd> elements found. Ensure your HTML contains the correct structure.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle input and filter visible options
|
||||||
|
document
|
||||||
|
.getElementById("search-input")
|
||||||
|
.addEventListener("input", (event) => {
|
||||||
|
const query = event.target.value.toLowerCase();
|
||||||
|
dtElements.forEach((dt, index) => {
|
||||||
|
const optionId =
|
||||||
|
dt.querySelector("a")?.id.toLowerCase() || "";
|
||||||
|
const isMatch = optionId.includes(query);
|
||||||
|
|
||||||
|
// toggle visibility based on the query match
|
||||||
|
dt.classList.toggle("hidden", !isMatch);
|
||||||
|
ddElements[index]?.classList.toggle("hidden", !isMatch);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
18
docs/static/style.scss
vendored
18
docs/static/style.scss
vendored
|
@ -233,6 +233,24 @@ li {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#search-bar {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
background: white;
|
||||||
|
padding: 10px;
|
||||||
|
border-bottom: 1px solid #ccc;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
#search-input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
div.titlepage {
|
div.titlepage {
|
||||||
margin: 40px 0;
|
margin: 40px 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue