-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathariaSpeak.js
More file actions
32 lines (23 loc) · 856 Bytes
/
ariaSpeak.js
File metadata and controls
32 lines (23 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/****************************************************************************
* ariaSpeak.js
* openacousticdevices.info
* May 2023
*****************************************************************************/
/**
* Say something if user is using a screen reader
* @param {string} text Text which should be said if viewed on a screen reader
*/
exports.speak = (text) => {
const element = document.createElement('div');
const id = 'speak-' + Date.now();
element.setAttribute('id', id);
element.setAttribute('aria-live', 'polite');
element.classList.add('visually-hidden');
document.body.appendChild(element);
window.setTimeout(() => {
document.getElementById(id).innerHTML = text;
}, 100);
window.setTimeout(() => {
document.body.removeChild(document.getElementById(id));
}, 1000);
};