Fix accordion panel to properly stay open/closed while preserving chevron rotation

This commit is contained in:
Marcus Quinn
2025-03-16 02:24:31 +00:00
parent 2f11132157
commit e50f82ed70

View File

@ -742,23 +742,6 @@ function wp_allstars_settings_page() {
<script>
jQuery(document).ready(function($) {
// Set initial state without animation
$('.wp-allstars-expand-settings').each(function() {
var $button = $(this);
var $panel = $button.closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings');
var $icon = $button.find('.dashicons');
var isExpanded = $button.attr('aria-expanded') === 'true';
// Set initial state
if (isExpanded) {
$panel.show();
$icon.css('transform', 'rotate(180deg)');
} else {
$panel.hide();
$icon.css('transform', '');
}
});
// Handle click events
$('.wp-allstars-expand-settings').on('click', function(e) {
e.preventDefault();
@ -768,13 +751,18 @@ function wp_allstars_settings_page() {
var $icon = $button.find('.dashicons');
var isExpanded = $button.attr('aria-expanded') === 'true';
// Toggle state
isExpanded = !isExpanded;
$button.attr('aria-expanded', isExpanded);
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
// Update state
$button.attr('aria-expanded', !isExpanded);
// Animate panel
$panel.slideToggle(200);
// Update icon (keep the working rotation logic)
$icon.css('transform', !isExpanded ? 'rotate(180deg)' : '');
// Toggle panel with animation
if (!isExpanded) {
$panel.slideDown(200);
} else {
$panel.slideUp(200);
}
});
});
</script>