1/** 2 * Public JavaScript for the Subscription System plugin 3 */ 4(function($) { 5 'use strict'; 6 7 $(document).ready(function() { 8 // Handle subscription form submission 9 $('.ss-subscription-form').on('submit', function(e) { 10 e.preventDefault(); 11 12 var form = $(this); 13 var submitButton = form.find('.ss-form-submit'); 14 var messageContainer = form.find('.ss-message'); 15 16 // Clear previous messages 17 messageContainer.removeClass('success error').empty().hide(); 18 19 // Get form data 20 var planId = form.find('select[name="plan_id"]').val() || form.find('input[name="plan_id"]').val(); 21 var email = form.find('input[name="email"]').val(); 22 23 // Validate form 24 if (!planId) { 25 messageContainer.addClass('error').text('Please select a subscription plan.').show(); 26 return; 27 } 28 29 if (!email) { 30 messageContainer.addClass('error').text('Please enter your email address.').show(); 31 return; 32 } 33 34 // Show loading state 35 submitButton.prop('disabled', true).text(ss_vars.i18n.processing); 36 37 // Send AJAX request 38 $.ajax({ 39 url: ss_vars.ajax_url, 40 type: 'POST', 41 data: { 42 action: 'ss_subscribe', 43 plan_id: planId, 44 email: email, 45 nonce: ss_vars.nonce 46 }, 47 success: function(response) { 48 if (response.success) { 49 messageContainer.addClass('success').text(response.data.message).show(); 50 51 // Reset form 52 form[0].reset(); 53 54 // Redirect if URL provided 55 if (response.data.redirect) { 56 setTimeout(function() { 57 window.location.href = response.data.redirect; 58 }, 2000); 59 } 60 } else { 61 messageContainer.addClass('error').text(ss_vars.i18n.error + ' ' + response.data.message).show(); 62 } 63 64 // Reset button 65 submitButton.prop('disabled', false).text(form.data('button-text')); 66 }, 67 error: function() { 68 messageContainer.addClass('error').text(ss_vars.i18n.error + ' An unexpected error occurred.').show(); 69 submitButton.prop('disabled', false).text(form.data('button-text')); 70 } 71 }); 72 }); 73 74 // Handle cancel subscription 75 $('.ss-cancel-subscription').on('click', function(e) { 76 e.preventDefault(); 77 78 if (confirm('Are you sure you want to cancel this subscription?')) { 79 var subscriptionId = $(this).data('id'); 80 81 // Send AJAX request 82 $.ajax({ 83 url: ss_vars.ajax_url, 84 type: 'POST', 85 data: { 86 action: 'manage_subscription', 87 subscription_id: subscriptionId, 88 nonce: ss_vars.nonce, 89 ss_action: 'cancel' 90 }, 91 success: function(response) { 92 if (response.success) { 93 alert(response.data.message); 94 window.location.reload(); 95 } else { 96 alert('Error: ' + (response.data.message || 'An error occurred')); 97 } 98 }, 99 error: function(xhr, status, error) { 100 console.error('AJAX Error:', status, error); 101 alert('An unexpected error occurred. Please try again.'); 102 } 103 }); 104 } 105 }); 106 107 // Handle pause subscription 108 $('.ss-pause-subscription').on('click', function(e) { 109 e.preventDefault(); 110 111 if (confirm('Are you sure you want to pause this subscription?')) { 112 var subscriptionId = $(this).data('id'); 113 114 // Send AJAX request 115 $.ajax({ 116 url: ss_vars.ajax_url, 117 type: 'POST', 118 data: { 119 action: 'manage_subscription', 120 subscription_id: subscriptionId, 121 nonce: ss_vars.nonce, 122 ss_action: 'pause' 123 }, 124 success: function(response) { 125 if (response.success) { 126 alert(response.data.message); 127 window.location.reload(); 128 } else { 129 alert('Error: ' + (response.data.message || 'An error occurred')); 130 } 131 }, 132 error: function(xhr, status, error) { 133 console.error('AJAX Error:', status, error); 134 alert('An unexpected error occurred. Please try again.'); 135 } 136 }); 137 } 138 }); 139 140 // Handle resume subscription 141 $('.ss-resume-subscription').on('click', function(e) { 142 e.preventDefault(); 143 144 if (confirm('Are you sure you want to resume this subscription?')) { 145 var subscriptionId = $(this).data('id'); 146 147 // Send AJAX request 148 $.ajax({ 149 url: ss_vars.ajax_url, 150 type: 'POST', 151 data: { 152 action: 'manage_subscription', 153 subscription_id: subscriptionId, 154 ss_action: 'resume', 155 nonce: ss_vars.nonce 156 }, 157 success: function(response) { 158 if (response.success) { 159 alert(response.data.message); 160 window.location.reload(); 161 } else { 162 alert('Error: ' + (response.data.message || 'An error occurred')); 163 } 164 }, 165 error: function(xhr, status, error) { 166 console.error('AJAX Error:', status, error); 167 alert('An unexpected error occurred. Please try again.'); 168 } 169 }); 170 } 171 }); 172 }); 173})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.