Add wp.a11y.speak() for audible alerts/updates in screen readers. Props afercia, GrahamArmfield (for the idea), iseulde. Fixes #31368.

Built from https://develop.svn.wordpress.org/trunk@31594


git-svn-id: http://core.svn.wordpress.org/trunk@31575 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-03-01 19:11:27 +00:00
parent a337c34c4e
commit 5e07bfdfd1
9 changed files with 65 additions and 9 deletions

View File

@ -118,8 +118,6 @@ do_action( 'customize_controls_print_scripts' );
<body class="<?php echo esc_attr( $body_class ); ?>">
<div class="wp-full-overlay expanded">
<form id="customize-controls" class="wrap wp-full-overlay-sidebar">
<div id="screen-reader-messages" role="status" aria-live="polite" aria-relevant="all" aria-atomic="true" class="screen-reader-text"></div>
<div id="customize-header-actions" class="wp-full-overlay-header">
<?php
$save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );

View File

@ -685,10 +685,10 @@
if ( isMoveUp ) {
self.moveUp();
$( '#screen-reader-messages' ).text( l10n.widgetMovedUp );
wp.a11y.speak( l10n.widgetMovedUp );
} else {
self.moveDown();
$( '#screen-reader-messages' ).text( l10n.widgetMovedDown );
wp.a11y.speak( l10n.widgetMovedDown );
}
$( this ).focus(); // re-focus after the container was moved

File diff suppressed because one or more lines are too long

View File

@ -107,6 +107,7 @@ window.wp = window.wp || {};
$message.addClass( 'updating-message' );
$message.text( wp.updates.l10n.updating );
wp.a11y.speak( wp.updates.l10n.updatingMsg );
if ( wp.updates.updateLock ) {
wp.updates.updateQueue.push( {
@ -153,6 +154,7 @@ window.wp = window.wp || {};
$message.removeClass( 'updating-message' ).addClass( 'updated-message' );
$message.text( wp.updates.l10n.updated );
wp.a11y.speak( wp.updates.l10n.updatedMsg );
wp.updates.decrementCount( 'plugin' );
};
@ -173,6 +175,7 @@ window.wp = window.wp || {};
}
$message.removeClass( 'updating-message' );
$message.text( wp.updates.l10n.updateFailed );
wp.a11y.speak( wp.updates.l10n.updateFailed );
};
/**
@ -198,6 +201,7 @@ window.wp = window.wp || {};
$message.addClass( 'updating-message' );
$message.text( wp.updates.l10n.installing );
wp.a11y.speak( wp.updates.l10n.installingMsg );
if ( wp.updates.updateLock ) {
wp.updates.updateQueue.push( {
@ -234,6 +238,7 @@ window.wp = window.wp || {};
$message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' );
$message.text( wp.updates.l10n.installed );
wp.a11y.speak( wp.updates.l10n.installedMsg );
};
/**

View File

@ -1 +1 @@
window.wp=window.wp||{},function(a,b,c){b.updates={},b.updates.ajaxNonce=window._wpUpdatesSettings.ajax_nonce,b.updates.l10n=window._wpUpdatesSettings.l10n,b.updates.updateLock=!1,b.updates.updateQueue=[],b.updates.decrementCount=function(b){var c,d,e=a("#wp-admin-bar-updates .ab-label"),f=a('a[href="update-core.php"] .update-plugins'),g=a("#menu-plugins");if(c=e.text(),c=parseInt(c,10)-1,!(0>c||isNaN(c))&&(a("#wp-admin-bar-updates .ab-item").removeAttr("title"),e.text(c),f.each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+c)}),f.removeAttr("title"),f.find(".update-count").text(c),"plugin"===b)){if(d=g.find(".plugin-count").eq(0).text(),d=parseInt(d,10)-1,0>d||isNaN(d))return;g.find(".plugin-count").text(d),g.find(".update-plugins").each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+d)}),d>0?a(".subsubsub .upgrade .count").text("("+d+")"):a(".subsubsub .upgrade").remove()}},b.updates.updatePlugin=function(d,e){var f;if("plugins"===c||"plugins-network"===c?f=a("#"+e).next().find(".update-message"):"plugin-install"===c&&(f=a(".plugin-card-"+e).find(".update-now")),f.addClass("updating-message"),f.text(b.updates.l10n.updating),b.updates.updateLock)return void b.updates.updateQueue.push({type:"update-plugin",data:{plugin:d,slug:e}});b.updates.updateLock=!0;var g={_ajax_nonce:b.updates.ajaxNonce,plugin:d,slug:e};b.ajax.post("update-plugin",g).done(b.updates.updateSuccess).fail(b.updates.updateError).always(b.updates.updateAlways)},b.updates.updateSuccess=function(d){var e;"plugins"===c||"plugins-network"===c?(e=a("#"+d.slug).next().find(".update-message"),a("#"+d.slug).addClass("updated").removeClass("update"),a("#"+d.slug+"-update").addClass("updated").removeClass("update")):"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now"),e.addClass("button-disabled")),e.removeClass("updating-message").addClass("updated-message"),e.text(b.updates.l10n.updated),b.updates.decrementCount("plugin")},b.updates.updateError=function(d){var e;"plugins"===c||"plugins-network"===c?e=a("#"+d.slug).next().find(".update-message"):"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now")),e.removeClass("updating-message"),e.text(b.updates.l10n.updateFailed)},b.updates.updateAlways=function(){b.updates.updateLock=!1,b.updates.queueChecker()},b.updates.installPlugin=function(c){var d=a(".plugin-card-"+c).find(".install-now");if(d.addClass("updating-message"),d.text(b.updates.l10n.installing),b.updates.updateLock)return void b.updates.updateQueue.push({type:"install-plugin",data:{slug:c}});b.updates.updateLock=!0;var e={_ajax_nonce:b.updates.ajaxNonce,slug:c};b.ajax.post("install-plugin",e).done(b.updates.installSuccess).fail(b.updates.installError).always(b.updates.updateAlways)},b.updates.installSuccess=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message").addClass("updated-message button-disabled"),d.text(b.updates.l10n.installed)},b.updates.installError=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message"),d.text(b.updates.l10n.installNow)},b.updates.queueChecker=function(){if(!(b.updates.updateLock||b.updates.updateQueue.length<=0)){var a=b.updates.updateQueue.shift();switch(a.type){case"update-plugin":b.updates.updatePlugin(a.data.plugin,a.data.slug);break;case"install-plugin":b.updates.installPlugin(a.data.slug);break;default:window.console.log("Failed to exect queued update job."),window.console.log(a)}}},a(document).ready(function(){a(".plugin-update-tr .update-link").on("click",function(c){c.preventDefault();var d=a(c.target).parents(".plugin-update-tr");b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a("#bulk-action-form").on("submit",function(c){var d,e,f;"update-selected"==a("#bulk-action-selector-top").val()&&(c.preventDefault(),a('input[name="checked[]"]:checked').each(function(c,g){d=a(g),e=d.val(),f=d.parents("tr").prop("id"),b.updates.updatePlugin(e,f),d.attr("checked",!1)}))}),a(".plugin-card .update-now").on("click",function(c){c.preventDefault();var d=a(c.target);b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a(".plugin-card .install-now").on("click",function(c){c.preventDefault();var d=a(c.target);d.hasClass("button-disabled")||b.updates.installPlugin(d.data("slug"))})}),a(window).on("message",function(c){var d,e=c.originalEvent,f=document.location,g=f.protocol+"//"+f.hostname;e.origin===g&&(d=a.parseJSON(e.data),"undefined"!=typeof d.action&&"decrementUpdateCount"===d.action&&b.updates.decrementCount(d.upgradeType))})}(jQuery,window.wp,window.pagenow,window.ajaxurl);
window.wp=window.wp||{},function(a,b,c){b.updates={},b.updates.ajaxNonce=window._wpUpdatesSettings.ajax_nonce,b.updates.l10n=window._wpUpdatesSettings.l10n,b.updates.updateLock=!1,b.updates.updateQueue=[],b.updates.decrementCount=function(b){var c,d,e=a("#wp-admin-bar-updates .ab-label"),f=a('a[href="update-core.php"] .update-plugins'),g=a("#menu-plugins");if(c=e.text(),c=parseInt(c,10)-1,!(0>c||isNaN(c))&&(a("#wp-admin-bar-updates .ab-item").removeAttr("title"),e.text(c),f.each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+c)}),f.removeAttr("title"),f.find(".update-count").text(c),"plugin"===b)){if(d=g.find(".plugin-count").eq(0).text(),d=parseInt(d,10)-1,0>d||isNaN(d))return;g.find(".plugin-count").text(d),g.find(".update-plugins").each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+d)}),d>0?a(".subsubsub .upgrade .count").text("("+d+")"):a(".subsubsub .upgrade").remove()}},b.updates.updatePlugin=function(d,e){var f;if("plugins"===c||"plugins-network"===c?f=a("#"+e).next().find(".update-message"):"plugin-install"===c&&(f=a(".plugin-card-"+e).find(".update-now")),f.addClass("updating-message"),f.text(b.updates.l10n.updating),b.a11y.speak(b.updates.l10n.updatingMsg),b.updates.updateLock)return void b.updates.updateQueue.push({type:"update-plugin",data:{plugin:d,slug:e}});b.updates.updateLock=!0;var g={_ajax_nonce:b.updates.ajaxNonce,plugin:d,slug:e};b.ajax.post("update-plugin",g).done(b.updates.updateSuccess).fail(b.updates.updateError).always(b.updates.updateAlways)},b.updates.updateSuccess=function(d){var e;"plugins"===c||"plugins-network"===c?(e=a("#"+d.slug).next().find(".update-message"),a("#"+d.slug).addClass("updated").removeClass("update"),a("#"+d.slug+"-update").addClass("updated").removeClass("update")):"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now"),e.addClass("button-disabled")),e.removeClass("updating-message").addClass("updated-message"),e.text(b.updates.l10n.updated),b.a11y.speak(b.updates.l10n.updatedMsg),b.updates.decrementCount("plugin")},b.updates.updateError=function(d){var e;"plugins"===c||"plugins-network"===c?e=a("#"+d.slug).next().find(".update-message"):"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now")),e.removeClass("updating-message"),e.text(b.updates.l10n.updateFailed),b.a11y.speak(b.updates.l10n.updateFailed)},b.updates.updateAlways=function(){b.updates.updateLock=!1,b.updates.queueChecker()},b.updates.installPlugin=function(c){var d=a(".plugin-card-"+c).find(".install-now");if(d.addClass("updating-message"),d.text(b.updates.l10n.installing),b.a11y.speak(b.updates.l10n.installingMsg),b.updates.updateLock)return void b.updates.updateQueue.push({type:"install-plugin",data:{slug:c}});b.updates.updateLock=!0;var e={_ajax_nonce:b.updates.ajaxNonce,slug:c};b.ajax.post("install-plugin",e).done(b.updates.installSuccess).fail(b.updates.installError).always(b.updates.updateAlways)},b.updates.installSuccess=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message").addClass("updated-message button-disabled"),d.text(b.updates.l10n.installed),b.a11y.speak(b.updates.l10n.installedMsg)},b.updates.installError=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message"),d.text(b.updates.l10n.installNow)},b.updates.queueChecker=function(){if(!(b.updates.updateLock||b.updates.updateQueue.length<=0)){var a=b.updates.updateQueue.shift();switch(a.type){case"update-plugin":b.updates.updatePlugin(a.data.plugin,a.data.slug);break;case"install-plugin":b.updates.installPlugin(a.data.slug);break;default:window.console.log("Failed to exect queued update job."),window.console.log(a)}}},a(document).ready(function(){a(".plugin-update-tr .update-link").on("click",function(c){c.preventDefault();var d=a(c.target).parents(".plugin-update-tr");b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a("#bulk-action-form").on("submit",function(c){var d,e,f;"update-selected"==a("#bulk-action-selector-top").val()&&(c.preventDefault(),a('input[name="checked[]"]:checked').each(function(c,g){d=a(g),e=d.val(),f=d.parents("tr").prop("id"),b.updates.updatePlugin(e,f),d.attr("checked",!1)}))}),a(".plugin-card .update-now").on("click",function(c){c.preventDefault();var d=a(c.target);b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a(".plugin-card .install-now").on("click",function(c){c.preventDefault();var d=a(c.target);d.hasClass("button-disabled")||b.updates.installPlugin(d.data("slug"))})}),a(window).on("message",function(c){var d,e=c.originalEvent,f=document.location,g=f.protocol+"//"+f.hostname;e.origin===g&&(d=a.parseJSON(e.data),"undefined"!=typeof d.action&&"decrementUpdateCount"===d.action&&b.updates.decrementCount(d.upgradeType))})}(jQuery,window.wp,window.pagenow,window.ajaxurl);

46
wp-includes/js/wp-a11y.js Normal file
View File

@ -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 );

1
wp-includes/js/wp-a11y.min.js vendored Normal file
View File

@ -0,0 +1 @@
window.wp=window.wp||{},function(a,b){"use strict";function c(a){d&&d.text(a)}var d;b(document).ready(function(){d=b("#wp-a11y-speak"),d.length||(d=b("<div>",{id:"wp-a11y-speak",role:"status","aria-live":"polite","aria-relevant":"all","aria-atomic":"true","class":"screen-reader-text"}),b(document.body).append(d))}),a.a11y=a.a11y||{},a.a11y.speak=c}(window.wp,window.jQuery);

View File

@ -82,6 +82,8 @@ function wp_default_scripts( &$scripts ) {
'warnDelete' => __("You are about to permanently delete the selected items.\n 'Cancel' to stop, 'OK' to delete.")
) );
$scripts->add( 'wp-a11y', "/wp-includes/js/wp-a11y$suffix.js", array( 'jquery' ), false, 1 );
$scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
$scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", array(), false, 1 );
@ -380,7 +382,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), 'r7', 1 );
$scripts->add( 'customize-base', "/wp-includes/js/customize-base$suffix.js", array( 'jquery', 'json2', 'underscore' ), false, 1 );
$scripts->add( 'customize-base', "/wp-includes/js/customize-base$suffix.js", array( 'jquery', 'json2', 'underscore', 'wp-a11y' ), false, 1 );
$scripts->add( 'customize-loader', "/wp-includes/js/customize-loader$suffix.js", array( 'customize-base' ), false, 1 );
$scripts->add( 'customize-preview', "/wp-includes/js/customize-preview$suffix.js", array( 'customize-base' ), false, 1 );
$scripts->add( 'customize-models', "/wp-includes/js/customize-models.js", array( 'underscore', 'backbone' ), false, 1 );
@ -532,7 +534,7 @@ function wp_default_scripts( &$scripts ) {
'ays' => __('Are you sure you want to install this plugin?')
) );
$scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util' ) );
$scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ) );
did_action( 'init' ) && $scripts->localize( 'updates', '_wpUpdatesSettings', array(
'ajax_nonce' => wp_create_nonce( 'updates' ),
'l10n' => array(
@ -543,6 +545,10 @@ function wp_default_scripts( &$scripts ) {
'installing' => __( 'Installing...' ),
'installed' => __( 'Installed!' ),
'installFailed' => __( 'Installation failed' ),
'updatingMsg' => __( 'Updating... please wait.' ),
'installingMsg' => __( 'Installing... please wait.' ),
'updatedMsg' => __( 'Update completed successfully.' ),
'installedMsg' => __( 'Installation completed successfully.' ),
)
) );

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-alpha-31593';
$wp_version = '4.2-alpha-31594';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.