diff -r 34716fd837a4 -r be944660c56a wp/wp-admin/js/updates.js --- a/wp/wp-admin/js/updates.js Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-admin/js/updates.js Wed Sep 21 18:19:35 2022 +0200 @@ -8,22 +8,26 @@ /* global pagenow */ /** - * @param {jQuery} $ jQuery object. - * @param {object} wp WP object. - * @param {object} settings WP Updates settings. - * @param {string} settings.ajax_nonce Ajax nonce. - * @param {object=} settings.plugins Base names of plugins in their different states. - * @param {Array} settings.plugins.all Base names of all plugins. - * @param {Array} settings.plugins.active Base names of active plugins. - * @param {Array} settings.plugins.inactive Base names of inactive plugins. - * @param {Array} settings.plugins.upgrade Base names of plugins with updates available. - * @param {Array} settings.plugins.recently_activated Base names of recently activated plugins. - * @param {object=} settings.themes Plugin/theme status information or null. - * @param {number} settings.themes.all Amount of all themes. - * @param {number} settings.themes.upgrade Amount of themes with updates available. - * @param {number} settings.themes.disabled Amount of disabled themes. - * @param {object=} settings.totals Combined information for available update counts. - * @param {number} settings.totals.count Holds the amount of available updates. + * @param {jQuery} $ jQuery object. + * @param {object} wp WP object. + * @param {object} settings WP Updates settings. + * @param {string} settings.ajax_nonce Ajax nonce. + * @param {object=} settings.plugins Base names of plugins in their different states. + * @param {Array} settings.plugins.all Base names of all plugins. + * @param {Array} settings.plugins.active Base names of active plugins. + * @param {Array} settings.plugins.inactive Base names of inactive plugins. + * @param {Array} settings.plugins.upgrade Base names of plugins with updates available. + * @param {Array} settings.plugins.recently_activated Base names of recently activated plugins. + * @param {Array} settings.plugins['auto-update-enabled'] Base names of plugins set to auto-update. + * @param {Array} settings.plugins['auto-update-disabled'] Base names of plugins set to not auto-update. + * @param {object=} settings.themes Slugs of themes in their different states. + * @param {Array} settings.themes.all Slugs of all themes. + * @param {Array} settings.themes.upgrade Slugs of themes with updates available. + * @param {Arrat} settings.themes.disabled Slugs of disabled themes. + * @param {Array} settings.themes['auto-update-enabled'] Slugs of themes set to auto-update. + * @param {Array} settings.themes['auto-update-disabled'] Slugs of themes set to not auto-update. + * @param {object=} settings.totals Combined information for available update counts. + * @param {number} settings.totals.count Holds the amount of available updates. */ (function( $, wp, settings ) { var $document = $( document ), @@ -115,7 +119,7 @@ autoUpdatesError: '' }; - wp.updates.l10n = window.wp.deprecateL10nObject( 'wp.updates.l10n', wp.updates.l10n ); + wp.updates.l10n = window.wp.deprecateL10nObject( 'wp.updates.l10n', wp.updates.l10n, '5.5.0' ); /** * User nonce for ajax calls. @@ -439,7 +443,8 @@ * decorated with an abort() method. */ wp.updates.updatePlugin = function( args ) { - var $updateRow, $card, $message, message; + var $updateRow, $card, $message, message, + $adminBarUpdates = $( '#wp-admin-bar-updates' ); args = _.extend( { success: wp.updates.updatePluginSuccess, @@ -467,6 +472,8 @@ $card.removeClass( 'plugin-card-update-failed' ).find( '.notice.notice-error' ).remove(); } + $adminBarUpdates.addClass( 'spin' ); + if ( $message.html() !== __( 'Updating...' ) ) { $message.data( 'originaltext', $message.html() ); } @@ -495,7 +502,8 @@ * @param {string} response.newVersion New version of the plugin. */ wp.updates.updatePluginSuccess = function( response ) { - var $pluginRow, $updateMessage, newText; + var $pluginRow, $updateMessage, newText, + $adminBarUpdates = $( '#wp-admin-bar-updates' ); if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { $pluginRow = $( 'tr[data-plugin="' + response.plugin + '"]' ) @@ -517,6 +525,8 @@ .addClass( 'button-disabled updated-message' ); } + $adminBarUpdates.removeClass( 'spin' ); + $updateMessage .attr( 'aria-label', @@ -549,7 +559,8 @@ * @param {string} response.errorMessage The error that occurred. */ wp.updates.updatePluginError = function( response ) { - var $card, $message, errorMessage; + var $card, $message, errorMessage, + $adminBarUpdates = $( '#wp-admin-bar-updates' ); if ( ! wp.updates.isValidResponse( response, 'update' ) ) { return; @@ -618,7 +629,7 @@ setTimeout( function() { $card .removeClass( 'plugin-card-update-failed' ) - .find( '.column-name a' ).focus(); + .find( '.column-name a' ).trigger( 'focus' ); $card.find( '.update-now' ) .attr( 'aria-label', false ) @@ -627,6 +638,8 @@ } ); } + $adminBarUpdates.removeClass( 'spin' ); + wp.a11y.speak( errorMessage, 'assertive' ); $document.trigger( 'wp-plugin-update-error', response ); @@ -788,7 +801,7 @@ setTimeout( function() { $card .removeClass( 'plugin-card-update-failed' ) - .find( '.column-name a' ).focus(); + .find( '.column-name a' ).trigger( 'focus' ); }, 200 ); } ); @@ -1007,6 +1020,24 @@ } } + if ( -1 !== _.indexOf( plugins['auto-update-enabled'], response.plugin ) ) { + plugins['auto-update-enabled'] = _.without( plugins['auto-update-enabled'], response.plugin ); + if ( plugins['auto-update-enabled'].length ) { + $views.find( '.auto-update-enabled .count' ).text( '(' + plugins['auto-update-enabled'].length + ')' ); + } else { + $views.find( '.auto-update-enabled' ).remove(); + } + } + + if ( -1 !== _.indexOf( plugins['auto-update-disabled'], response.plugin ) ) { + plugins['auto-update-disabled'] = _.without( plugins['auto-update-disabled'], response.plugin ); + if ( plugins['auto-update-disabled'].length ) { + $views.find( '.auto-update-disabled .count' ).text( '(' + plugins['auto-update-disabled'].length + ')' ); + } else { + $views.find( '.auto-update-disabled' ).remove(); + } + } + plugins.all = _.without( plugins.all, response.plugin ); if ( plugins.all.length ) { @@ -1184,10 +1215,10 @@ // Focus on Customize button after updating. if ( isModalOpen ) { - $( '.load-customize:visible' ).focus(); + $( '.load-customize:visible' ).trigger( 'focus' ); $( '.theme-info .theme-autoupdate' ).find( '.auto-update-time' ).empty(); } else { - $theme.find( '.load-customize' ).focus(); + $theme.find( '.load-customize' ).trigger( 'focus' ); } } @@ -1240,7 +1271,7 @@ } else { $notice = $( '.theme-info .notice' ).add( $theme.find( '.notice' ) ); - $( 'body.modal-open' ).length ? $( '.load-customize:visible' ).focus() : $theme.find( '.load-customize' ).focus(); + $( 'body.modal-open' ).length ? $( '.load-customize:visible' ).trigger( 'focus' ) : $theme.find( '.load-customize' ).trigger( 'focus'); } wp.updates.addAdminNotice( { @@ -1505,7 +1536,7 @@ $themeRows.css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() { var $views = $( '.subsubsub' ), $themeRow = $( this ), - totals = settings.themes, + themes = settings.themes, deletedRow = wp.template( 'item-deleted-row' ); if ( ! $themeRow.hasClass( 'plugin-update-tr' ) ) { @@ -1521,23 +1552,43 @@ $themeRow.remove(); // Remove theme from update count. - if ( $themeRow.hasClass( 'update' ) ) { - totals.upgrade--; + if ( -1 !== _.indexOf( themes.upgrade, response.slug ) ) { + themes.upgrade = _.without( themes.upgrade, response.slug ); wp.updates.decrementCount( 'theme' ); } // Remove from views. - if ( $themeRow.hasClass( 'inactive' ) ) { - totals.disabled--; - if ( totals.disabled ) { - $views.find( '.disabled .count' ).text( '(' + totals.disabled + ')' ); + if ( -1 !== _.indexOf( themes.disabled, response.slug ) ) { + themes.disabled = _.without( themes.disabled, response.slug ); + if ( themes.disabled.length ) { + $views.find( '.disabled .count' ).text( '(' + themes.disabled.length + ')' ); } else { $views.find( '.disabled' ).remove(); } } + if ( -1 !== _.indexOf( themes['auto-update-enabled'], response.slug ) ) { + themes['auto-update-enabled'] = _.without( themes['auto-update-enabled'], response.slug ); + if ( themes['auto-update-enabled'].length ) { + $views.find( '.auto-update-enabled .count' ).text( '(' + themes['auto-update-enabled'].length + ')' ); + } else { + $views.find( '.auto-update-enabled' ).remove(); + } + } + + if ( -1 !== _.indexOf( themes['auto-update-disabled'], response.slug ) ) { + themes['auto-update-disabled'] = _.without( themes['auto-update-disabled'], response.slug ); + if ( themes['auto-update-disabled'].length ) { + $views.find( '.auto-update-disabled .count' ).text( '(' + themes['auto-update-disabled'].length + ')' ); + } else { + $views.find( '.auto-update-disabled' ).remove(); + } + } + + themes.all = _.without( themes.all, response.slug ); + // There is always at least one theme available. - $views.find( '.all .count' ).text( '(' + --totals.all + ')' ); + $views.find( '.all .count' ).text( '(' + themes.all.length + ')' ); } ); } @@ -1717,11 +1768,11 @@ // #upgrade button must always be the last focus-able element in the dialog. if ( 'upgrade' === event.target.id && ! event.shiftKey ) { - $( '#hostname' ).focus(); + $( '#hostname' ).trigger( 'focus' ); event.preventDefault(); } else if ( 'hostname' === event.target.id && event.shiftKey ) { - $( '#upgrade' ).focus(); + $( '#upgrade' ).trigger( 'focus' ); event.preventDefault(); } @@ -1738,7 +1789,7 @@ $( 'body' ).addClass( 'modal-open' ); $modal.show(); - $modal.find( 'input:enabled:first' ).focus(); + $modal.find( 'input:enabled:first' ).trigger( 'focus' ); $modal.on( 'keydown', wp.updates.keydown ); }; @@ -1752,7 +1803,7 @@ $( 'body' ).removeClass( 'modal-open' ); if ( wp.updates.$elToReturnFocusToFromCredentialsModal ) { - wp.updates.$elToReturnFocusToFromCredentialsModal.focus(); + wp.updates.$elToReturnFocusToFromCredentialsModal.trigger( 'focus' ); } }; @@ -2003,7 +2054,7 @@ */ $filesystemForm.on( 'change', 'input[name="connection_type"]', function() { $( '#ssh-keys' ).toggleClass( 'hidden', ( 'ssh' !== $( this ).val() ) ); - } ).change(); + } ).trigger( 'change' ); /** * Handles events after the credential modal was closed. @@ -2580,8 +2631,8 @@ var $subTitle = $( '' ).addClass( 'subtitle' ).html( sprintf( /* translators: %s: Search query. */ - __( 'Search results for “%s”' ), - _.escape( data.s ) + __( 'Search results for: %s' ), + '' + _.escape( data.s ) + '' ) ), $oldSubTitle = $( '.wrap .subtitle' ); @@ -2723,7 +2774,7 @@ } try { - message = $.parseJSON( originalEvent.data ); + message = JSON.parse( originalEvent.data ); } catch ( e ) { return; }