Fix accordion functionality with proper initialization and reliable toggle behavior

This commit is contained in:
Marcus Quinn
2025-03-16 02:34:57 +00:00
parent 4a860c416c
commit 50bba9e322

View File

@ -742,27 +742,34 @@ function wp_allstars_settings_page() {
<script> <script>
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
// Handle accordion functionality // Set initial state of panels
$('.wp-allstars-expand-settings').on('click', function(e) { $('.wp-allstars-toggle-settings').each(function() {
e.preventDefault(); var $panel = $(this);
var $button = $panel.closest('.wp-allstars-toggle').find('.wp-allstars-expand-settings');
var isExpanded = $button.attr('aria-expanded') === 'true';
// Set initial visibility without animation
$panel.toggle(isExpanded);
if (isExpanded) {
$button.find('.dashicons').css('transform', 'rotate(180deg)');
}
});
// Handle click events
$('.wp-allstars-expand-settings').on('click', function() {
var $button = $(this); var $button = $(this);
var $panel = $button.closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings'); var $panel = $button.closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings');
var $icon = $button.find('.dashicons'); var $icon = $button.find('.dashicons');
var isExpanded = $button.attr('aria-expanded') === 'true'; var isExpanded = $button.attr('aria-expanded') === 'true';
// Toggle aria state // Update state
$button.attr('aria-expanded', !isExpanded); $button.attr('aria-expanded', !isExpanded);
// Rotate icon // Update icon
$icon.css('transform', !isExpanded ? 'rotate(180deg)' : ''); $icon.css('transform', !isExpanded ? 'rotate(180deg)' : '');
// Toggle panel visibility with animation // Toggle panel
if (!isExpanded) { $panel.slideToggle(200);
$panel.css('display', 'block').hide().slideDown(200);
} else {
$panel.slideUp(200);
}
}); });
}); });
</script> </script>