mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
Add wp.a11y.speak() for audible alerts/updates in screen readers. Props afercia, GrahamArmfield (for the idea), iseulde. Fixes #31368.
git-svn-id: https://develop.svn.wordpress.org/trunk@31594 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
window.wp = window.wp || {};
|
||||
|
||||
( function ( wp, $ ) {
|
||||
'use strict';
|
||||
|
||||
var $container;
|
||||
|
||||
/**
|
||||
* Update the ARIA live notification area text node.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param {String} message
|
||||
*/
|
||||
function speak( message ) {
|
||||
if ( $container ) {
|
||||
$container.text( message );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize wp.a11y and define ARIA live notification area.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
$( document ).ready( function() {
|
||||
$container = $( '#wp-a11y-speak' );
|
||||
|
||||
if ( ! $container.length ) {
|
||||
$container = $( '<div>', {
|
||||
id: 'wp-a11y-speak',
|
||||
role: 'status',
|
||||
'aria-live': 'polite',
|
||||
'aria-relevant': 'all',
|
||||
'aria-atomic': 'true',
|
||||
'class': 'screen-reader-text'
|
||||
} );
|
||||
|
||||
$( document.body ).append( $container );
|
||||
}
|
||||
} );
|
||||
|
||||
wp.a11y = wp.a11y || {};
|
||||
wp.a11y.speak = speak;
|
||||
|
||||
} )( window.wp, window.jQuery );
|
||||
Reference in New Issue
Block a user