more page accessibility fixes
All checks were successful
/ build (push) Successful in 26s

This commit is contained in:
Ruben 2025-04-07 11:26:39 -05:00
commit 6ef069cadc
No known key found for this signature in database
GPG key ID: 8EA836555FB6D9A5
8 changed files with 74 additions and 74 deletions

View file

@ -5,10 +5,10 @@
document.addEventListener("DOMContentLoaded", function () {
let popup = document.getElementById("alt-popup");
// add popup to all elements with alt
// add popup to all elements with alt or aria-label
function initializePopups() {
// find all elements with alt
const elementsWithAlt = document.querySelectorAll("[alt]");
// find all elements with alt or aria-label
const elementsWithAlt = document.querySelectorAll("[alt], [aria-label]");
// add mouse events to each element
elementsWithAlt.forEach((element) => {
@ -19,12 +19,16 @@ document.addEventListener("DOMContentLoaded", function () {
// show popup and position it near the cursor
function showPopup(event) {
// get alt text
// get alt text or aria-label
const altText = event.target.getAttribute("alt");
const ariaLabel = event.target.getAttribute("aria-label");
// Use alt text if available, otherwise use aria-label
const displayText = altText || ariaLabel;
if (altText) {
// use alt text in popup
popup.textContent = altText;
if (displayText) {
// use text in popup
popup.textContent = displayText;
// correct popup positioning away from cursor and make it visible
popup.style.left = event.clientX + 20 + "px";
@ -48,15 +52,13 @@ document.addEventListener("DOMContentLoaded", function () {
});
});
// Only set up the observer once
if (document.body) {
observer.observe(document.body, { childList: true, subtree: true });
}
}
});
// Start observing the document with the configured parameters
observer.observe(document.body, { childList: true, subtree: true });
// snippet that copies the html for my button(s)
function copyButtonSneexy() {
navigator.clipboard.writeText(