1// ============================================================================= 2// JS/SITE/MAIN.JS 3// ----------------------------------------------------------------------------- 4// Plugin site scripts. 5// ============================================================================= 6 7// ============================================================================= 8// TABLE OF CONTENTS 9// ----------------------------------------------------------------------------- 10// 01. Handle Form Submissions 11// ============================================================================= 12 13// Handle Form Submissions 14// ============================================================================= 15 16jQuery(document).ready(function($) { 17 18 function confirm_subscription( form ) { 19 20 var confirm_type = form.data('x-email-confirm'); 21 22 if ( confirm_type === 'Message' ) { 23 make_alert( form.data('x-email-message'), 'x-alert-success' ).appendTo(form); 24 } 25 26 if ( confirm_type === 'Redirect' ) { 27 window.location.href = form.data('x-email-redirect'); 28 } 29 30 } 31 32 function make_alert( content, class_name ) { 33 34 return $('<div class="x-subscribe-form-alert-wrap">' + 35 '<div class="x-alert ' + ( class_name || 'x-alert-danger' ) + ' fade in man">' + 36 '<button type="button" class="close" data-dismiss="alert">×</button>' + 37 content + 38 '</div>' + 39 '</div>').alert(); 40 41 } 42 43 $('.x-subscribe-form').submit(function(e) { 44 45 // 46 // Prevent default behavior. 47 // 48 49 e.preventDefault(); 50 51 52 // 53 // Make note of our form. 54 // 55 56 $form = $(this); 57 58 59 // 60 // Prevent extra submissions. 61 // 62 63 $form.find('input[type="submit"]').prop('disabled', true).addClass('btn-muted'); 64 65 66 // 67 // Craft data for AJAX request. 68 // 69 70 postdata = { 71 action : 'x_subscribe', 72 data : { 73 form_id : $(this).find('input[name="x_subscribe_form[id]"]').val() || '', 74 first_name : $(this).find('input[name="x_subscribe_form[first-name]"]').val() || '', 75 last_name : $(this).find('input[name="x_subscribe_form[last-name]"]').val() || '', 76 full_name : $(this).find('input[name="x_subscribe_form[full-name]"]').val() || '', 77 email_address : $(this).find('input[name="x_subscribe_form[email]"]').val() || '', 78 } 79 }; 80 81 82 // 83 // Submit form. 84 // 85 86 $.post(x_email_forms.ajaxurl, postdata, function(response) { 87 data = $.parseJSON(response); 88 if ( data.error ) { 89 console.log(data.log_message); 90 make_alert(data.message).appendTo($form); 91 } else { 92 console.log('subscribed'); 93 confirm_subscription($form); 94 } 95 }); 96 97 }); 98 99});
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.