Make WordPress Core

Ticket #42406: 42406.5.diff

File 42406.5.diff, 5.3 KB (added by westonruter, 7 years ago)
  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 7fb87bc88e..fbb8f42959 100644
     
    25492549                 * @returns {void}
    25502550                 */
    25512551                showDetails: function ( theme, callback ) {
    2552                         var section = this;
     2552                        var section = this, panel = api.panel( 'themes' );
    25532553                        section.currentTheme = theme.id;
    25542554                        section.overlay.html( section.template( theme ) )
    25552555                                .fadeIn( 'fast' )
    25562556                                .focus();
     2557
     2558                        function disableSwitchButtons() {
     2559                                return ! panel.canSwitchTheme( theme.id );
     2560                        }
     2561
     2562                        // Temporary special function since supplying SFTP credentials does not work yet. See #42184.
     2563                        function disableInstallButtons() {
     2564                                return disableSwitchButtons() || true === api.settings.theme._filesystemCredentialsNeeded;
     2565                        }
     2566
     2567                        section.overlay.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() );
     2568                        section.overlay.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() );
     2569
    25572570                        section.$body.addClass( 'modal-open' );
    25582571                        section.containFocus( section.overlay );
    25592572                        section.updateLimits();
     
    30303043                        api.Panel.prototype.initialize.call( panel, id, options );
    30313044                },
    30323045
     3046                /**
     3047                 * Determine whether a given theme can be switched to, or in general.
     3048                 *
     3049                 * @since 4.9.0
     3050                 *
     3051                 * @param {string} [slug] - Theme slug.
     3052                 * @returns {boolean} Whether the theme can be switched to.
     3053                 */
     3054                canSwitchTheme: function canSwitchTheme( slug ) {
     3055                        if ( slug && slug === api.settings.theme.stylesheet ) {
     3056                                return true;
     3057                        }
     3058                        return 'publish' === api.state( 'selectedChangesetStatus' ).get() && ( '' === api.state( 'changesetStatus' ).get() || 'auto-draft' === api.state( 'changesetStatus' ).get() );
     3059                },
     3060
    30333061                /**
    30343062                 * Attach events.
    30353063                 *
     
    30523080                        }
    30533081
    30543082                        function toggleDisabledNotifications() {
    3055                                 if ( 'publish' === api.state( 'selectedChangesetStatus' ).get() ) {
     3083                                if ( panel.canSwitchTheme() ) {
    30563084                                        panel.notifications.remove( 'theme_switch_unavailable' );
    30573085                                } else {
    30583086                                        panel.notifications.add( new api.Notification( 'theme_switch_unavailable', {
     
    30633091                        }
    30643092                        toggleDisabledNotifications();
    30653093                        api.state( 'selectedChangesetStatus' ).bind( toggleDisabledNotifications );
     3094                        api.state( 'changesetStatus' ).bind( toggleDisabledNotifications );
    30663095
    30673096                        // Collapse panel to customize the current theme.
    30683097                        panel.contentContainer.on( 'click', '.customize-theme', function() {
     
    31733202                        }
    31743203
    31753204                        // Prevent loading a non-active theme preview when there is a drafted/scheduled changeset.
    3176                         if ( 'publish' !== api.state( 'selectedChangesetStatus' ).get() && slug !== api.settings.theme.stylesheet ) {
     3205                        if ( panel.canSwitchTheme( slug ) ) {
    31773206                                deferred.reject({
    31783207                                        errorCode: 'theme_switch_unavailable'
    31793208                                });
     
    32663295                 * @returns {jQuery.promise} Promise.
    32673296                 */
    32683297                loadThemePreview: function( themeId ) {
    3269                         var deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams;
     3298                        var panel = this, deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams;
    32703299
    32713300                        // Prevent loading a non-active theme preview when there is a drafted/scheduled changeset.
    3272                         if ( 'publish' !== api.state( 'selectedChangesetStatus' ).get() && themeId !== api.settings.theme.stylesheet ) {
     3301                        if ( ! panel.canSwitchTheme( themeId ) ) {
    32733302                                return deferred.reject().promise();
    32743303                        }
    32753304
     
    50895118                 * @since 4.2.0
    50905119                 */
    50915120                ready: function() {
    5092                         var control = this;
     5121                        var control = this, panel = api.panel( 'themes' );
    50935122
    50945123                        function disableSwitchButtons() {
    5095                                 return 'publish' !== api.state( 'selectedChangesetStatus' ).get() && control.params.theme.id !== api.settings.theme.stylesheet;
     5124                                return ! panel.canSwitchTheme( control.params.theme.id );
    50965125                        }
    50975126
    50985127                        // Temporary special function since supplying SFTP credentials does not work yet. See #42184.
    50995128                        function disableInstallButtons() {
    51005129                                return disableSwitchButtons() || true === api.settings.theme._filesystemCredentialsNeeded;
    51015130                        }
    5102                         function updateButtons( container ) {
    5103                                 var _container = container || control.container;
    5104                                 _container.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() );
    5105                                 _container.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() );
     5131                        function updateButtons() {
     5132                                control.container.find( 'button.preview, button.preview-theme' ).toggleClass( 'disabled', disableSwitchButtons() );
     5133                                control.container.find( 'button.theme-install' ).toggleClass( 'disabled', disableInstallButtons() );
    51065134                        }
    51075135
    5108                         api.state( 'selectedChangesetStatus' ).bind( function() {
    5109                                 updateButtons();
    5110                         });
     5136                        api.state( 'selectedChangesetStatus' ).bind( updateButtons );
     5137                        api.state( 'changesetStatus' ).bind( updateButtons );
    51115138                        updateButtons();
    51125139
    51135140                        control.container.on( 'touchmove', '.theme', function() {
     
    51345161                                event.preventDefault(); // Keep this AFTER the key filter above
    51355162                                section = api.section( control.section() );
    51365163                                section.showDetails( control.params.theme, function() {
    5137                                         updateButtons( section.overlay.find( '.theme-actions' ) );
    51385164
    51395165                                        // Temporary special function since supplying SFTP credentials does not work yet. See #42184.
    51405166                                        if ( api.settings.theme._filesystemCredentialsNeeded ) {