Index: src/wp-admin/js/updates.js
===================================================================
--- src/wp-admin/js/updates.js (revision 31898)
+++ src/wp-admin/js/updates.js (working copy)
@@ -79,6 +79,15 @@
wp.updates.updateQueue = [];
/**
+ * Store a jQuery reference to return focus to when exiting the request credentials modal.
+ *
+ * @since 4.2.0
+ *
+ * @var jQuery object
+ */
+ wp.updates.$elToReturnFocusToFromCredentialsModal = null;
+
+ /**
* Decrement update counts throughout the various menus.
*
* @since 3.9.0
@@ -144,6 +153,7 @@
}
$message.addClass( 'updating-message' );
+ $message.data( 'originaltext', $message.html() );
$message.text( wp.updates.l10n.updating );
wp.a11y.speak( wp.updates.l10n.updatingMsg );
@@ -247,12 +257,12 @@
* @since 4.2.0
*/
wp.updates.showErrorInCredentialsForm = function( message ) {
- var $notificationDialog = $( '.notification-dialog' );
+ var $modal = $( '.notification-dialog' );
- // Remove any existing error
- $notificationDialog.find( '.error' ).remove();
+ // Remove any existing error.
+ $modal.find( '.error' ).remove();
- $notificationDialog.find( 'h3' ).after( '
' + message + '
' );
+ $modal.find( 'h3' ).after( '
' + message + '
' );
};
/**
@@ -302,18 +312,88 @@
/**
- * Request the users filesystem credentials if we don't have them already
+ * Request the users filesystem credentials if we don't have them already.
*
* @since 4.2.0
*/
- wp.updates.requestFilesystemCredentials = function() {
+ wp.updates.requestFilesystemCredentials = function( event ) {
if ( wp.updates.updateDoneSuccessfully === false ) {
+ /*
+ * For the plugin install screen, return the focus to the install button
+ * after exiting the credentials request modal.
+ */
+ if ( adminpage === 'plugin-install-php' ) {
+ wp.updates.$elToReturnFocusToFromCredentialsModal = $( event.target );
+ }
+
wp.updates.updateLock = true;
- $( 'body' ).addClass( 'modal-open' );
- $( '#request-filesystem-credentials-dialog' ).show();
+
+ wp.updates.requestForCredentialsModalOpen();
}
};
+ /**
+ * Keydown handler for the request for credentials modal.
+ *
+ * Close the modal when the escape key is pressed.
+ * Constrain keyboard navigation to inside the modal.
+ *
+ * @since 4.2.0
+ */
+ wp.updates.keydown = function( event ) {
+ if ( 27 === event.keyCode ) {
+ wp.updates.requestForCredentialsModalCancel();
+ } else if ( 9 === event.keyCode ) {
+ // #upgrade button must always be the last focusable element in the dialog.
+ if ( event.target.id === 'upgrade' && ! event.shiftKey ) {
+ $( '#hostname' ).focus();
+ event.preventDefault();
+ } else if ( event.target.id === 'hostname' && event.shiftKey ) {
+ $( '#upgrade' ).focus();
+ event.preventDefault();
+ }
+ }
+ };
+
+ /**
+ * Open the request for credentials modal.
+ *
+ * @since 4.2.0
+ */
+ wp.updates.requestForCredentialsModalOpen = function() {
+ var $modal = $( '#request-filesystem-credentials-dialog' );
+ $( 'body' ).addClass( 'modal-open' );
+ $modal.show();
+
+ $modal.find( '#hostname' ).focus();
+ $modal.keydown( wp.updates.keydown );
+ };
+
+ /**
+ * Close the request for credentials modal.
+ *
+ * @since 4.2.0
+ */
+ wp.updates.requestForCredentialsModalClose = function() {
+ $( '#request-filesystem-credentials-dialog' ).hide();
+ $( 'body' ).removeClass( 'modal-open' );
+ wp.updates.$elToReturnFocusToFromCredentialsModal.focus();
+ };
+
+ wp.updates.requestForCredentialsModalCancel = function() {
+ var slug = wp.updates.updateQueue[0].data.slug;
+
+ wp.updates.requestForCredentialsModalClose();
+ if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
+ $message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' );
+ } else if ( 'plugin-install' === pagenow ) {
+ $message = $( '.plugin-card-' + slug ).find( '.update-now' );
+ }
+ $message.removeClass( 'updating-message' );
+ $message.html( $message.data( 'originaltext' ) );
+ wp.a11y.speak( wp.updates.l10n.updateCancel );
+ }
+
$( document ).ready( function() {
/*
* Check whether a user needs to submit filesystem credentials based on whether
@@ -333,8 +413,7 @@
wp.updates.filesystemCredentials.ssh.publicKey = $('#public_key').val();
wp.updates.filesystemCredentials.ssh.privateKey = $('#private_key').val();
- $( '#request-filesystem-credentials-dialog' ).hide();
- $( 'body' ).removeClass( 'modal-open' );
+ wp.updates.requestForCredentialsModalClose();
// Unlock and invoke the queue.
wp.updates.updateLock = false;
@@ -343,14 +422,21 @@
return false;
});
+ // Close the request credentials modal when
+ $( '#request-filesystem-credentials-dialog [data-js-action="close"], .notification-dialog-background' ).on( 'click', function() {
+ wp.updates.requestForCredentialsModalCancel();
+ });
+
// Click handler for plugin updates in List Table view.
$( '.plugin-update-tr .update-link' ).on( 'click', function( e ) {
e.preventDefault();
if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.updateLock ) {
- wp.updates.requestFilesystemCredentials();
+ wp.updates.requestFilesystemCredentials( e );
}
- var $row = $( e.target ).parents( '.plugin-update-tr' );
- wp.updates.updatePlugin( $row.data( 'plugin' ), $row.data( 'slug' ) );
+ var updateRow = $( e.target ).parents( '.plugin-update-tr' );
+ // Return the user to the input box of the plugin's table row after closing the modal.
+ wp.updates.$elToReturnFocusToFromCredentialsModal = $( '#' + updateRow.data( 'slug' ) ).find( '.check-column input' );
+ wp.updates.updatePlugin( updateRow.data( 'plugin' ), updateRow.data( 'slug' ) );
} );
$( '#bulk-action-form' ).on( 'submit', function( e ) {
Index: src/wp-includes/script-loader.php
===================================================================
--- src/wp-includes/script-loader.php (revision 31898)
+++ src/wp-includes/script-loader.php (working copy)
@@ -533,6 +533,7 @@
'installingMsg' => __( 'Installing... please wait.' ),
'updatedMsg' => __( 'Update completed successfully.' ),
'installedMsg' => __( 'Installation completed successfully.' ),
+ 'updateCancel' => __( 'Update canceled' ),
)
) );