Administration: Audible messages on AJAX error cases.

Issues appropriate audible messages via `wp.a11y.speak()` when `ajax-response.js` generates an error via `wp_die()`.

Props afercia, alexstine.
Fixes #54483.

git-svn-id: https://develop.svn.wordpress.org/trunk@53709 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Dolson
2022-07-16 01:06:40 +00:00
parent 9341481811
commit b977f5b18f

View File

@@ -53,19 +53,27 @@ window.wpAjax = jQuery.extend( {
parsed.responses.push( response );
} );
if ( err.length ) {
re.html( '<div class="error">' + err + '</div>' );
re.html( '<div class="notice notice-error">' + err + '</div>' );
wp.a11y.speak( err );
} else if ( noticeMessage.length ) {
re.html( '<div class="updated notice is-dismissible"><p>' + noticeMessage + '</p></div>');
re.html( '<div class="notice notice-success is-dismissible"><p>' + noticeMessage + '</p></div>');
jQuery(document).trigger( 'wp-updates-notice-added' );
wp.a11y.speak( noticeMessage );
}
return parsed;
}
if ( isNaN(x) ) { return !re.html('<div class="error"><p>' + x + '</p></div>'); }
x = parseInt(x,10);
if ( -1 === x ) { return !re.html('<div class="error"><p>' + wpAjax.noPerm + '</p></div>'); }
else if ( 0 === x ) { return !re.html('<div class="error"><p>' + wpAjax.broken + '</p></div>'); }
if ( isNaN( x ) ) {
wp.a11y.speak( x );
return ! re.html( '<div class="notice notice-error"><p>' + x + '</p></div>' );
}
x = parseInt( x, 10 );
if ( -1 === x ) {
wp.a11y.speak( wpAjax.noPerm );
return ! re.html( '<div class="notice notice-error"><p>' + wpAjax.noPerm + '</p></div>' );
} else if ( 0 === x ) {
wp.a11y.speak( wpAjax.broken );
return ! re.html( '<div class="notice notice-error"><p>' + wpAjax.broken + '</p></div>' );
}
return true;
},
invalidateForm: function ( selector ) {