chore: search cleanup
This commit is contained in:
parent
839bb9a808
commit
a141dd5ce0
3 changed files with 118 additions and 25 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "1.5.19",
|
"version": "1.5.20",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "1.5.19",
|
"version": "1.5.20",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cdransf/api-text": "^1.5.0",
|
"@cdransf/api-text": "^1.5.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "1.5.19",
|
"version": "1.5.20",
|
||||||
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -1,4 +1,96 @@
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
|
// menu keyboard controls
|
||||||
|
(() => {
|
||||||
|
const menuInput = document.getElementById("menu-toggle");
|
||||||
|
const menuButtonContainer = document.querySelector(
|
||||||
|
".menu-button-container"
|
||||||
|
);
|
||||||
|
const menuItems = document.querySelectorAll(".menu-primary li");
|
||||||
|
|
||||||
|
menuButtonContainer.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "Enter" || e.key === " ") {
|
||||||
|
e.preventDefault();
|
||||||
|
menuInput.checked = !menuInput.checked;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
menuItems.forEach((item) => {
|
||||||
|
item.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "Enter" || e.key === " ") {
|
||||||
|
e.preventDefault();
|
||||||
|
item.querySelector("a").click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "Escape" && menuInput.checked) menuInput.checked = false;
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
// modal keyboard controls and scroll management
|
||||||
|
(() => {
|
||||||
|
const modalInputs = document.querySelectorAll(".modal-input");
|
||||||
|
if (!modalInputs) return;
|
||||||
|
|
||||||
|
const toggleBodyScroll = (disableScroll) => {
|
||||||
|
if (disableScroll) {
|
||||||
|
document.body.style.overflow = "hidden";
|
||||||
|
} else {
|
||||||
|
document.body.style.overflow = "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkModals = () => {
|
||||||
|
let isAnyModalOpen = false;
|
||||||
|
modalInputs.forEach((modalInput) => {
|
||||||
|
if (modalInput.checked) isAnyModalOpen = true;
|
||||||
|
});
|
||||||
|
toggleBodyScroll(isAnyModalOpen);
|
||||||
|
};
|
||||||
|
|
||||||
|
modalInputs.forEach((modalInput) => {
|
||||||
|
modalInput.addEventListener("change", checkModals);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
modalInputs.forEach((modalInput) => {
|
||||||
|
if (modalInput.checked) modalInput.checked = false;
|
||||||
|
});
|
||||||
|
toggleBodyScroll(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
checkModals();
|
||||||
|
})();
|
||||||
|
|
||||||
|
// text toggle for media pages
|
||||||
|
(() => {
|
||||||
|
const button = document.querySelector("[data-toggle-button]");
|
||||||
|
const content = document.querySelector("[data-toggle-content]");
|
||||||
|
const text = document.querySelectorAll("[data-toggle-content] p");
|
||||||
|
const minHeight = 500; // this needs to match the height set on [data-toggle-content].text-toggle-hidden in text-toggle.css
|
||||||
|
const interiorHeight = Array.from(text).reduce(
|
||||||
|
(acc, node) => acc + node.scrollHeight,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!button || !content || !text) return;
|
||||||
|
|
||||||
|
if (interiorHeight < minHeight) {
|
||||||
|
content.classList.remove("text-toggle-hidden");
|
||||||
|
button.style.display = "none";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
const isHidden = content.classList.toggle("text-toggle-hidden");
|
||||||
|
button.textContent = isHidden ? "Show more" : "Show less";
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
// search logic
|
||||||
(() => {
|
(() => {
|
||||||
if (typeof MiniSearch === "undefined") return;
|
if (typeof MiniSearch === "undefined") return;
|
||||||
|
|
||||||
|
@ -39,6 +131,7 @@ window.addEventListener("load", () => {
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
let currentResults = [];
|
let currentResults = [];
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
let debounceTimeout; // Declare debounceTimeout here
|
||||||
|
|
||||||
const parseMarkdown = (markdown) =>
|
const parseMarkdown = (markdown) =>
|
||||||
markdown
|
markdown
|
||||||
|
|
Reference in a new issue