1/** 2 * Adds an HTML element and method to trigger audio UAs to read system messages. 3 * 4 * Use Backdrop.announce() to indicate to screen reader users that an element on 5 * the page has changed state. For instance, if clicking a link loads 10 more 6 * items into a list, one might announce the change like this. 7 * $('#search-list') 8 * .on('itemInsert', function (event, data) { 9 * // Insert the new items. 10 * $(data.container.el).append(data.items.el); 11 * // Announce the change to the page contents. 12 * Backdrop.announce(Backdrop.t('@count items added to @container', 13 * {'@count': data.items.length, '@container': data.container.title} 14 * )); 15 * }); 16 */ 17(function (Backdrop) { 18 var liveElement; 19 var announcements = []; 20 Backdrop.behaviors.backdropAnnounce = { 21 attach: function attach(context) { 22 if (!liveElement) { 23 liveElement = document.createElement('div'); 24 liveElement.id = 'backdrop-live-announce'; 25 liveElement.className = 'element-invisible'; 26 liveElement.setAttribute('aria-live', 'polite'); 27 liveElement.setAttribute('aria-busy', 'false'); 28 document.body.appendChild(liveElement); 29 } 30 } 31 }; 32 33 function announce() { 34 var text = []; 35 var priority = 'polite'; 36 var announcement; 37 var il = announcements.length; 38 39 for (var i = 0; i < il; i++) { 40 announcement = announcements.pop(); 41 text.unshift(announcement.text); 42 43 if (announcement.priority === 'assertive') { 44 priority = 'assertive'; 45 } 46 } 47 48 if (text.length) { 49 liveElement.innerHTML = ''; 50 liveElement.setAttribute('aria-busy', 'true'); 51 liveElement.setAttribute('aria-live', priority); 52 liveElement.innerHTML = text.join('\n'); 53 liveElement.setAttribute('aria-busy', 'false'); 54 } 55 } 56 57 /** 58 * Triggers audio UAs to read the supplied text. 59 * 60 * The aria-live region will only read the text that currently populates its 61 * text node. Replacing text quickly in rapid calls to announce results in 62 * only the text from the most recent call to Backdrop.announce() being 63 * read. By wrapping the call to announce in a debounce function, we allow for 64 * time for multiple calls to Backdrop.announce() to queue up their 65 * messages. These messages are then joined and append to the aria-live region 66 * as one text node. 67 * 68 * @param string text 69 * A string to be read by the UA. 70 * @param string priority 71 * A string to indicate the priority of the message. Can be either 72 * 'polite' or 'assertive'. 73 * 74 * @return function 75 * The return of the call to debounce. 76 * 77 * @see http://www.w3.org/WAI/PF/aria-practices/#liveprops 78 * @since 1.18.2 Method added. 79 */ 80 Backdrop.announce = function (text, priority) { 81 announcements.push({ 82 text: text, 83 priority: priority 84 }); 85 return Backdrop.debounce(announce, 300)(); 86 }; 87})(Backdrop);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.