1 2 // WPForms AJAX Submission JS 3 4 // this variable will record that a form was submitted through ajax 5 // or that the form was submitted at all 6 // this value is provided for a way to test to see if a form was submitted 7 var wpforms_ajax_submit_done = false; 8 9 // this viable will hold the last form id submitted 10 // another variable that can be tested from another script 11 var wpforms_last_submitted_form = false; 12 13 jQuery(document).ready(function($) { 14 15 var trigger = location.hash; 16 if (!trigger.match(/^#wpforms-/)) { 17 trigger = false; 18 } 19 20 if (typeof(FormData) == 'undefined') { 21 if (trigger && trigger.match(/^#wpforms-/)) { 22 var triggerEl = $($('[data-trigger="'+trigger+'"]')[0]); 23 var triggerType = triggerEl.attr('data-trigger-type'); 24 if (typeof(triggerType) == 'undefined') { 25 triggerType = 'click'; 26 } 27 triggerEl.trigger(triggerType); 28 wpforms_ajax_submit_done = true; 29 wpforms_last_submitted_form = trigger; 30 } 31 return; 32 } 33 $('.wpforms-ajax-submit form').each(function(index, element) { 34 wpforms_alter_submit(element); 35 }); 36 }); 37 38 function wpforms_alter_submit(form) { 39 // define $ 40 $ = jQuery; 41 42 var form_id = $(form).attr('id'); 43 $(form).attr('action', 'javascript: wpforms_ajax_submit("'+form_id+'");'); 44 $(form).append('<input type="hidden" name="action" value="wpforms_ajax_submit" />'); 45 } 46 47 function wpforms_ajax_submit(form_id) { 48 // define $ 49 $ = jQuery; 50 51 // disable form 52 var container = $('#'+form_id).parent(); 53 container.css('position', 'relative'); 54 var overlay = '<div id="'+form_id+'-overlay" style="background-image:url('+wpforms_ajax_submit_data.loading_image+');background-position:left bottom;background-repeat:no-repeat;width:100%;height:100%;position:absolute;background-color:rgba(0,0,0,0.25);z-index:9999;"></div>'; 55 container.prepend(overlay); 56 57 // do AJAX request 58 var ajaxurl = wpforms_ajax_submit_data.ajaxurl; 59 var form = $('#'+form_id).get(0); 60 ajaxdata = new FormData(form); 61 var ajaxobject = { 62 type: 'post', 63 dataType: 'json', 64 url: ajaxurl, 65 data: ajaxdata, 66 cache: false, 67 contentType: false, 68 processData: false, 69 success: function(json) { 70 // enable form 71 $('#'+form_id+'-overlay').remove(); 72 if (!json) { 73 return; 74 } 75 if (json['redirect_url']) { 76 window.location = json['redirect_url']; 77 return; 78 } 79 if (json['content']) { 80 container.empty(); 81 container.append(json['content']); 82 // make changes to the form that was just inserted 83 // so it keeps working 84 // thanks @caleb-smith-capstorm 85 var form = $('#'+form_id).get(0); 86 wpforms_alter_submit(form); 87 } 88 wpforms_ajax_submit_done = true; 89 wpforms_last_submitted_form = '#'+form_id; 90 }, 91 error: function(jqHXR, textStatus, error) { 92 console.log('error'); 93 console.log(jqHXR); 94 console.log(textStatus); 95 console.log(error); 96 }, 97 complete: function(jqHXR, textStatus) { 98 //console.log('complete'); 99 //console.log(jqHXR); 100 //console.log(textStatus); 101 }, 102 }; 103 104 $.ajax(ajaxobject); 105 }
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.