Ticket #32600: 32600.4.patch
File 32600.4.patch, 3.0 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 'politeness' argument. 12 14 * 13 * @param {String} message 15 * @param {String} message The message to be announced by Assistive Technologies. 16 * @param {String} politeness 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, politeness ) { 20 21 // Clear previous messages if any to allow repeated strings being read out. 22 speakClear(); 23 24 if ( $containerAssertive && 'assertive' === politeness ) { 25 26 // Print the message to the assertive live region. 27 $containerAssertive.text( message ); 28 29 } else if ( $containerPolite ) { 30 31 // Print the message to the polite live region. 32 $containerPolite.text( message ); 33 18 34 } 19 35 } 20 36 21 37 /** 38 * Build the live regions markup. 39 * 40 * @since 4.3.0 41 * 42 * @param {String} id The id attribute for the live region. 43 * @param {String} politeness The value for the 'aria-live' attribute. 44 * 45 * @return {Object} $container The ARIA live region jQuery object. 46 */ 47 function speakAddContainer( id, politeness ) { 48 49 // Create a jQuery live region object. 50 var $container = $( '<div>', { 51 'id': id, 52 'role': 'status', 53 'aria-live': politeness, 54 'aria-relevant': 'additions text', 55 'aria-atomic': 'true', 56 'class': 'screen-reader-text wp-a11y-speak-region' 57 }); 58 59 $( document.body ).append( $container ); 60 61 return $container; 62 } 63 64 /** 65 * Clear the live regions. 66 * 67 * @since 4.3.0 68 */ 69 function speakClear() { 70 $( '.wp-a11y-speak-region' ).text( '' ); 71 } 72 73 /** 22 74 * Initialize wp.a11y and define ARIA live notification area. 23 75 * 24 76 * @since 4.2.0 77 * @since 4.3.0 Added the assertive live region. 25 78 */ 26 79 $( document ).ready( function() { 27 $container = $( '#wp-a11y-speak' ); 80 $containerPolite = $( '#wp-a11y-speak-polite' ); 81 $containerAssertive = $( '#wp-a11y-speak-assertive' ); 28 82 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 } ); 83 if ( ! $containerPolite.length ) { 84 $containerPolite = speakAddContainer( 'wp-a11y-speak-polite', 'polite' ); 85 } 38 86 39 $( document.body ).append( $container ); 87 if ( ! $containerAssertive.length ) { 88 $containerAssertive = speakAddContainer( 'wp-a11y-speak-assertive', 'assertive' ); 40 89 } 41 } 90 }); 42 91 43 92 wp.a11y = wp.a11y || {}; 44 93 wp.a11y.speak = speak;