]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/updates.js
WordPress 4.7.2-scripts
[autoinstalls/wordpress.git] / wp-admin / js / updates.js
index 239829fe3252294c2c0f8b7077d90966f836adf4..7dd58aaee7c49c8f9bec40394589696ae62c04bc 100644 (file)
  * @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.totals                     Plugin/theme status information or null.
- * @param {number}  settings.totals.all                 Amount of all plugins or themes.
- * @param {number}  settings.totals.upgrade             Amount of plugins or themes with updates available.
- * @param {number}  settings.totals.disabled            Amount of disabled themes.
+ * @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.
  */
 (function( $, wp, settings ) {
        var $document = $( document );
        };
 
        /**
-        * Decrements the update counts throughout the various menus.
-        *
-        * This includes the toolbar, the "Updates" menu item and the menu items
-        * for plugins and themes.
+        * Refreshes update counts everywhere on the screen.
         *
-        * @since 3.9.0
-        *
-        * @param {string} type The type of item that was updated or deleted.
-        *                      Can be 'plugin', 'theme'.
+        * @since 4.7.0
         */
-       wp.updates.decrementCount = function( type ) {
-               var $adminBarUpdates             = $( '#wp-admin-bar-updates' ),
-                       $dashboardNavMenuUpdateCount = $( 'a[href="update-core.php"] .update-plugins' ),
-                       count                        = $adminBarUpdates.find( '.ab-label' ).text(),
-                       $menuItem, $itemCount, itemCount;
-
-               count = parseInt( count, 10 ) - 1;
-
-               if ( count < 0 || isNaN( count ) ) {
-                       return;
-               }
+       wp.updates.refreshCount = function() {
+               var $adminBarUpdates              = $( '#wp-admin-bar-updates' ),
+                       $dashboardNavMenuUpdateCount  = $( 'a[href="update-core.php"] .update-plugins' ),
+                       $pluginsNavMenuUpdateCount    = $( 'a[href="plugins.php"] .update-plugins' ),
+                       $appearanceNavMenuUpdateCount = $( 'a[href="themes.php"] .update-plugins' ),
+                       itemCount;
 
                $adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
-               $adminBarUpdates.find( '.ab-label' ).text( count );
+               $adminBarUpdates.find( '.ab-label' ).text( settings.totals.counts.total );
 
                // Remove the update count from the toolbar if it's zero.
-               if ( ! count ) {
+               if ( 0 === settings.totals.counts.total ) {
                        $adminBarUpdates.find( '.ab-label' ).parents( 'li' ).remove();
                }
 
                // Update the "Updates" menu item.
                $dashboardNavMenuUpdateCount.each( function( index, element ) {
-                       element.className = element.className.replace( /count-\d+/, 'count-' + count );
+                       element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.total );
                } );
+               if ( settings.totals.counts.total > 0 ) {
+                       $dashboardNavMenuUpdateCount.find( '.update-count' ).text( settings.totals.counts.total );
+               } else {
+                       $dashboardNavMenuUpdateCount.remove();
+               }
 
-               $dashboardNavMenuUpdateCount.removeAttr( 'title' );
-               $dashboardNavMenuUpdateCount.find( '.update-count' ).text( count );
-
-               if ( 'plugin' === type ) {
-                       $menuItem  = $( '#menu-plugins' );
-                       $itemCount = $menuItem.find( '.plugin-count' );
-               } else if ( 'theme' === type ) {
-                       $menuItem  = $( '#menu-appearance' );
-                       $itemCount = $menuItem.find( '.theme-count' );
+               // Update the "Plugins" menu item.
+               $pluginsNavMenuUpdateCount.each( function( index, element ) {
+                       element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.plugins );
+               } );
+               if ( settings.totals.counts.total > 0 ) {
+                       $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( settings.totals.counts.plugins );
+               } else {
+                       $pluginsNavMenuUpdateCount.remove();
                }
 
-               // Decrement the counter of the other menu items.
-               if ( $itemCount ) {
-                       itemCount = $itemCount.eq( 0 ).text();
-                       itemCount = parseInt( itemCount, 10 ) - 1;
+               // Update the "Appearance" menu item.
+               $appearanceNavMenuUpdateCount.each( function( index, element ) {
+                       element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.themes );
+               } );
+               if ( settings.totals.counts.total > 0 ) {
+                       $appearanceNavMenuUpdateCount.find( '.theme-count' ).text( settings.totals.counts.themes );
+               } else {
+                       $appearanceNavMenuUpdateCount.remove();
                }
 
-               if ( itemCount < 0 || isNaN( itemCount ) ) {
-                       return;
+               // Update list table filter navigation.
+               if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
+                       itemCount = settings.totals.counts.plugins;
+               } else if ( 'themes' === pagenow || 'themes-network' === pagenow ) {
+                       itemCount = settings.totals.counts.themes;
                }
 
                if ( itemCount > 0 ) {
                        $( '.subsubsub .upgrade .count' ).text( '(' + itemCount + ')' );
-
-                       $itemCount.text( itemCount );
-                       $menuItem.find( '.update-plugins' ).each( function( index, element ) {
-                               element.className = element.className.replace( /count-\d+/, 'count-' + itemCount );
-                       } );
                } else {
                        $( '.subsubsub .upgrade' ).remove();
-                       $menuItem.find( '.update-plugins' ).remove();
                }
        };
 
+       /**
+        * Decrements the update counts throughout the various menus.
+        *
+        * This includes the toolbar, the "Updates" menu item and the menu items
+        * for plugins and themes.
+        *
+        * @since 3.9.0
+        *
+        * @param {string} type The type of item that was updated or deleted.
+        *                      Can be 'plugin', 'theme'.
+        */
+       wp.updates.decrementCount = function( type ) {
+               settings.totals.counts.total = Math.max( --settings.totals.counts.total, 0 );
+
+               if ( 'plugin' === type ) {
+                       settings.totals.counts.plugins = Math.max( --settings.totals.counts.plugins, 0 );
+               } else if ( 'theme' === type ) {
+                       settings.totals.counts.themes = Math.max( --settings.totals.counts.themes, 0 );
+               }
+
+               wp.updates.refreshCount( type );
+       };
+
        /**
         * Sends an Ajax request to the server to update a plugin.
         *
                                $message.siblings( '.preview' ).replaceWith( function () {
                                        return $( '<a>' )
                                                .attr( 'href', response.customizeUrl )
-                                               .addClass( 'button button-secondary load-customize' )
+                                               .addClass( 'button load-customize' )
                                                .text( wp.updates.l10n.livePreview );
                                } );
                        }
                        $themeRows.css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() {
                                var $views     = $( '.subsubsub' ),
                                        $themeRow  = $( this ),
-                                       totals     = settings.totals,
+                                       totals     = settings.themes,
                                        deletedRow = wp.template( 'item-deleted-row' );
 
                                if ( ! $themeRow.hasClass( 'plugin-update-tr' ) ) {
         * @param {string} message Error message.
         */
        wp.updates.showErrorInCredentialsForm = function( message ) {
-               var $modal = $( '#request-filesystem-credentials-form' );
+               var $filesystemForm = $( '#request-filesystem-credentials-form' );
 
                // Remove any existing error.
-               $modal.find( '.notice' ).remove();
-               $modal.find( '#request-filesystem-credentials-title' ).after( '<div class="notice notice-alt notice-error"><p>' + message + '</p></div>' );
+               $filesystemForm.find( '.notice' ).remove();
+               $filesystemForm.find( '#request-filesystem-credentials-title' ).after( '<div class="notice notice-alt notice-error"><p>' + message + '</p></div>' );
        };
 
        /**
        $( function() {
                var $pluginFilter        = $( '#plugin-filter' ),
                        $bulkActionForm      = $( '#bulk-action-form' ),
+                       $filesystemForm      = $( '#request-filesystem-credentials-form' ),
                        $filesystemModal     = $( '#request-filesystem-credentials-dialog' ),
                        $pluginSearch        = $( '.plugins-php .wp-filter-search' ),
                        $pluginInstallSearch = $( '.plugin-install-php .wp-filter-search' );
 
+               settings = _.extend( settings, window._wpUpdatesItemCounts || {} );
+
+               if ( settings.totals ) {
+                       wp.updates.refreshCount();
+               }
+
                /*
                 * Whether a user needs to submit filesystem credentials.
                 *
                 *
                 * @since 4.2.0
                 */
-               $filesystemModal.on( 'change', 'input[name="connection_type"]', function() {
+               $filesystemForm.on( 'change', 'input[name="connection_type"]', function() {
                        $( '#ssh-keys' ).toggleClass( 'hidden', ( 'ssh' !== $( this ).val() ) );
                } ).change();
 
 
                        wp.updates.installPlugin( {
                                slug:    $button.data( 'slug' ),
+                               pagenow: pagenow,
                                success: wp.updates.installImporterSuccess,
                                error:   wp.updates.installImporterError
                        } );
                 */
                $pluginSearch.on( 'keyup input', _.debounce( function( event ) {
                        var data = {
-                               _ajax_nonce: wp.updates.ajaxNonce,
-                               s:           event.target.value,
-                               pagenow:     pagenow
-                       };
+                               _ajax_nonce:   wp.updates.ajaxNonce,
+                               s:             event.target.value,
+                               pagenow:       pagenow,
+                               plugin_status: 'all'
+                       },
+                       queryArgs;
 
                        // Clear on escape.
                        if ( 'keyup' === event.type && 27 === event.which ) {
                                wp.updates.searchTerm = data.s;
                        }
 
+                       queryArgs = _.object( _.compact( _.map( location.search.slice( 1 ).split( '&' ), function( item ) {
+                               if ( item ) return item.split( '=' );
+                       } ) ) );
+
+                       data.plugin_status = queryArgs.plugin_status || 'all';
+
                        if ( window.history && window.history.replaceState ) {
-                               window.history.replaceState( null, '', location.href.split( '?' )[ 0 ] + '?s=' + data.s );
+                               window.history.replaceState( null, '', location.href.split( '?' )[ 0 ] + '?s=' + data.s + '&plugin_status=' + data.plugin_status );
                        }
 
                        if ( 'undefined' !== typeof wp.updates.searchRequest ) {
 
                        $bulkActionForm.empty();
                        $( 'body' ).addClass( 'loading-content' );
+                       $( '.subsubsub .current' ).removeClass( 'current' );
 
                        wp.updates.searchRequest = wp.ajax.post( 'search-plugins', data ).done( function( response ) {
 
 
                                if ( ! data.s.length ) {
                                        $oldSubTitle.remove();
+                                       $( '.subsubsub .' + data.plugin_status + ' a' ).addClass( 'current' );
                                } else if ( $oldSubTitle.length ) {
                                        $oldSubTitle.replaceWith( $subTitle );
                                } else {
                 */
                $( window ).on( 'beforeunload', wp.updates.beforeunload );
        } );
-})( jQuery, window.wp, _.extend( window._wpUpdatesSettings, window._wpUpdatesItemCounts || {} ) );
+})( jQuery, window.wp, window._wpUpdatesSettings );