Fix accordion toggle functionality to prevent yoyo effect on first click
This commit is contained in:
@ -742,31 +742,21 @@ 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);
|
|
||||||
|
// Update state before animation
|
||||||
|
isExpanded = !isExpanded;
|
||||||
|
$button.attr('aria-expanded', isExpanded);
|
||||||
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
|
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
|
||||||
|
|
||||||
// Handle click events
|
// Animate panel
|
||||||
$button.on('click', function(e) {
|
$panel.slideToggle(200);
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user