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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Polyfill for the [ARIA Notification API](https://github.com/WICG/accessible-notifications/blob/main/README.md)

The goal of this library is to polyfill `ariaNotify` so that it can be used seamlessly across browsers that support the native functionality, and those that don't. This adds the `Element.prototype.ariaNotify` function if it does not exist, emulating the native functionality.
The goal of this library is to polyfill `ariaNotify` so that it can be used seamlessly across browsers that support the native functionality, and those that don't. This adds the `Element.prototype.ariaNotify` and/or `Document.prototype.ariaNotify` functions if they do not exist, emulating the native functionality.

This is used in production on github.com.

Expand Down
40 changes: 28 additions & 12 deletions arianotify-polyfill.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

if (!("ariaNotify" in Element.prototype)) {
if (!("ariaNotify" in Element.prototype) || !("ariaNotify" in Document.prototype)) {
/** @type {string} */
let uniqueId = `${Date.now()}`;
try {
Expand Down Expand Up @@ -166,15 +166,31 @@ if (!("ariaNotify" in Element.prototype)) {
}
customElements.define(liveRegionCustomElementName, LiveRegionCustomElement);

/**
* @param {string} message
* @param {object} options
* @param {"high" | "normal"} [options.priority]
*/
Element.prototype["ariaNotify"] = function (
message,
{ priority = "normal" } = {}
) {
queue.enqueue(new Message({ element: this, message, priority }));
};
if (!("ariaNotify" in Element.prototype)) {
/**
* @param {string} message
* @param {object} options
* @param {"high" | "normal"} [options.priority]
*/
Element.prototype["ariaNotify"] = function (
message,
{ priority = "normal" } = {}
) {
queue.enqueue(new Message({ element: this, message, priority }));
};
}

if (!("ariaNotify" in Document.prototype)) {
/**
* @param {string} message
* @param {object} options
* @param {"high" | "normal"} [options.priority]
*/
Document.prototype["ariaNotify"] = function (
message,
{ priority = "normal" } = {}
) {
queue.enqueue(new Message({ element: this.documentElement, message, priority }));
};
}
}