jQuery(document).ready(function($) { // Toggle switch functionality $('.wp-allstars-toggle input[type="checkbox"]').on('change', function() { var $input = $(this); var option = $input.attr('name'); var value = $input.is(':checked') ? 1 : 0; // Remove any existing status messages $('.wp-status').remove(); // Add a small notification that fades out var $notification = $('Setting saved'); $('body').append($notification); $.post(wpAllstars.ajaxurl, { action: 'wp_allstars_update_option', option: option, value: value, nonce: wpAllstars.nonce }, function(response) { if (!response.success) { console.error('Error:', response); $notification.css('background', '#d63638').text('Error saving setting'); } // Fade out and remove the notification after 2 seconds setTimeout(function() { $notification.fadeOut(300, function() { $(this).remove(); }); }, 2000); }); }); // Expand/collapse settings functionality $('.wp-allstars-expand-settings').on('click', function(e) { e.preventDefault(); var $button = $(this); var $settings = $button.closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings'); var isExpanded = $button.attr('aria-expanded') === 'true'; $button.attr('aria-expanded', !isExpanded); $button.find('.dashicons').toggleClass('dashicons-arrow-down-alt2 dashicons-arrow-up-alt2'); if (isExpanded) { $settings.slideUp(200); } else { $settings.slideDown(200); } }); // Save settings on form submit $('form').on('submit', function() { // Remove any existing status messages $('.wp-status').remove(); // Add a small notification that fades out var $notification = $('Settings saved'); $('body').append($notification); // Fade out and remove the notification after 2 seconds setTimeout(function() { $notification.fadeOut(300, function() { $(this).remove(); }); }, 2000); }); });