/** * Update Source Selector * * Handles the UI for selecting which source to use for plugin updates. */ jQuery(document).ready(function($) { // Open modal when toggle is clicked $(document).on('click', '.fpden-update-source-toggle', function(e) { e.preventDefault(); // Add overlay $('body').append('
'); $('#fpden-modal-overlay').css({ 'position': 'fixed', 'top': 0, 'left': 0, 'width': '100%', 'height': '100%', 'background-color': 'rgba(0,0,0,0.5)', 'z-index': 100000 }); // Position and show modal var modal = $('#fpden-update-source-modal'); modal.css({ 'position': 'fixed', 'top': '50%', 'left': '50%', 'transform': 'translate(-50%, -50%)', 'background-color': '#fff', 'padding': '20px', 'border-radius': '5px', 'box-shadow': '0 0 10px rgba(0,0,0,0.5)', 'z-index': 100001, 'width': '400px', 'max-width': '90%' }).show(); // Add close button styles $('.fpden-close-modal').css({ 'position': 'absolute', 'top': '10px', 'right': '10px', 'cursor': 'pointer', 'font-size': '20px', 'color': '#666' }); }); // Close modal when clicking overlay or close button $(document).on('click', '#fpden-modal-overlay, .fpden-close-modal', function() { $('#fpden-update-source-modal').hide(); $('#fpden-modal-overlay').remove(); }); // Prevent clicks inside modal from closing it $('#fpden-update-source-modal').on('click', function(e) { e.stopPropagation(); }); // Handle form submission $('#fpden-update-source-form').on('submit', function(e) { e.preventDefault(); var source = $('input[name="update_source"]:checked').val(); // Show loading state var submitButton = $(this).find('button[type="submit"]'); var originalText = submitButton.text(); submitButton.text('Saving...').prop('disabled', true); // Save via AJAX $.post(ajaxurl, { action: 'fpden_save_update_source', source: source, nonce: fpdenData.updateSourceNonce }, function(response) { submitButton.text(originalText).prop('disabled', false); if (response.success) { // Show success message var message = $('
Update source saved successfully!
'); message.css({ 'color': 'green', 'margin-top': '10px', 'text-align': 'center' }); $('#fpden-update-source-form').append(message); // Hide message and modal after delay setTimeout(function() { message.fadeOut(function() { $(this).remove(); $('#fpden-update-source-modal').hide(); $('#fpden-modal-overlay').remove(); }); }, 1500); } else { // Show error message var message = $('
Error saving update source.
'); message.css({ 'color': 'red', 'margin-top': '10px', 'text-align': 'center' }); $('#fpden-update-source-form').append(message); // Hide message after delay setTimeout(function() { message.fadeOut(function() { $(this).remove(); }); }, 3000); } }); }); });