Files
awesome-copilot/website/src/scripts/pages/extension-gallery.ts
T
github-actions[bot] 51b6fa0253 chore: publish from main
2026-07-10 03:24:21 +00:00

42 lines
1.0 KiB
TypeScript

/**
* Extension detail page image gallery.
* Switches the main preview image when a thumbnail is selected.
*/
function initExtensionGallery(): void {
const mainImage = document.getElementById(
"extension-gallery-image"
) as HTMLImageElement | null;
const thumbs = document.querySelectorAll<HTMLButtonElement>(
".extension-gallery-thumb"
);
if (!mainImage || thumbs.length === 0) return;
thumbs.forEach((thumb) => {
thumb.addEventListener("click", () => {
const url = thumb.dataset.galleryUrl;
if (!url) return;
mainImage.src = url;
thumbs.forEach((other) => {
const isActive = other === thumb;
other.classList.toggle("active", isActive);
if (isActive) {
other.setAttribute("aria-current", "true");
} else {
other.removeAttribute("aria-current");
}
});
});
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initExtensionGallery, {
once: true,
});
} else {
initExtensionGallery();
}