123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- (function (Drupal, debounce) {
- let liveElement;
- const announcements = [];
-
- Drupal.behaviors.drupalAnnounce = {
- attach(context) {
-
- if (!liveElement) {
- liveElement = document.createElement('div');
- liveElement.id = 'drupal-live-announce';
- liveElement.className = 'visually-hidden';
- liveElement.setAttribute('aria-live', 'polite');
- liveElement.setAttribute('aria-busy', 'false');
- document.body.appendChild(liveElement);
- }
- },
- };
-
- function announce() {
- const text = [];
- let priority = 'polite';
- let announcement;
-
-
- const il = announcements.length;
- for (let i = 0; i < il; i++) {
- announcement = announcements.pop();
- text.unshift(announcement.text);
-
-
- if (announcement.priority === 'assertive') {
- priority = 'assertive';
- }
- }
- if (text.length) {
-
- liveElement.innerHTML = '';
-
- liveElement.setAttribute('aria-busy', 'true');
-
- liveElement.setAttribute('aria-live', priority);
-
-
- liveElement.innerHTML = text.join('\n');
-
- liveElement.setAttribute('aria-busy', 'false');
- }
- }
-
- Drupal.announce = function (text, priority) {
-
-
- announcements.push({
- text,
- priority,
- });
-
-
-
- return (debounce(announce, 200)());
- };
- }(Drupal, Drupal.debounce));
|