Plugins: Prevent ajaxComplete listener from observing all events.

Add a conditional to prevent the `prefers-reduced-motion` `ajaxComplete` listener from observing events not occurring in the plugin installation screen. Improve handling of settings data test.

The listener observing `ajaxComplete` in [56541] was intercepting all `ajaxComplete` events, creating potential for unexpected errors in unrelated functions.

Props bplv, afercia, rudlinkon, hellofromTonya, huzaifaalmesbah, joedolson, jorbin.
Fixes #59689.
Built from https://develop.svn.wordpress.org/trunk@57022


git-svn-id: http://core.svn.wordpress.org/trunk@56533 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2023-10-27 19:25:20 +00:00
parent b4a6b21986
commit 32bf11b728
3 changed files with 24 additions and 20 deletions

View File

@ -2129,8 +2129,8 @@ $( function( $ ) {
/** /**
* Freeze animated plugin icons when reduced motion is enabled. * Freeze animated plugin icons when reduced motion is enabled.
* *
* When the user has enabled the 'prefers-reduced-motion' setting, this module * When the user has enabled the 'prefers-reduced-motion' setting, this module
* stops animations for all GIFs on the page with the class 'plugin-icon' or * stops animations for all GIFs on the page with the class 'plugin-icon' or
* plugin icon images in the update plugins table. * plugin icon images in the update plugins table.
* *
* @since 6.4.0 * @since 6.4.0
@ -2156,7 +2156,7 @@ $( function( $ ) {
var width = img.width; var width = img.width;
var height = img.height; var height = img.height;
var canvas = document.createElement( 'canvas' ); var canvas = document.createElement( 'canvas' );
// Set canvas dimensions. // Set canvas dimensions.
canvas.width = width; canvas.width = width;
canvas.height = height; canvas.height = height;
@ -2219,23 +2219,27 @@ $( function( $ ) {
// Listen for jQuery AJAX events. // Listen for jQuery AJAX events.
( function( $ ) { ( function( $ ) {
$( document ).ajaxComplete( function( event, xhr, settings ) { if ( window.pagenow === 'plugin-install' ) {
// Check if this is the 'search-install-plugins' request. // Only listen for ajaxComplete if this is the plugin-install.php page.
if ( settings.data && settings.data.includes( 'action=search-install-plugins' ) ) { $( document ).ajaxComplete( function( event, xhr, settings ) {
// Recheck if the user prefers reduced motion.
if ( window.matchMedia ) { // Check if this is the 'search-install-plugins' request.
var mediaQuery = window.matchMedia( '(prefers-reduced-motion: reduce)' ); if ( settings.data && typeof settings.data === 'string' && settings.data.includes( 'action=search-install-plugins' ) ) {
if ( mediaQuery.matches ) { // Recheck if the user prefers reduced motion.
pub.freezeAll(); if ( window.matchMedia ) {
} var mediaQuery = window.matchMedia( '(prefers-reduced-motion: reduce)' );
} else { if ( mediaQuery.matches ) {
// Fallback for browsers that don't support matchMedia. pub.freezeAll();
if ( true === priv.pauseAll ) { }
pub.freezeAll(); } else {
// Fallback for browsers that don't support matchMedia.
if ( true === priv.pauseAll ) {
pub.freezeAll();
}
} }
} }
} } );
} ); }
} )( jQuery ); } )( jQuery );
// Expose public methods. // Expose public methods.

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.5-alpha-57021'; $wp_version = '6.5-alpha-57022';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.