Simplify accordion toggle functionality for better reliability
This commit is contained in:
@ -742,55 +742,28 @@ function wp_allstars_settings_page() {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
// Initialize accordion functionality
|
$('.wp-allstars-expand-settings').on('click', function() {
|
||||||
function initAccordion() {
|
var $button = $(this);
|
||||||
const $button = $('.wp-allstars-expand-settings');
|
var $panel = $button.closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings');
|
||||||
const $settings = $('.wp-allstars-toggle-settings');
|
var isExpanded = $button.attr('aria-expanded') === 'true';
|
||||||
let isAnimating = false;
|
|
||||||
|
|
||||||
$button.on('click', function(e) {
|
// Update button state
|
||||||
e.preventDefault();
|
$button.attr('aria-expanded', !isExpanded);
|
||||||
e.stopPropagation();
|
|
||||||
|
|
||||||
// Prevent multiple clicks during animation
|
// Toggle icon
|
||||||
if (isAnimating) return;
|
$button.find('.dashicons')
|
||||||
|
.removeClass('dashicons-arrow-down-alt2 dashicons-arrow-up-alt2')
|
||||||
|
.addClass(isExpanded ? 'dashicons-arrow-down-alt2' : 'dashicons-arrow-up-alt2');
|
||||||
|
|
||||||
const $thisButton = $(this);
|
// Toggle panel
|
||||||
const isExpanded = $thisButton.attr('aria-expanded') === 'true';
|
$panel.slideToggle(200);
|
||||||
|
|
||||||
// Set animating flag
|
return false;
|
||||||
isAnimating = true;
|
|
||||||
|
|
||||||
// Toggle aria state
|
|
||||||
$thisButton.attr('aria-expanded', !isExpanded);
|
|
||||||
|
|
||||||
// Toggle icon rotation
|
|
||||||
$thisButton.find('.dashicons')
|
|
||||||
.toggleClass('dashicons-arrow-down-alt2', isExpanded)
|
|
||||||
.toggleClass('dashicons-arrow-up-alt2', !isExpanded);
|
|
||||||
|
|
||||||
// Animate panel
|
|
||||||
$settings.slideToggle({
|
|
||||||
duration: 200,
|
|
||||||
complete: function() {
|
|
||||||
isAnimating = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Prevent panel closing when clicking inside
|
|
||||||
$settings.on('click', function(e) {
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize accordion
|
|
||||||
initAccordion();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Accordion Toggle Styles */
|
|
||||||
.wp-allstars-toggle {
|
.wp-allstars-toggle {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border: 1px solid #ccd0d4;
|
border: 1px solid #ccd0d4;
|
||||||
|
Reference in New Issue
Block a user