Fix accordion toggle functionality to prevent yoyo effect on first click

This commit is contained in:
Marcus Quinn
2025-03-16 02:20:10 +00:00
parent 2db85d559b
commit cd3bae732b

View File

@ -742,31 +742,21 @@ function wp_allstars_settings_page() {
<script>
jQuery(document).ready(function($) {
// Handle accordion functionality
$('.wp-allstars-expand-settings').each(function() {
$('.wp-allstars-expand-settings').on('click', function(e) {
e.preventDefault();
var $button = $(this);
var $panel = $button.closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings');
var $icon = $button.find('.dashicons');
// Set initial state without animation
var isExpanded = $button.attr('aria-expanded') === 'true';
$panel.toggle(isExpanded);
// Update state before animation
isExpanded = !isExpanded;
$button.attr('aria-expanded', isExpanded);
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
// Handle click events
$button.on('click', function(e) {
e.preventDefault();
// Toggle state
isExpanded = !isExpanded;
$button.attr('aria-expanded', isExpanded);
// Update icon rotation
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
// Animate panel only on click
$panel.slideToggle(200);
});
// Animate panel
$panel.slideToggle(200);
});
});
</script>