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