1(function ($) { 2 'use strict'; 3 4 // Helper function to fire analytics events 5 function fireAnalyticsEvent() { 6 if (typeof gtag == 'function') { 7 gtag('event', 'Enquiry', { 8 'event_category': 'submit' 9 }); 10 } 11 }; 12 13 $('.icaal-contact-form').submit(function (e) { 14 var $form = $(this); 15 var form_submission = $form.attr('data-form'); 16 17 var $submit = $form.find('.submit'); 18 var $response = $form.find('.response'); 19 var $data = $form.serializeArray(); 20 var data = new FormData(); 21 22 var api_key_name_1 = icaal_options['api_key_name_1']; 23 var api_key_name_2 = icaal_options['api_key_name_2']; 24 var api_key_name_3 = icaal_options['api_key_name_3']; 25 var api_key_name_4 = icaal_options['api_key_name_4']; 26 var api_key_name_5 = icaal_options['api_key_name_5']; 27 var api_key = ''; 28 var lead_destination = ''; 29 var api_key_found = false; 30 31 switch (form_submission) { 32 case api_key_name_1: 33 api_key = icaal_options['api_key_1']; 34 lead_destination = icaal_options['lead_destination_1']; 35 api_key_found = true; 36 break; 37 case api_key_name_2: 38 api_key = icaal_options['api_key_2']; 39 lead_destination = icaal_options['lead_destination_2']; 40 api_key_found = true; 41 break; 42 case api_key_name_3: 43 api_key = icaal_options['api_key_3']; 44 lead_destination = icaal_options['lead_destination_3']; 45 api_key_found = true; 46 break; 47 case api_key_name_4: 48 api_key = icaal_options['api_key_4']; 49 lead_destination = icaal_options['lead_destination_4']; 50 api_key_found = true; 51 break; 52 case api_key_name_5: 53 api_key = icaal_options['api_key_5']; 54 lead_destination = icaal_options['lead_destination_5']; 55 api_key_found = true; 56 break; 57 default: 58 api_key_found = false; 59 } 60 61 if (api_key_found) { 62 63 $submit.addClass('btn-loading').prop('disabled', true); 64 $response.empty(); 65 66 $.each($data, function (index, field) { 67 data.append(field.name, field.value); 68 }); 69 70 var icaal_form_attachments = $form.find('[type="file"]'); 71 if (icaal_form_attachments.length > 0) { 72 $.each($form.find('[type="file"]'), function (index, file) { 73 var attachment_name = $(this).attr('name'); 74 $.each($(this)[0].files, function (index, file) { 75 data.append(attachment_name, file); 76 }); 77 }); 78 } 79 80 data.append('action', 'lead_gen_ajax_send_to_dashboard'); 81 data.append('security', nonce); 82 83 if (lead_destination == 'icaal') { 84 85 $.ajax({ 86 url: 'https://api.clients.icaal.co.uk/forms/' + api_key, 87 method: 'post', 88 contentType: false, 89 processData: false, 90 data: data 91 }).done(function (response) { 92 if (response.redirect_to) { 93 location.assign(response.redirect_to); 94 } else if (response.message) { 95 $response.addAlert('success', response.message); 96 } 97 $form.find('input').addClass('is-valid').removeClass('is-invalid'); 98 $form.find('.invalid-feedback').empty(); 99 100 $form.trigger('reset'); 101 102 // Fire analytics before any redirect or completion 103 fireAnalyticsEvent(); 104 105 $form.trigger('success'); 106 $form.trigger('complete'); 107 }).fail(function (response) { 108 var errors = response.responseJSON.errors; 109 var error = response.responseJSON.error; 110 111 $submit.removeClass('btn-loading').prop('disabled', false); 112 if (errors) { 113 $form.find('input').addClass('is-valid').removeClass('is-invalid');
114 $form.find('.invalid-feedback').empty(); 115 $.each(errors, function (index, value) { 116 $('[name=' + index + ']').addClass('is-invalid').removeClass('is-valid'); 117 $('[name=' + index + ']').next('.invalid-feedback').text(value); 118 }); 119 $response.addAlert('danger', 'Validation Errors', errors); 120 $form.trigger('complete'); 121 } else if (error) { 122 $response.addAlert('danger', error); 123 $form.trigger('complete'); 124 } 125 }); 126 127 } else if (lead_destination == 'leadgen') { 128 129 $.ajax({ 130 url: ajax_url, 131 method: 'post', 132 contentType: false, 133 processData: false, 134 data: data, 135 }).done(function (response) { 136 137 response = JSON.parse(response); 138 139 $form.find('input').addClass('is-valid').removeClass('is-invalid'); 140 $form.find('.invalid-feedback').empty(); 141 142 $submit.removeClass('btn-loading').prop('disabled', false); 143 144 var errors = response.errors; 145 146 if (errors) { 147 $form.find('input').addClass('is-valid').removeClass('is-invalid'); 148 $form.find('.invalid-feedback').empty(); 149 $.each(errors, function (index, value) { 150 if (index == 'phone_number') { 151 index = 'phone'; 152 } 153 $('[name=' + index + ']').addClass('is-invalid').removeClass('is-valid'); 154 $('[name=' + index + ']').next('.invalid-feedback').text(value); 155 }); 156 157 $response.addAlert('danger', 'Validation Errors', errors); 158 $form.trigger('complete'); 159 } else { 160 $response.addAlert('success', 'Your message was sent successfully'); 161 fireAnalyticsEvent(); 162 $form.trigger('success'); 163 $form.trigger('complete'); 164 } 165 166 }); 167 168 } else { 169 $response.addAlert('danger', 'No / Incorrect Lead Destination Set'); 170 } 171 172 } else { 173 $response.addAlert('danger', 'No / Incorrect API Key Name Set'); 174 } 175 176 $form.on('complete', function () { 177 var custom_html = icaal_options['custom_html'];
178 $response.append(custom_html); 179 }); 180 181 $('html, body').animate({scrollTop: $response.offset().top - 50}, 100); 182 183 return false; 184 }); 185 186})(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.