Ticket #32600: 32600.2.patch
File 32600.2.patch, 3.0 KB (added by , 10 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 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 function speakMarkup( id, politeness ) { 46 47 // Create a jQuery live region object. 48 var $container = $( '<div>', { 49 'id': id, 50 'role': 'status', 51 'aria-live': politeness, 52 'aria-relevant': 'additions text', 53 'aria-atomic': 'true', 54 'class': 'screen-reader-text wp-a11y-speak-region' 55 }); 56 57 // Populate the polite and assertive jQuery objects. 58 if ( 'assertive' === politeness ) { 59 $containerAssertive = $container; 60 } else { 61 $containerPolite = $container; 62 } 63 64 $( document.body ).append( $container ); 65 } 66 67 /** 68 * Clear the live regions. 69 * 70 * @since 4.3.0 71 */ 72 function speakClear() { 73 $( '.wp-a11y-speak-region' ).text( '' ); 74 } 75 76 /** 22 77 * Initialize wp.a11y and define ARIA live notification area. 23 78 * 24 79 * @since 4.2.0 80 * @since 4.3.0 Added the assertive live region. 25 81 */ 26 82 $( document ).ready( function() { 27 $container = $( '#wp-a11y-speak' ); 83 $containerPolite = $( '#wp-a11y-speak-polite' ); 84 $containerAssertive = $( '#wp-a11y-speak-assertive' ); 28 85 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 } ); 86 if ( ! $containerPolite.length ) { 87 speakMarkup( 'wp-a11y-speak-polite', 'polite' ); 88 } 38 89 39 $( document.body ).append( $container ); 90 if ( ! $containerAssertive.length ) { 91 speakMarkup( 'wp-a11y-speak-assertive', 'assertive' ); 40 92 } 41 } 93 }); 42 94 43 95 wp.a11y = wp.a11y || {}; 44 96 wp.a11y.speak = speak;