Ticket #32600: 32600.5.patch
File 32600.5.patch, 2.8 KB (added by , 9 years ago) |
---|
-
src/wp-includes/js/wp-a11y.js
3 3 ( function ( wp, $ ) { 4 4 'use strict'; 5 5 6 var $container; 6 var $containerPolite, 7 $containerAssertive; 7 8 8 9 /** 9 10 * Update the ARIA live notification area text node. 10 11 * 11 12 * @since 4.2.0 13 * @since 4.3.0 Introduced the 'ariaLive' argument. 12 14 * 13 * @param {String} message 15 * @param {String} message The message to be announced by Assistive Technologies. 16 * @param {String} ariaLive Optional. The politeness level for aria-live. Possible values: 17 * polite or assertive. Default polite. 14 18 */ 15 function speak( message ) { 16 if ( $container ) { 17 $container.text( message ); 19 function speak( message, ariaLive ) { 20 // Clear previous messages to allow repeated strings being read out. 21 clear(); 22 23 if ( $containerAssertive && 'assertive' === ariaLive ) { 24 $containerAssertive.text( message ); 25 } else if ( $containerPolite ) { 26 $containerPolite.text( message ); 18 27 } 19 28 } 20 29 21 30 /** 31 * Build the live regions markup. 32 * 33 * @since 4.3.0 34 * 35 * @param {String} id The id attribute for the live region. 36 * @param {String} ariaLive Optional Value for the 'aria-live' attribute, default 'polite'. 37 * 38 * @return {Object} $container The ARIA live region jQuery object. 39 */ 40 function addContainer( ariaLive ) { 41 ariaLive = ariaLive || 'polite'; 42 43 var $container = $( '<div>', { 44 'id': 'wp-a11y-speak-' + ariaLive, 45 'role': 'status', 46 'aria-live': ariaLive, 47 'aria-relevant': 'additions text', 48 'aria-atomic': 'true', 49 'class': 'screen-reader-text wp-a11y-speak-region' 50 }); 51 52 $( document.body ).append( $container ); 53 return $container; 54 } 55 56 /** 57 * Clear the live regions. 58 * 59 * @since 4.3.0 60 */ 61 function clear() { 62 $( '.wp-a11y-speak-region' ).text( '' ); 63 } 64 65 /** 22 66 * Initialize wp.a11y and define ARIA live notification area. 23 67 * 24 68 * @since 4.2.0 69 * @since 4.3.0 Added the assertive live region. 25 70 */ 26 71 $( document ).ready( function() { 27 $container = $( '#wp-a11y-speak' ); 72 $containerPolite = $( '#wp-a11y-speak-polite' ); 73 $containerAssertive = $( '#wp-a11y-speak-assertive' ); 28 74 29 if ( ! $container.length ) { 30 $container = $( '<div>', { 31 id: 'wp-a11y-speak', 32 role: 'status', 33 'aria-live': 'polite', 34 'aria-relevant': 'all', 35 'aria-atomic': 'true', 36 'class': 'screen-reader-text' 37 } ); 75 if ( ! $containerPolite.length ) { 76 $containerPolite = addContainer( 'polite' ); 77 } 38 78 39 $( document.body ).append( $container ); 79 if ( ! $containerAssertive.length ) { 80 $containerAssertive = addContainer( 'assertive' ); 40 81 } 41 } 82 }); 42 83 43 84 wp.a11y = wp.a11y || {}; 44 85 wp.a11y.speak = speak;