clean up clean up everybody do your share

This commit is contained in:
2026-02-17 20:42:52 -06:00
parent 3f0f9907ed
commit 44948a6e9f
12 changed files with 263 additions and 485 deletions

View File

@@ -1,28 +1,28 @@
function toggleMenu(collapse=false) {
function toggleMenu(collapse) {
if (window.innerWidth < 1400) {
const e = document.querySelector(".navControl");
const menu = document.querySelector(".navControl");
const bar = document.querySelector(".header");
const isCollapsed = !e.style.maxHeight || e.style.maxHeight === "0px";
const isCollapsed = !menu.style.maxHeight || menu.style.maxHeight === "0px";
if (isCollapsed && !collapse) {
e.style.maxHeight = `${e.scrollHeight + 10}px`;
menu.style.maxHeight = `${menu.scrollHeight + 10}px`;
bar.style.borderBottomWidth = "0px";
} else {
e.style.maxHeight = "0px";
menu.style.maxHeight = "0px";
bar.style.borderBottomWidth = "3px";
}
}
}
async function goto(location, { push = true } = {}) {
let a;
let response;
try {
a = await fetch("/api/goto/" + location, {
response = await fetch("/api/goto/" + location, {
credentials: "include",
method: "GET",
mode: "cors",
});
if (!a.ok) {
console.error(`Navigation failed: HTTP ${a.status}`);
if (!response.ok) {
console.error(`Navigation failed: HTTP ${response.status}`);
return;
}
} catch (err) {
@@ -32,29 +32,29 @@ async function goto(location, { push = true } = {}) {
document.dispatchEvent(new Event('beforenavigate'));
const response = await a.json();
const metadata = response[0];
const content = response[1];
const [metadata, content] = await response.json();
const root = document.getElementById("root");
root.innerHTML = content;
root.querySelectorAll("script").forEach((oldScript) => {
// Re-execute scripts injected via innerHTML (browser ignores them otherwise)
root.querySelectorAll("script").forEach(function(oldScript) {
const newScript = document.createElement("script");
Array.from(oldScript.attributes).forEach(attr => {
Array.from(oldScript.attributes).forEach(function(attr) {
newScript.setAttribute(attr.name, attr.value);
});
newScript.textContent = oldScript.textContent;
oldScript.parentNode.replaceChild(newScript, oldScript);
});
if (!window.location.href.includes("#")) {
window.scrollTo({top: 0, left: 0, behavior:"instant"});
} else {
const eid = decodeURIComponent(window.location.hash.substring(1));
const el = document.getElementById(eid);
if (window.location.href.includes("#")) {
const id = decodeURIComponent(window.location.hash.substring(1));
const el = document.getElementById(id);
if (el) el.scrollIntoView();
} else {
window.scrollTo({ top: 0, left: 0, behavior: "instant" });
}
toggleMenu(collapse=true);
toggleMenu(true);
document.querySelector("title").textContent = metadata["title"];
if (push) {
history.pushState(null, null, metadata["canonical"]);
@@ -62,6 +62,18 @@ async function goto(location, { push = true } = {}) {
}
function backButton() {
const location = window.location.pathname;
goto(location.substring(1), { push: false }); // remove slash, goto already does that
const path = window.location.pathname;
goto(path.substring(1), { push: false });
}
function activeSkill(obj) {
let skill = obj.closest(".skill");
if (skill.classList.contains("activeSkill")) {
skill.classList.remove("activeSkill");
return;
}
while (skill) {
skill.classList.add("activeSkill");
skill = skill.parentElement.closest(".skill");
}
}