]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/updates.js
WordPress 4.4
[autoinstalls/wordpress.git] / wp-admin / js / updates.js
index 2ddfc85dabe7c96c38243e499f97ce2d60a314b1..3f1dba71e3aad2751aa5e7948a73981e631c1ad2 100644 (file)
@@ -93,7 +93,7 @@ window.wp = window.wp || {};
         *
         * @since 3.9.0
         *
-        * @param {string} updateType
+        * @param {string} upgradeType
         */
        wp.updates.decrementCount = function( upgradeType ) {
                var count,
@@ -146,13 +146,17 @@ window.wp = window.wp || {};
         * @param {string} slug
         */
        wp.updates.updatePlugin = function( plugin, slug ) {
-               var $message, name;
+               var $message, name,
+                       $card = $( '.plugin-card-' + slug );
+
                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 = $card.find( '.update-now' );
                        name = $message.data( 'name' );
                        $message.attr( 'aria-label', wp.updates.l10n.updatingLabel.replace( '%s', name ) );
+                       // Remove previous error messages, if any.
+                       $card.removeClass( 'plugin-card-update-failed' ).find( '.notice.notice-error' ).remove();
                }
 
                $message.addClass( 'updating-message' );
@@ -248,23 +252,47 @@ window.wp = window.wp || {};
         * @param {object} response
         */
        wp.updates.updateError = function( response ) {
-               var $message, name;
+               var $card = $( '.plugin-card-' + response.slug ),
+                       $message,
+                       $button,
+                       name,
+                       error_message;
+
                wp.updates.updateDoneSuccessfully = false;
+
                if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' && wp.updates.shouldRequestFilesystemCredentials ) {
                        wp.updates.credentialError( response, 'update-plugin' );
                        return;
                }
+
+               error_message = wp.updates.l10n.updateFailed.replace( '%s', response.error );
+
                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
                        $message = $( '[data-slug="' + response.slug + '"]' ).next().find( '.update-message' );
+                       $message.html( error_message ).removeClass( 'updating-message' );
                } else if ( 'plugin-install' === pagenow ) {
-                       $message = $( '.plugin-card-' + response.slug ).find( '.update-now' );
-
-                       name = $message.data( 'name' );
-                       $message.attr( 'aria-label', wp.updates.l10n.updateFailedLabel.replace( '%s', name ) );
+                       $button = $card.find( '.update-now' );
+                       name = $button.data( 'name' );
+
+                       $card
+                               .addClass( 'plugin-card-update-failed' )
+                               .append( '<div class="notice notice-error is-dismissible"><p>' + error_message + '</p></div>' );
+
+                       $button
+                               .attr( 'aria-label', wp.updates.l10n.updateFailedLabel.replace( '%s', name ) )
+                               .html( wp.updates.l10n.updateFailedShort ).removeClass( 'updating-message' );
+
+                       $card.on( 'click', '.notice.is-dismissible .notice-dismiss', function() {
+                               // Use same delay as the total duration of the notice fadeTo + slideUp animation.
+                               setTimeout( function() {
+                                       $card
+                                               .removeClass( 'plugin-card-update-failed' )
+                                               .find( '.column-name a' ).focus();
+                               }, 200 );
+                       });
                }
-               $message.removeClass( 'updating-message' );
-               $message.html( wp.updates.l10n.updateFailed + ': ' + response.error );
-               wp.a11y.speak( wp.updates.l10n.updateFailed );
+
+               wp.a11y.speak( error_message, 'assertive' );
 
                /*
                 * The lock can be released since this failure was
@@ -552,7 +580,7 @@ window.wp = window.wp || {};
                                        // trigger the update
                                        $( '.plugin-update-tr[data-slug="' + message.slug + '"]' ).find( '.update-link' ).trigger( 'click' );
                                } else if ( 'plugin-install' === pagenow ) {
-                                       $( '.plugin-card-' + message.slug ).find( 'h4 a' ).focus();
+                                       $( '.plugin-card-' + message.slug ).find( '.column-name a' ).focus();
                                        $( '.plugin-card-' + message.slug ).find( '[data-slug="' + message.slug + '"]' ).trigger( 'click' );
                                }
                                break;