fix(scripts/index.js): formatting consistency

This commit is contained in:
Cory Dransfeldt 2025-06-09 15:30:53 -07:00
parent 328464670d
commit c54d27dc33
No known key found for this signature in database
3 changed files with 43 additions and 43 deletions

View file

@ -1,64 +1,64 @@
window.addEventListener("load", () => {
window.addEventListener('load', () => {
// service worker
if ('serviceWorker' in navigator) navigator.serviceWorker.register('/assets/scripts/sw.js');
// dialog controls
(() => {
const dialogButtons = document.querySelectorAll(".dialog-open");
const dialogButtons = document.querySelectorAll('.dialog-open');
if (!dialogButtons.length) return;
dialogButtons.forEach((button) => {
const dialogId = button.getAttribute("data-dialog-trigger");
const dialogId = button.getAttribute('data-dialog-trigger');
const dialog = document.getElementById(`dialog-${dialogId}`);
if (!dialog) return;
const closeButton = dialog.querySelector(".dialog-close");
const closeButton = dialog.querySelector('.dialog-close');
button.addEventListener("click", async () => {
button.addEventListener('click', async () => {
const isDynamic = dialog.dataset.dynamic;
const isLoaded = dialog.dataset.loaded;
if (isDynamic && !isLoaded) {
const markdownFields = dialog.dataset.markdown || "";
const markdownFields = dialog.dataset.markdown || '';
try {
const res = await fetch(`/api/query.php?data=${isDynamic}&id=${dialogId}&markdown=${encodeURIComponent(markdownFields)}`);
const [data] = await res.json();
const firstField = markdownFields.split(",")[0]?.trim();
const html = data?.[`${firstField}_html`] || "<p>No notes available.</p>";
const firstField = markdownFields.split(',')[0]?.trim();
const html = data?.[`${firstField}_html`] || '<p>No notes available.</p>';
dialog.querySelectorAll(".dialog-dynamic").forEach((el) => el.remove());
dialog.querySelectorAll('.dialog-dynamic').forEach((el) => el.remove());
const container = document.createElement("div");
const container = document.createElement('div');
container.classList.add("dialog-dynamic");
container.classList.add('dialog-dynamic');
container.innerHTML = html;
dialog.appendChild(container);
dialog.dataset.loaded = "true";
dialog.dataset.loaded = 'true';
} catch (err) {
dialog.querySelectorAll(".dialog-dynamic").forEach((el) => el.remove());
dialog.querySelectorAll('.dialog-dynamic').forEach((el) => el.remove());
const errorNode = document.createElement("div");
const errorNode = document.createElement('div');
errorNode.classList.add("dialog-dynamic");
errorNode.textContent = "Failed to load content.";
errorNode.classList.add('dialog-dynamic');
errorNode.textContent = 'Failed to load content.';
dialog.appendChild(errorNode);
console.warn("Dialog content load error:", err);
console.warn('Dialog content load error:', err);
}
}
dialog.showModal();
dialog.classList.remove("closing");
dialog.classList.remove('closing');
});
if (closeButton) {
closeButton.addEventListener("click", () => {
dialog.classList.add("closing");
closeButton.addEventListener('click', () => {
dialog.classList.add('closing');
setTimeout(() => dialog.close(), 200);
});
}
dialog.addEventListener("click", (event) => {
dialog.addEventListener('click', (event) => {
const rect = dialog.getBoundingClientRect();
const outsideClick =
event.clientX < rect.left ||
@ -67,14 +67,14 @@ window.addEventListener("load", () => {
event.clientY > rect.bottom;
if (outsideClick) {
dialog.classList.add("closing");
dialog.classList.add('closing');
setTimeout(() => dialog.close(), 200);
}
});
dialog.addEventListener("cancel", (event) => {
dialog.addEventListener('cancel', (event) => {
event.preventDefault();
dialog.classList.add("closing");
dialog.classList.add('closing');
setTimeout(() => dialog.close(), 200);
});
});
@ -82,23 +82,23 @@ window.addEventListener("load", () => {
// 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 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.length) return;
if (interiorHeight < minHeight) {
content.classList.remove("text-toggle-hidden");
button.style.display = "none";
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";
button.addEventListener('click', () => {
const isHidden = content.classList.toggle('text-toggle-hidden');
button.textContent = isHidden ? 'Show more' : 'Show less';
});
})();
});