Improve settings UI: - Remove Save Changes button for instant saves - Move save notification to bottom right - Fix toggle switch interference - Improve notification styling and animations
This commit is contained in:
@ -3,19 +3,31 @@ jQuery(document).ready(function($) {
|
|||||||
var $input = $(this);
|
var $input = $(this);
|
||||||
var option = $input.attr('name');
|
var option = $input.attr('name');
|
||||||
var value = $input.is(':checked') ? 1 : 0;
|
var value = $input.is(':checked') ? 1 : 0;
|
||||||
|
|
||||||
|
// Remove any existing status messages
|
||||||
|
$('.wpa-status').remove();
|
||||||
|
|
||||||
|
// Add a small notification that fades out
|
||||||
|
var $notification = $('<span class="wpa-status" style="position: fixed; bottom: 20px; right: 20px; background: #00a32a; color: white; padding: 8px 16px; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">Setting saved</span>');
|
||||||
|
$('body').append($notification);
|
||||||
|
|
||||||
$.post(wpaSuperstar.ajaxurl, {
|
$.post(wpaSuperstar.ajaxurl, {
|
||||||
action: 'wpa_superstar_update_option',
|
action: 'wpa_superstar_update_option',
|
||||||
option: option,
|
option: option,
|
||||||
value: value,
|
value: value,
|
||||||
nonce: wpaSuperstar.nonce
|
nonce: wpaSuperstar.nonce
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response.success) {
|
if (!response.success) {
|
||||||
$input.next('.wpa-status').remove();
|
|
||||||
$input.after('<span class="wpa-status" style="color: green; margin-left: 10px;">Saved</span>');
|
|
||||||
setTimeout(function() { $('.wpa-status').fadeOut(); }, 2000);
|
|
||||||
} else {
|
|
||||||
console.error('Error:', response);
|
console.error('Error:', response);
|
||||||
|
$notification.css('background', '#d63638').text('Error saving setting');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fade out and remove the notification after 2 seconds
|
||||||
|
setTimeout(function() {
|
||||||
|
$notification.fadeOut(300, function() {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
}, 2000);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -49,7 +49,7 @@ function wpa_superstar_settings_page() {
|
|||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<form method="post" action="options.php">
|
<div class="wpa-settings-content">
|
||||||
<?php settings_fields( 'wpa-superstar-settings' ); ?>
|
<?php settings_fields( 'wpa-superstar-settings' ); ?>
|
||||||
<?php do_settings_sections( 'wpa-superstar-settings' ); ?>
|
<?php do_settings_sections( 'wpa-superstar-settings' ); ?>
|
||||||
|
|
||||||
@ -108,9 +108,7 @@ function wpa_superstar_settings_page() {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
<?php submit_button( __( 'Save Changes', 'wpa-superstar' ) ); ?>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
Reference in New Issue
Block a user