21
21
* @param {Array} settings.plugins.inactive Base names of inactive plugins.
22
22
* @param {Array} settings.plugins.upgrade Base names of plugins with updates available.
23
23
* @param {Array} settings.plugins.recently_activated Base names of recently activated plugins.
24
* @param {object=} settings.totals Plugin/theme status information or null.
25
* @param {number} settings.totals.all Amount of all plugins or themes.
26
* @param {number} settings.totals.upgrade Amount of plugins or themes with updates available.
27
* @param {number} settings.totals.disabled Amount of disabled themes.
24
* @param {object=} settings.themes Plugin/theme status information or null.
25
* @param {number} settings.themes.all Amount of all themes.
26
* @param {number} settings.themes.upgrade Amount of themes with updates available.
27
* @param {number} settings.themes.disabled Amount of disabled themes.
28
* @param {object=} settings.totals Combined information for available update counts.
29
* @param {number} settings.totals.count Holds the amount of available updates.
29
31
(function( $, wp, settings ) {
30
32
var $document = $( document );
262
* Refreshes update counts everywhere on the screen.
266
wp.updates.refreshCount = function() {
267
var $adminBarUpdates = $( '#wp-admin-bar-updates' ),
268
$dashboardNavMenuUpdateCount = $( 'a[href="update-core.php"] .update-plugins' ),
269
$pluginsNavMenuUpdateCount = $( 'a[href="plugins.php"] .update-plugins' ),
270
$appearanceNavMenuUpdateCount = $( 'a[href="themes.php"] .update-plugins' ),
273
$adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
274
$adminBarUpdates.find( '.ab-label' ).text( settings.totals.counts.total );
276
// Remove the update count from the toolbar if it's zero.
277
if ( 0 === settings.totals.counts.total ) {
278
$adminBarUpdates.find( '.ab-label' ).parents( 'li' ).remove();
281
// Update the "Updates" menu item.
282
$dashboardNavMenuUpdateCount.each( function( index, element ) {
283
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.total );
285
if ( settings.totals.counts.total > 0 ) {
286
$dashboardNavMenuUpdateCount.find( '.update-count' ).text( settings.totals.counts.total );
288
$dashboardNavMenuUpdateCount.remove();
291
// Update the "Plugins" menu item.
292
$pluginsNavMenuUpdateCount.each( function( index, element ) {
293
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.plugins );
295
if ( settings.totals.counts.total > 0 ) {
296
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( settings.totals.counts.plugins );
298
$pluginsNavMenuUpdateCount.remove();
301
// Update the "Appearance" menu item.
302
$appearanceNavMenuUpdateCount.each( function( index, element ) {
303
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.themes );
305
if ( settings.totals.counts.total > 0 ) {
306
$appearanceNavMenuUpdateCount.find( '.theme-count' ).text( settings.totals.counts.themes );
308
$appearanceNavMenuUpdateCount.remove();
311
// Update list table filter navigation.
312
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
313
itemCount = settings.totals.counts.plugins;
314
} else if ( 'themes' === pagenow || 'themes-network' === pagenow ) {
315
itemCount = settings.totals.counts.themes;
318
if ( itemCount > 0 ) {
319
$( '.subsubsub .upgrade .count' ).text( '(' + itemCount + ')' );
321
$( '.subsubsub .upgrade' ).remove();
260
326
* Decrements the update counts throughout the various menus.
262
328
* This includes the toolbar, the "Updates" menu item and the menu items
268
334
* Can be 'plugin', 'theme'.
270
336
wp.updates.decrementCount = function( type ) {
271
var $adminBarUpdates = $( '#wp-admin-bar-updates' ),
272
$dashboardNavMenuUpdateCount = $( 'a[href="update-core.php"] .update-plugins' ),
273
count = $adminBarUpdates.find( '.ab-label' ).text(),
274
$menuItem, $itemCount, itemCount;
276
count = parseInt( count, 10 ) - 1;
278
if ( count < 0 || isNaN( count ) ) {
282
$adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
283
$adminBarUpdates.find( '.ab-label' ).text( count );
285
// Remove the update count from the toolbar if it's zero.
287
$adminBarUpdates.find( '.ab-label' ).parents( 'li' ).remove();
290
// Update the "Updates" menu item.
291
$dashboardNavMenuUpdateCount.each( function( index, element ) {
292
element.className = element.className.replace( /count-\d+/, 'count-' + count );
295
$dashboardNavMenuUpdateCount.removeAttr( 'title' );
296
$dashboardNavMenuUpdateCount.find( '.update-count' ).text( count );
337
settings.totals.counts.total = Math.max( --settings.totals.counts.total, 0 );
298
339
if ( 'plugin' === type ) {
299
$menuItem = $( '#menu-plugins' );
300
$itemCount = $menuItem.find( '.plugin-count' );
340
settings.totals.counts.plugins = Math.max( --settings.totals.counts.plugins, 0 );
301
341
} else if ( 'theme' === type ) {
302
$menuItem = $( '#menu-appearance' );
303
$itemCount = $menuItem.find( '.theme-count' );
306
// Decrement the counter of the other menu items.
308
itemCount = $itemCount.eq( 0 ).text();
309
itemCount = parseInt( itemCount, 10 ) - 1;
312
if ( itemCount < 0 || isNaN( itemCount ) ) {
316
if ( itemCount > 0 ) {
317
$( '.subsubsub .upgrade .count' ).text( '(' + itemCount + ')' );
319
$itemCount.text( itemCount );
320
$menuItem.find( '.update-plugins' ).each( function( index, element ) {
321
element.className = element.className.replace( /count-\d+/, 'count-' + itemCount );
324
$( '.subsubsub .upgrade' ).remove();
325
$menuItem.find( '.update-plugins' ).remove();
342
settings.totals.counts.themes = Math.max( --settings.totals.counts.themes, 0 );
345
wp.updates.refreshCount( type );
1217
1236
$themeRows.css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() {
1218
1237
var $views = $( '.subsubsub' ),
1219
1238
$themeRow = $( this ),
1220
totals = settings.totals,
1239
totals = settings.themes,
1221
1240
deletedRow = wp.template( 'item-deleted-row' );
1223
1242
if ( ! $themeRow.hasClass( 'plugin-update-tr' ) ) {
1655
1674
$pluginSearch = $( '.plugins-php .wp-filter-search' ),
1656
1675
$pluginInstallSearch = $( '.plugin-install-php .wp-filter-search' );
1677
settings = _.extend( settings, window._wpUpdatesItemCounts || {} );
1679
if ( settings.totals ) {
1680
wp.updates.refreshCount();
1659
1684
* Whether a user needs to submit filesystem credentials.
2201
2229
wp.updates.searchTerm = data.s;
2232
queryArgs = _.object( _.compact( _.map( location.search.slice( 1 ).split( '&' ), function( item ) {
2233
if ( item ) return item.split( '=' );
2236
data.plugin_status = queryArgs.plugin_status || 'all';
2204
2238
if ( window.history && window.history.replaceState ) {
2205
window.history.replaceState( null, '', location.href.split( '?' )[ 0 ] + '?s=' + data.s );
2239
window.history.replaceState( null, '', location.href.split( '?' )[ 0 ] + '?s=' + data.s + '&plugin_status=' + data.plugin_status );
2208
2242
if ( 'undefined' !== typeof wp.updates.searchRequest ) {
2378
2414
$( window ).on( 'beforeunload', wp.updates.beforeunload );
2380
})( jQuery, window.wp, _.extend( window._wpUpdatesSettings, window._wpUpdatesItemCounts || {} ) );
2416
})( jQuery, window.wp, window._wpUpdatesSettings );