Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions js/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -3352,20 +3352,7 @@ class Block {
const blockLabel =
(that.protoblock.staticLabels && that.protoblock.staticLabels[0]) ||
that.name;
const liveRegion =
document.getElementById("mbA11yLiveRegion") ||
(() => {
const r = document.createElement("div");
r.id = "mbA11yLiveRegion";
r.setAttribute("role", "status");
r.setAttribute("aria-live", "polite");
r.setAttribute("aria-atomic", "true");
r.style.cssText =
"position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden;";
document.body.appendChild(r);
return r;
})();
liveRegion.textContent = _("picked up") + " " + blockLabel;
announceToScreenReader(_("picked up") + " " + blockLabel);
}
}
} else {
Expand Down
24 changes: 22 additions & 2 deletions js/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (typeof module !== "undefined" && module.exports) {
}

/* exported
canvasPixelRatio, changeImage, closeBlkWidgets, closeWidgets,
announceToScreenReader,canvasPixelRatio, changeImage, closeBlkWidgets, closeWidgets,
delayExecution, displayMsg, doBrowserCheck, docByClass, docByName,
docBySelector, docByTagName, doPublish, doStopVideoCam, doSVG,
doUseCamera, format, getTextWidth, hideDOMLabel, httpGet, httpPost, HttpRequest,
Expand Down Expand Up @@ -1456,6 +1456,25 @@ let closeBlkWidgets = name => {
* @param {*[]} viewArgs - Constructor arguments for the view.
* @returns {void}
*/
/**
* Announces a message to screen readers via a shared aria-live region.
* Creates the region lazily on first use and reuses it for all subsequent calls.
* @param {string} msg - The message to announce.
*/
const announceToScreenReader = msg => {
let region = document.getElementById("mbA11yLiveRegion");
if (!region) {
region = document.createElement("div");
region.id = "mbA11yLiveRegion";
region.setAttribute("role", "status");
region.setAttribute("aria-live", "polite");
region.setAttribute("aria-atomic", "true");
region.style.cssText =
"position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden;";
document.body.appendChild(region);
}
region.textContent = msg;
};
let importMembers = (obj, className, modelArgs, viewArgs) => {
/**
* Adds methods and variables of one class to another class's instance.
Expand Down Expand Up @@ -1544,6 +1563,7 @@ if (typeof module !== "undefined" && module.exports) {
processPluginData,
processMacroData,
hideDOMLabel,
displayMsg
displayMsg,
announceToScreenReader
};
}
Loading