/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** *UtilityfunctionsforUIaccessibility.
*/
var A11yUtils = { /** *Announceamessagetotheuser. *Thisshouldonlybeusedwhensomethinghappensthatisimportanttothe *userandwillbenoticedvisually,butisnotrelatedtothefocused *controlandisnotapop-upsuchasadoorhanger. *Forexample,thiscouldbeusedtoindicatethatReaderViewisavailable *orthatFirefoxismakingarecommendationviathetoolbar. *Thismustbeusedwithcaution,asitcancreateunwantedverbosityand *canthushinderratherthanhelpusersifusedincorrectly. *PleaseonlyusethisafterconsultationwiththeMozillaaccessibility *team. * *@param{object}[options] *@param{string}[options.id]TheFluentidofthemessagetoannounce.The *ftlfilemustalreadybeincludedinbrowser.xhtml.Thismustbe *specifiedunlessarawmessageisspecifiedinstead. *@param{object}[options.args]ArgumentsfortheFluentmessage. *@param{string}[options.raw]Theraw,alreadylocalizedmessageto *announce.YoushouldgenerallypreferaFluentidinstead,butin *rarecases,thismightnotbefeasible.
*/
async announce({ id = null, args = {}, raw = null } = {}) { if ((!id && !raw) || (id && raw)) { thrownew Error("One of raw or id must be specified.");
}
// Cancel a previous pending call if any. if (this._cancelAnnounce) { this._cancelAnnounce(); this._cancelAnnounce = null;
}
let message; if (id) {
let cancel = false; this._cancelAnnounce = () => (cancel = true);
message = await document.l10n.formatValue(id, args); if (cancel) { // announce() was called again while we were waiting for translation. return;
} // No more async operations from this point. this._cancelAnnounce = null;
} else { // We run fully synchronously if a raw message is provided.
message = raw;
}
// For now, we don't use source, but it might be useful in future. // For example, we might use it when we support announcement events on // more platforms or it could be used to have a keyboard shortcut which // focuses the last element to announce a message.
let live = document.getElementById("a11y-announcement"); // We use role="alert" because JAWS doesn't support aria-live in browser // chrome. // Gecko a11y needs an insertion to trigger an alert event. This is why // we can't just use aria-label on the alert. if (live.firstChild) {
live.firstChild.remove();
}
let label = document.createElement("label");
label.setAttribute("aria-label", message);
live.appendChild(label);
},
};
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-09-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.