Skip to content

Commit f3eb3eb

Browse files
authored
feat: Implement on Document (#22)
Fixes #19
2 parents 3499580 + 3144b7f commit f3eb3eb

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
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.
5+
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.
66

77
This is used in production on github.com.
88

arianotify-polyfill.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22

3-
if (!("ariaNotify" in Element.prototype)) {
3+
if (!("ariaNotify" in Element.prototype) || !("ariaNotify" in Document.prototype)) {
44
/** @type {string} */
55
let uniqueId = `${Date.now()}`;
66
try {
@@ -166,15 +166,31 @@ if (!("ariaNotify" in Element.prototype)) {
166166
}
167167
customElements.define(liveRegionCustomElementName, LiveRegionCustomElement);
168168

169-
/**
170-
* @param {string} message
171-
* @param {object} options
172-
* @param {"high" | "normal"} [options.priority]
173-
*/
174-
Element.prototype["ariaNotify"] = function (
175-
message,
176-
{ priority = "normal" } = {}
177-
) {
178-
queue.enqueue(new Message({ element: this, message, priority }));
179-
};
169+
if (!("ariaNotify" in Element.prototype)) {
170+
/**
171+
* @param {string} message
172+
* @param {object} options
173+
* @param {"high" | "normal"} [options.priority]
174+
*/
175+
Element.prototype["ariaNotify"] = function (
176+
message,
177+
{ priority = "normal" } = {}
178+
) {
179+
queue.enqueue(new Message({ element: this, message, priority }));
180+
};
181+
}
182+
183+
if (!("ariaNotify" in Document.prototype)) {
184+
/**
185+
* @param {string} message
186+
* @param {object} options
187+
* @param {"high" | "normal"} [options.priority]
188+
*/
189+
Document.prototype["ariaNotify"] = function (
190+
message,
191+
{ priority = "normal" } = {}
192+
) {
193+
queue.enqueue(new Message({ element: this.documentElement, message, priority }));
194+
};
195+
}
180196
}

0 commit comments

Comments
 (0)