Changeset 42113
- Timestamp:
- 11/03/2017 12:58:25 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-controls.js
r42104 r42113 2550 2550 */ 2551 2551 showDetails: function ( theme, callback ) { 2552 var section = this ;2552 var section = this, panel = api.panel( 'themes' ); 2553 2553 section.currentTheme = theme.id; 2554 2554 section.overlay.html( section.template( theme ) ) 2555 2555 .fadeIn( 'fast' ) 2556 2556 .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 2557 2570 section.$body.addClass( 'modal-open' ); 2558 2571 section.containFocus( section.overlay ); … … 3032 3045 3033 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 3061 /** 3034 3062 * Attach events. 3035 3063 * … … 3053 3081 3054 3082 function toggleDisabledNotifications() { 3055 if ( 'publish' === api.state( 'selectedChangesetStatus' ).get() ) {3083 if ( panel.canSwitchTheme() ) { 3056 3084 panel.notifications.remove( 'theme_switch_unavailable' ); 3057 3085 } else { … … 3064 3092 toggleDisabledNotifications(); 3065 3093 api.state( 'selectedChangesetStatus' ).bind( toggleDisabledNotifications ); 3094 api.state( 'changesetStatus' ).bind( toggleDisabledNotifications ); 3066 3095 3067 3096 // Collapse panel to customize the current theme. … … 3174 3203 3175 3204 // 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 ) ) { 3177 3206 deferred.reject({ 3178 3207 errorCode: 'theme_switch_unavailable' … … 3267 3296 */ 3268 3297 loadThemePreview: function( themeId ) { 3269 var deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams;3298 var panel = this, deferred = $.Deferred(), onceProcessingComplete, urlParser, queryParams; 3270 3299 3271 3300 // 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 ) ) { 3273 3302 return deferred.reject().promise(); 3274 3303 } … … 5090 5119 */ 5091 5120 ready: function() { 5092 var control = this ;5121 var control = this, panel = api.panel( 'themes' ); 5093 5122 5094 5123 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 ); 5096 5125 } 5097 5126 … … 5100 5129 return disableSwitchButtons() || true === api.settings.theme._filesystemCredentialsNeeded; 5101 5130 } 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() ); 5106 } 5107 5108 api.state( 'selectedChangesetStatus' ).bind( function() { 5109 updateButtons(); 5110 }); 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() ); 5134 } 5135 5136 api.state( 'selectedChangesetStatus' ).bind( updateButtons ); 5137 api.state( 'changesetStatus' ).bind( updateButtons ); 5111 5138 updateButtons(); 5112 5139 … … 5135 5162 section = api.section( control.section() ); 5136 5163 section.showDetails( control.params.theme, function() { 5137 updateButtons( section.overlay.find( '.theme-actions' ) );5138 5164 5139 5165 // Temporary special function since supplying SFTP credentials does not work yet. See #42184.
Note: See TracChangeset
for help on using the changeset viewer.