Resolve various script warnings
This commit is contained in:
parent
f7da277120
commit
20c0227cc2
1 changed files with 18 additions and 17 deletions
35
script.js
35
script.js
|
|
@ -1,3 +1,5 @@
|
|||
// @ts-nocheck
|
||||
|
||||
const cleanTerm = (text) => text.replace(/\s+/g, " ").replace(/\.$/, "").trim();
|
||||
|
||||
const slugify = (text) =>
|
||||
|
|
@ -38,7 +40,7 @@ termEntries.forEach(([term, id]) => {
|
|||
link.textContent = term;
|
||||
const item = document.createElement("li");
|
||||
item.appendChild(link);
|
||||
tocList.appendChild(item);
|
||||
tocList?.appendChild(item);
|
||||
});
|
||||
|
||||
Array.from(firstByLetter.entries())
|
||||
|
|
@ -47,13 +49,13 @@ Array.from(firstByLetter.entries())
|
|||
const link = document.createElement("a");
|
||||
link.href = `#${id}`;
|
||||
link.textContent = letter;
|
||||
tocLetters.appendChild(link);
|
||||
tocLetters?.appendChild(link);
|
||||
});
|
||||
|
||||
const searchInput = document.getElementById("toc-search");
|
||||
searchInput.addEventListener("input", (event) => {
|
||||
searchInput?.addEventListener("input", (event) => {
|
||||
const query = event.target.value.trim().toLowerCase();
|
||||
Array.from(tocList.querySelectorAll("li")).forEach((item) => {
|
||||
Array.from(tocList?.querySelectorAll("li") ?? []).forEach((item) => {
|
||||
const text = item.textContent.toLowerCase();
|
||||
item.style.display = text.includes(query) ? "" : "none";
|
||||
});
|
||||
|
|
@ -252,10 +254,9 @@ const linkifyTextNode = (node) => {
|
|||
node.parentNode.replaceChild(fragment, node);
|
||||
};
|
||||
|
||||
const walker = document.createTreeWalker(
|
||||
document.getElementById("content"),
|
||||
NodeFilter.SHOW_TEXT,
|
||||
{
|
||||
const contentEl = document.getElementById("content");
|
||||
if (contentEl) {
|
||||
const walker = document.createTreeWalker(contentEl, NodeFilter.SHOW_TEXT, {
|
||||
acceptNode: (node) => {
|
||||
const parent = node.parentElement;
|
||||
if (!parent) {
|
||||
|
|
@ -269,16 +270,16 @@ const walker = document.createTreeWalker(
|
|||
}
|
||||
return NodeFilter.FILTER_ACCEPT;
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const nodesToLinkify = [];
|
||||
while (walker.nextNode()) {
|
||||
nodesToLinkify.push(walker.currentNode);
|
||||
const nodesToLinkify = [];
|
||||
while (walker.nextNode()) {
|
||||
nodesToLinkify.push(walker.currentNode);
|
||||
}
|
||||
|
||||
nodesToLinkify.forEach((node) => linkifyTextNode(node));
|
||||
}
|
||||
|
||||
nodesToLinkify.forEach((node) => linkifyTextNode(node));
|
||||
|
||||
// TOC collapse/expand toggle
|
||||
const tocToggle = document.createElement("button");
|
||||
tocToggle.className = "toc-toggle";
|
||||
|
|
@ -290,7 +291,7 @@ const toc = document.querySelector(".toc");
|
|||
const layout = document.querySelector(".layout");
|
||||
|
||||
tocToggle.addEventListener("click", () => {
|
||||
toc.classList.toggle("collapsed");
|
||||
layout.classList.toggle("toc-hidden");
|
||||
toc?.classList.toggle("collapsed");
|
||||
layout?.classList.toggle("toc-hidden");
|
||||
document.body.classList.toggle("toc-collapsed");
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue