From a65abecc15dc8f7d5896da0c81b3e709d776b16d Mon Sep 17 00:00:00 2001 From: joedolson Date: Sat, 16 Jul 2022 01:08:10 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@53709 git-svn-id: http://core.svn.wordpress.org/trunk@53268 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/wp-ajax-response.js | 20 ++++++++++++++------ wp-includes/js/wp-ajax-response.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wp-includes/js/wp-ajax-response.js b/wp-includes/js/wp-ajax-response.js index f1b0dcd361..3fd6ff0314 100644 --- a/wp-includes/js/wp-ajax-response.js +++ b/wp-includes/js/wp-ajax-response.js @@ -53,19 +53,27 @@ window.wpAjax = jQuery.extend( { parsed.responses.push( response ); } ); if ( err.length ) { - re.html( '
' + err + '
' ); + re.html( '
' + err + '
' ); wp.a11y.speak( err ); } else if ( noticeMessage.length ) { - re.html( '

' + noticeMessage + '

'); + re.html( '

' + noticeMessage + '

'); jQuery(document).trigger( 'wp-updates-notice-added' ); wp.a11y.speak( noticeMessage ); } return parsed; } - if ( isNaN(x) ) { return !re.html('

' + x + '

'); } - x = parseInt(x,10); - if ( -1 === x ) { return !re.html('

' + wpAjax.noPerm + '

'); } - else if ( 0 === x ) { return !re.html('

' + wpAjax.broken + '

'); } + if ( isNaN( x ) ) { + wp.a11y.speak( x ); + return ! re.html( '

' + x + '

' ); + } + x = parseInt( x, 10 ); + if ( -1 === x ) { + wp.a11y.speak( wpAjax.noPerm ); + return ! re.html( '

' + wpAjax.noPerm + '

' ); + } else if ( 0 === x ) { + wp.a11y.speak( wpAjax.broken ); + return ! re.html( '

' + wpAjax.broken + '

' ); + } return true; }, invalidateForm: function ( selector ) { diff --git a/wp-includes/js/wp-ajax-response.min.js b/wp-includes/js/wp-ajax-response.min.js index 98bf64353d..db74038fc1 100644 --- a/wp-includes/js/wp-ajax-response.min.js +++ b/wp-includes/js/wp-ajax-response.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -window.wpAjax=jQuery.extend({unserialize:function(e){var r,t,i,a,n={};if(!e)return n;for(i in t=(e=(r=e.split("?"))[1]?r[1]:e).split("&"))"function"==typeof t.hasOwnProperty&&!t.hasOwnProperty(i)||(n[(a=t[i].split("="))[0]]=a[1]);return n},parseAjaxResponse:function(a,e,n){var o={},e=jQuery("#"+e).empty(),s="",t="";return a&&"object"==typeof a&&a.getElementsByTagName("wp_ajax")?(o.responses=[],o.errors=!1,jQuery("response",a).each(function(){var e=jQuery(this),r=jQuery(this.firstChild),i={action:e.attr("action"),what:r.get(0).nodeName,id:r.attr("id"),oldId:r.attr("old_id"),position:r.attr("position")};i.data=jQuery("response_data",r).text(),i.supplemental={},jQuery("supplemental",r).children().each(function(){"notice"===this.nodeName?t+=jQuery(this).text():i.supplemental[this.nodeName]=jQuery(this).text()}).length||(i.supplemental=!1),i.errors=[],jQuery("wp_error",r).each(function(){var e=jQuery(this).attr("code"),r={code:e,message:this.firstChild.nodeValue,data:!1},t=jQuery('wp_error_data[code="'+e+'"]',a);t&&(r.data=t.get()),(t=jQuery("form-field",t).text())&&(e=t),n&&wpAjax.invalidateForm(jQuery("#"+n+' :input[name="'+e+'"]').parents(".form-field:first")),s+="

"+r.message+"

",i.errors.push(r),o.errors=!0}).length||(i.errors=!1),o.responses.push(i)}),s.length?(e.html('
'+s+"
"),wp.a11y.speak(s)):t.length&&(e.html('

'+t+"

"),jQuery(document).trigger("wp-updates-notice-added"),wp.a11y.speak(t)),o):isNaN(a)?!e.html('

'+a+"

"):-1===(a=parseInt(a,10))?!e.html('

'+wpAjax.noPerm+"

"):0!==a||!e.html('

'+wpAjax.broken+"

")},invalidateForm:function(e){return jQuery(e).addClass("form-invalid").find("input").one("change wp-check-valid-field",function(){jQuery(this).closest(".form-invalid").removeClass("form-invalid")})},validateForm:function(e){return e=jQuery(e),!wpAjax.invalidateForm(e.find(".form-required").filter(function(){return""===jQuery("input:visible",this).val()})).length}},wpAjax||{noPerm:"Sorry, you are not allowed to do that.",broken:"Something went wrong."}),jQuery(function(e){e("form.validate").on("submit",function(){return wpAjax.validateForm(e(this))})}); \ No newline at end of file +window.wpAjax=jQuery.extend({unserialize:function(e){var t,r,i,n,a={};if(!e)return a;for(i in r=(e=(t=e.split("?"))[1]?t[1]:e).split("&"))"function"==typeof r.hasOwnProperty&&!r.hasOwnProperty(i)||(a[(n=r[i].split("="))[0]]=n[1]);return a},parseAjaxResponse:function(n,e,a){var o={},e=jQuery("#"+e).empty(),s="",r="";return n&&"object"==typeof n&&n.getElementsByTagName("wp_ajax")?(o.responses=[],o.errors=!1,jQuery("response",n).each(function(){var e=jQuery(this),t=jQuery(this.firstChild),i={action:e.attr("action"),what:t.get(0).nodeName,id:t.attr("id"),oldId:t.attr("old_id"),position:t.attr("position")};i.data=jQuery("response_data",t).text(),i.supplemental={},jQuery("supplemental",t).children().each(function(){"notice"===this.nodeName?r+=jQuery(this).text():i.supplemental[this.nodeName]=jQuery(this).text()}).length||(i.supplemental=!1),i.errors=[],jQuery("wp_error",t).each(function(){var e=jQuery(this).attr("code"),t={code:e,message:this.firstChild.nodeValue,data:!1},r=jQuery('wp_error_data[code="'+e+'"]',n);r&&(t.data=r.get()),(r=jQuery("form-field",r).text())&&(e=r),a&&wpAjax.invalidateForm(jQuery("#"+a+' :input[name="'+e+'"]').parents(".form-field:first")),s+="

"+t.message+"

",i.errors.push(t),o.errors=!0}).length||(i.errors=!1),o.responses.push(i)}),s.length?(e.html('
'+s+"
"),wp.a11y.speak(s)):r.length&&(e.html('

'+r+"

"),jQuery(document).trigger("wp-updates-notice-added"),wp.a11y.speak(r)),o):isNaN(n)?(wp.a11y.speak(n),!e.html('

'+n+"

")):-1===(n=parseInt(n,10))?(wp.a11y.speak(wpAjax.noPerm),!e.html('

'+wpAjax.noPerm+"

")):0!==n||(wp.a11y.speak(wpAjax.broken),!e.html('

'+wpAjax.broken+"

"))},invalidateForm:function(e){return jQuery(e).addClass("form-invalid").find("input").one("change wp-check-valid-field",function(){jQuery(this).closest(".form-invalid").removeClass("form-invalid")})},validateForm:function(e){return e=jQuery(e),!wpAjax.invalidateForm(e.find(".form-required").filter(function(){return""===jQuery("input:visible",this).val()})).length}},wpAjax||{noPerm:"Sorry, you are not allowed to do that.",broken:"Something went wrong."}),jQuery(function(e){e("form.validate").on("submit",function(){return wpAjax.validateForm(e(this))})}); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 2a357e787f..354ca6bc53 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53708'; +$wp_version = '6.1-alpha-53709'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.