Improve theme install/activate buttons: maintain button size and use spinner animation

This commit is contained in:
Marcus Quinn
2025-03-25 02:34:40 +00:00
parent e19dfecd6c
commit 05ff272b51
2 changed files with 31 additions and 17 deletions

View File

@ -623,17 +623,29 @@ input:checked + .wp-toggle-slider:before {
gap: 8px; gap: 8px;
} }
/* Make theme buttons match size of plugin buttons */ /* Fix theme buttons to maintain consistent size and prevent layout jumps */
.theme-actions .button { .theme-actions .button {
margin: 0; min-width: 80px !important;
padding: 6px 14px; text-align: center !important;
height: auto; position: relative !important;
line-height: 1.4; padding-left: 12px !important;
font-size: 13px; padding-right: 12px !important;
font-weight: 500; }
min-width: 100px;
text-align: center; /* Style for the updating message with spinner */
border-radius: 4px; .theme-actions .button.updating-message:before,
.theme-actions .button.updated-message:before {
margin-top: 0 !important;
padding-right: 3px !important;
vertical-align: bottom !important;
}
/* Style theme actions container spacing */
.theme-actions {
display: flex !important;
flex-wrap: wrap !important;
gap: 8px !important;
padding: 15px !important;
} }
/* Responsive Adjustments */ /* Responsive Adjustments */

View File

@ -310,13 +310,14 @@ jQuery(document).ready(function($) {
e.preventDefault(); e.preventDefault();
var $button = $(this); var $button = $(this);
var slug = $button.data('slug'); var slug = $button.data('slug');
var buttonText = $button.text();
$button.addClass('updating-message').text('Installing...'); $button.addClass('updating-message').attr('aria-label', wp.updates.l10n.installing);
wp.updates.installTheme({ wp.updates.installTheme({
slug: slug, slug: slug,
success: function(response) { success: function(response) {
$button.removeClass('updating-message').addClass('updated-message').text('Installed!'); $button.removeClass('updating-message').addClass('updated-message').attr('aria-label', wp.updates.l10n.installed);
setTimeout(function() { setTimeout(function() {
// Replace the button with an activate button // Replace the button with an activate button
var $parent = $button.parent(); var $parent = $button.parent();
@ -332,7 +333,7 @@ jQuery(document).ready(function($) {
}, 1000); }, 1000);
}, },
error: function(response) { error: function(response) {
$button.removeClass('updating-message').text('Install'); $button.removeClass('updating-message').text(buttonText);
alert(response.errorMessage || 'Error installing theme'); alert(response.errorMessage || 'Error installing theme');
} }
}); });
@ -344,8 +345,9 @@ jQuery(document).ready(function($) {
var $button = $(this); var $button = $(this);
var slug = $button.data('slug'); var slug = $button.data('slug');
var nonce = $button.data('nonce'); var nonce = $button.data('nonce');
var buttonText = $button.text();
$button.addClass('updating-message').text('Activating...'); $button.addClass('updating-message').attr('aria-label', 'Activating...');
$.ajax({ $.ajax({
url: ajaxurl, url: ajaxurl,
@ -357,7 +359,7 @@ jQuery(document).ready(function($) {
}, },
success: function(response) { success: function(response) {
if (response.success) { if (response.success) {
$button.removeClass('updating-message').addClass('updated-message').text('Activated!'); $button.removeClass('updating-message').addClass('updated-message').attr('aria-label', 'Activated');
setTimeout(function() { setTimeout(function() {
// Replace the button with an active button // Replace the button with an active button
var $parent = $button.parent(); var $parent = $button.parent();
@ -368,12 +370,12 @@ jQuery(document).ready(function($) {
// window.location.reload(); // window.location.reload();
}, 1000); }, 1000);
} else { } else {
$button.removeClass('updating-message').text('Activate'); $button.removeClass('updating-message').text(buttonText);
alert(response.data || 'Error activating theme'); alert(response.data || 'Error activating theme');
} }
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
$button.removeClass('updating-message').text('Activate'); $button.removeClass('updating-message').text(buttonText);
alert('Failed to activate theme. Please try again or activate from the Themes page. Error: ' + error); alert('Failed to activate theme. Please try again or activate from the Themes page. Error: ' + error);
} }
}); });