Make WordPress Core

Changeset 57022 for trunk


Ignore:
Timestamp:
10/27/2023 07:23:07 PM (7 months ago)
Author:
joedolson
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/common.js

    r56810 r57022  
    21302130 * Freeze animated plugin icons when reduced motion is enabled.
    21312131 *
    2132  * When the user has enabled the 'prefers-reduced-motion' setting, this module 
    2133  * stops animations for all GIFs on the page with the class 'plugin-icon' or 
     2132 * When the user has enabled the 'prefers-reduced-motion' setting, this module
     2133 * stops animations for all GIFs on the page with the class 'plugin-icon' or
    21342134 * plugin icon images in the update plugins table.
    21352135 *
     
    21572157            var height = img.height;
    21582158            var canvas = document.createElement( 'canvas' );
    2159            
     2159
    21602160            // Set canvas dimensions.
    21612161            canvas.width = width;
     
    22202220    // Listen for jQuery AJAX events.
    22212221    ( function( $ ) {
    2222         $( document ).ajaxComplete( function( event, xhr, settings ) {
    2223             // Check if this is the 'search-install-plugins' request.
    2224             if ( settings.data && settings.data.includes( 'action=search-install-plugins' ) ) {
    2225                 // Recheck if the user prefers reduced motion.
    2226                 if ( window.matchMedia ) {
    2227                     var mediaQuery = window.matchMedia( '(prefers-reduced-motion: reduce)' );
    2228                     if ( mediaQuery.matches ) {
    2229                         pub.freezeAll();
    2230                     }
    2231                 } else {
    2232                     // Fallback for browsers that don't support matchMedia.
    2233                     if ( true === priv.pauseAll ) {
    2234                         pub.freezeAll();
     2222        if ( window.pagenow === 'plugin-install' ) {
     2223            // Only listen for ajaxComplete if this is the plugin-install.php page.
     2224            $( document ).ajaxComplete( function( event, xhr, settings ) {
     2225
     2226                // Check if this is the 'search-install-plugins' request.
     2227                if ( settings.data && typeof settings.data === 'string' && settings.data.includes( 'action=search-install-plugins' ) ) {
     2228                    // Recheck if the user prefers reduced motion.
     2229                    if ( window.matchMedia ) {
     2230                        var mediaQuery = window.matchMedia( '(prefers-reduced-motion: reduce)' );
     2231                        if ( mediaQuery.matches ) {
     2232                            pub.freezeAll();
     2233                        }
     2234                    } else {
     2235                        // Fallback for browsers that don't support matchMedia.
     2236                        if ( true === priv.pauseAll ) {
     2237                            pub.freezeAll();
     2238                        }
    22352239                    }
    22362240                }
    2237             }
    2238         } );
     2241            } );
     2242        }
    22392243    } )( jQuery );
    22402244
Note: See TracChangeset for help on using the changeset viewer.