~canonical-sysadmins/wordpress/4.7.3

« back to all changes in this revision

Viewing changes to wp-admin/js/updates.js

  • Committer: Haw Loeung
  • Date: 2016-12-13 06:56:21 UTC
  • mfrom: (1.1.20 upstream)
  • Revision ID: haw.loeung@canonical.com-20161213065621-8tcu7u7vlxgs2s81
Merge WP4.7 from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
28
30
 */
29
31
(function( $, wp, settings ) {
30
32
        var $document = $( document );
257
259
        };
258
260
 
259
261
        /**
 
262
         * Refreshes update counts everywhere on the screen.
 
263
         *
 
264
         * @since 4.7.0
 
265
         */
 
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' ),
 
271
                        itemCount;
 
272
 
 
273
                $adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
 
274
                $adminBarUpdates.find( '.ab-label' ).text( settings.totals.counts.total );
 
275
 
 
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();
 
279
                }
 
280
 
 
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 );
 
284
                } );
 
285
                if ( settings.totals.counts.total > 0 ) {
 
286
                        $dashboardNavMenuUpdateCount.find( '.update-count' ).text( settings.totals.counts.total );
 
287
                } else {
 
288
                        $dashboardNavMenuUpdateCount.remove();
 
289
                }
 
290
 
 
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 );
 
294
                } );
 
295
                if ( settings.totals.counts.total > 0 ) {
 
296
                        $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( settings.totals.counts.plugins );
 
297
                } else {
 
298
                        $pluginsNavMenuUpdateCount.remove();
 
299
                }
 
300
 
 
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 );
 
304
                } );
 
305
                if ( settings.totals.counts.total > 0 ) {
 
306
                        $appearanceNavMenuUpdateCount.find( '.theme-count' ).text( settings.totals.counts.themes );
 
307
                } else {
 
308
                        $appearanceNavMenuUpdateCount.remove();
 
309
                }
 
310
 
 
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;
 
316
                }
 
317
 
 
318
                if ( itemCount > 0 ) {
 
319
                        $( '.subsubsub .upgrade .count' ).text( '(' + itemCount + ')' );
 
320
                } else {
 
321
                        $( '.subsubsub .upgrade' ).remove();
 
322
                }
 
323
        };
 
324
 
 
325
        /**
260
326
         * Decrements the update counts throughout the various menus.
261
327
         *
262
328
         * This includes the toolbar, the "Updates" menu item and the menu items
268
334
         *                      Can be 'plugin', 'theme'.
269
335
         */
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;
275
 
 
276
 
                count = parseInt( count, 10 ) - 1;
277
 
 
278
 
                if ( count < 0 || isNaN( count ) ) {
279
 
                        return;
280
 
                }
281
 
 
282
 
                $adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
283
 
                $adminBarUpdates.find( '.ab-label' ).text( count );
284
 
 
285
 
                // Remove the update count from the toolbar if it's zero.
286
 
                if ( ! count ) {
287
 
                        $adminBarUpdates.find( '.ab-label' ).parents( 'li' ).remove();
288
 
                }
289
 
 
290
 
                // Update the "Updates" menu item.
291
 
                $dashboardNavMenuUpdateCount.each( function( index, element ) {
292
 
                        element.className = element.className.replace( /count-\d+/, 'count-' + count );
293
 
                } );
294
 
 
295
 
                $dashboardNavMenuUpdateCount.removeAttr( 'title' );
296
 
                $dashboardNavMenuUpdateCount.find( '.update-count' ).text( count );
 
337
                settings.totals.counts.total = Math.max( --settings.totals.counts.total, 0 );
297
338
 
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' );
304
 
                }
305
 
 
306
 
                // Decrement the counter of the other menu items.
307
 
                if ( $itemCount ) {
308
 
                        itemCount = $itemCount.eq( 0 ).text();
309
 
                        itemCount = parseInt( itemCount, 10 ) - 1;
310
 
                }
311
 
 
312
 
                if ( itemCount < 0 || isNaN( itemCount ) ) {
313
 
                        return;
314
 
                }
315
 
 
316
 
                if ( itemCount > 0 ) {
317
 
                        $( '.subsubsub .upgrade .count' ).text( '(' + itemCount + ')' );
318
 
 
319
 
                        $itemCount.text( itemCount );
320
 
                        $menuItem.find( '.update-plugins' ).each( function( index, element ) {
321
 
                                element.className = element.className.replace( /count-\d+/, 'count-' + itemCount );
322
 
                        } );
323
 
                } else {
324
 
                        $( '.subsubsub .upgrade' ).remove();
325
 
                        $menuItem.find( '.update-plugins' ).remove();
326
 
                }
 
342
                        settings.totals.counts.themes = Math.max( --settings.totals.counts.themes, 0 );
 
343
                }
 
344
 
 
345
                wp.updates.refreshCount( type );
327
346
        };
328
347
 
329
348
        /**
1105
1124
                                $message.siblings( '.preview' ).replaceWith( function () {
1106
1125
                                        return $( '<a>' )
1107
1126
                                                .attr( 'href', response.customizeUrl )
1108
 
                                                .addClass( 'button button-secondary load-customize' )
 
1127
                                                .addClass( 'button load-customize' )
1109
1128
                                                .text( wp.updates.l10n.livePreview );
1110
1129
                                } );
1111
1130
                        }
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' );
1222
1241
 
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' );
1657
1676
 
 
1677
                settings = _.extend( settings, window._wpUpdatesItemCounts || {} );
 
1678
 
 
1679
                if ( settings.totals ) {
 
1680
                        wp.updates.refreshCount();
 
1681
                }
 
1682
 
1658
1683
                /*
1659
1684
                 * Whether a user needs to submit filesystem credentials.
1660
1685
                 *
1876
1901
 
1877
1902
                        wp.updates.installPlugin( {
1878
1903
                                slug:    $button.data( 'slug' ),
 
1904
                                pagenow: pagenow,
1879
1905
                                success: wp.updates.installImporterSuccess,
1880
1906
                                error:   wp.updates.installImporterError
1881
1907
                        } );
2185
2211
                 */
2186
2212
                $pluginSearch.on( 'keyup input', _.debounce( function( event ) {
2187
2213
                        var data = {
2188
 
                                _ajax_nonce: wp.updates.ajaxNonce,
2189
 
                                s:           event.target.value,
2190
 
                                pagenow:     pagenow
2191
 
                        };
 
2214
                                _ajax_nonce:   wp.updates.ajaxNonce,
 
2215
                                s:             event.target.value,
 
2216
                                pagenow:       pagenow,
 
2217
                                plugin_status: 'all'
 
2218
                        },
 
2219
                        queryArgs;
2192
2220
 
2193
2221
                        // Clear on escape.
2194
2222
                        if ( 'keyup' === event.type && 27 === event.which ) {
2201
2229
                                wp.updates.searchTerm = data.s;
2202
2230
                        }
2203
2231
 
 
2232
                        queryArgs = _.object( _.compact( _.map( location.search.slice( 1 ).split( '&' ), function( item ) {
 
2233
                                if ( item ) return item.split( '=' );
 
2234
                        } ) ) );
 
2235
 
 
2236
                        data.plugin_status = queryArgs.plugin_status || 'all';
 
2237
 
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 );
2206
2240
                        }
2207
2241
 
2208
2242
                        if ( 'undefined' !== typeof wp.updates.searchRequest ) {
2211
2245
 
2212
2246
                        $bulkActionForm.empty();
2213
2247
                        $( 'body' ).addClass( 'loading-content' );
 
2248
                        $( '.subsubsub .current' ).removeClass( 'current' );
2214
2249
 
2215
2250
                        wp.updates.searchRequest = wp.ajax.post( 'search-plugins', data ).done( function( response ) {
2216
2251
 
2220
2255
 
2221
2256
                                if ( ! data.s.length ) {
2222
2257
                                        $oldSubTitle.remove();
 
2258
                                        $( '.subsubsub .' + data.plugin_status + ' a' ).addClass( 'current' );
2223
2259
                                } else if ( $oldSubTitle.length ) {
2224
2260
                                        $oldSubTitle.replaceWith( $subTitle );
2225
2261
                                } else {
2377
2413
                 */
2378
2414
                $( window ).on( 'beforeunload', wp.updates.beforeunload );
2379
2415
        } );
2380
 
})( jQuery, window.wp, _.extend( window._wpUpdatesSettings, window._wpUpdatesItemCounts || {} ) );
 
2416
})( jQuery, window.wp, window._wpUpdatesSettings );