Upgrade/Install: Refresh update counts after page load.
By enqueuing the updates script in the footer and passing the number of available updates to it after page load, the update bubbles will be more accurate. Props ocean90, swissspidy. Fixes #13071. Built from https://develop.svn.wordpress.org/trunk@38827 git-svn-id: http://core.svn.wordpress.org/trunk@38770 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -21,10 +21,12 @@
|
||||
* @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 );
|
||||
@@ -260,6 +262,70 @@
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Refreshes update counts everywhere on the screen.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*/
|
||||
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( settings.totals.counts.total );
|
||||
|
||||
// Remove the update count from the toolbar if it's zero.
|
||||
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-' + settings.totals.counts.total );
|
||||
} );
|
||||
if ( settings.totals.counts.total > 0 ) {
|
||||
$dashboardNavMenuUpdateCount.find( '.update-count' ).text( settings.totals.counts.total );
|
||||
} else {
|
||||
$dashboardNavMenuUpdateCount.remove();
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
// 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 + ')' );
|
||||
} else {
|
||||
$( '.subsubsub .upgrade' ).remove();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Decrements the update counts throughout the various menus.
|
||||
*
|
||||
@@ -272,62 +338,15 @@
|
||||
* Can be 'plugin', 'theme'.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
$adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
|
||||
$adminBarUpdates.find( '.ab-label' ).text( count );
|
||||
|
||||
// Remove the update count from the toolbar if it's zero.
|
||||
if ( ! count ) {
|
||||
$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 );
|
||||
} );
|
||||
|
||||
$dashboardNavMenuUpdateCount.removeAttr( 'title' );
|
||||
$dashboardNavMenuUpdateCount.find( '.update-count' ).text( count );
|
||||
settings.totals.counts.total = Math.max( --settings.totals.counts.total, 0 );
|
||||
|
||||
if ( 'plugin' === type ) {
|
||||
$menuItem = $( '#menu-plugins' );
|
||||
$itemCount = $menuItem.find( '.plugin-count' );
|
||||
settings.totals.counts.plugins = Math.max( --settings.totals.counts.plugins, 0 );
|
||||
} else if ( 'theme' === type ) {
|
||||
$menuItem = $( '#menu-appearance' );
|
||||
$itemCount = $menuItem.find( '.theme-count' );
|
||||
settings.totals.counts.themes = Math.max( --settings.totals.counts.themes, 0 );
|
||||
}
|
||||
|
||||
// Decrement the counter of the other menu items.
|
||||
if ( $itemCount ) {
|
||||
itemCount = $itemCount.eq( 0 ).text();
|
||||
itemCount = parseInt( itemCount, 10 ) - 1;
|
||||
}
|
||||
|
||||
if ( itemCount < 0 || isNaN( itemCount ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
wp.updates.refreshCount( type );
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1251,7 +1270,7 @@
|
||||
$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' ) ) {
|
||||
@@ -1689,6 +1708,12 @@
|
||||
$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.
|
||||
*
|
||||
@@ -2412,4 +2437,4 @@
|
||||
*/
|
||||
$( window ).on( 'beforeunload', wp.updates.beforeunload );
|
||||
} );
|
||||
})( jQuery, window.wp, _.extend( window._wpUpdatesSettings, window._wpUpdatesItemCounts || {} ) );
|
||||
})( jQuery, window.wp, window._wpUpdatesSettings );
|
||||
|
||||
4
wp-admin/js/updates.min.js
vendored
4
wp-admin/js/updates.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user