1function ajaxFormContactus(options) { 2 var _this = {}; 3 _this.options = {}; 4 _this.formId = ""; 5 _this.$button = null; 6 _this.recaptcha = null; 7 _this.recaptchaWidgetId = null; 8 _this.resetRecaptcha = function () { 9 if (_this.recaptchaWidgetId != null) { 10 grecaptcha.reset(_this.recaptchaWidgetId); 11 } 12 }; 13 _this.executeRecaptcha = function () { 14 if (_this.recaptchaWidgetId != null) { 15 _this.resetRecaptcha(); // Ensures Recaptcha has loaded properly 16 grecaptcha.execute(_this.recaptchaWidgetId); 17 } 18 }; 19 _this.constructor = function (options) { 20 _this.formId = $(options.formSelector).data("form-id"); 21 $(options.formSelector).on('keypress', function (e) { 22 if (e.which === 13 && !$(e.target).is("textarea")) { 23 _this.send(); 24 return false; 25 } 26 }); 27 _this.options = options; 28 if (!_this.options.url) { 29 _this.options.url = "/services/forms/ajaxforms.asmx/" + $(_this.options.formSelector).data("kf-ajax-form"); 30 } 31 _this.renderRecapthca(); 32 _this.$button = $(_this.options.formSelector).find(".contact-submit-contactus"); 33 34 _this.$button.on('click', function (event) { 35 event.preventDefault(); 36 _this.send(); 37 return; 38 }); 39 }; 40 _this.renderRecapthca = function () { 41 if (window.grecaptcha && window.grecaptcha.render) { 42 _this.recaptcha = $(options.formSelector).find("[data-ajax-form-recaptcha]"); 43 if (_this.recaptcha.length === 0) { 44 return; 45 } 46 47 _this.recaptchaWidgetId = grecaptcha.render( 48 _this.recaptcha[0], 49 { 50 'sitekey': _this.recaptcha.data("ajax-form-recaptcha"), 51 'callback': _this.send, 52 'size': 'invisible' 53 } 54 ); 55 return; 56 } 57 setTimeout(_this.renderRecapthca, 500); 58 }; 59 _this.sending = false; 60 _this.send = function (captchaToken) { 61 if (_this.sending && !captchaToken) { 62 return; 63 } 64 _this.sending = true; 65 var form = getForm(_this.options.formSelector); 66 var data = form.data; 67 data.formId = _this.formId; 68 data.captchaToken = captchaToken; 69 data.url = window.location.href; 70 if (_this.options.validation && !_this.options.validation(_this.options.formSelector, form)) { 71 _this.sending = false; 72 _this.resetRecaptcha(); 73 return; 74 } 75 if (_this.recaptcha && (_this.recaptcha.length > 0 && !captchaToken)) { 76 _this.sending = false; 77 _this.executeRecaptcha(); 78 return; 79 } 80 var dataToSend = { 81 formData: data 82 }; 83 84 function handleSuccess(msg) { 85 86 if (window.tC) { 87 tC.event.cms_contact_form_submit(this, { 88 "form_name": "CMS Contact Form", 89 "form_status": "form.submit.success", 90 "lead_id": msg.d.EFormSubmissionId 91 }); 92 } 93 94 if (_this.options.showOnSuccessSelector) { 95 $(options.formSelector).find(_this.options.showOnSuccessSelector).removeClass("d-none"); 96 } 97 if (_this.options.hideOnSuccessSelector) { 98 $(options.formSelector).find(_this.options.hideOnSuccessSelector).addClass("d-none"); 99 } 100 if (_this.options.onSuccess) { 101 _this.options.onSuccess(msg.d); 102 } 103 _this.response = msg.d; 104 _this.sending = false; 105 } 106 107 function handleError() { 108 $(options.formSelector).find(_this.options.showOnErrorSelector).removeClass("d-none"); 109 $(options.formSelector).find(_this.options.hideOnSuccessSelector).addClass("d-none"); 110 } 111 112 $.ajax({ 113 type: "POST", 114 url: options.url, 115 data: JSON.stringify(dataToSend), 116 contentType: "application/json; charset=utf-8", 117 success: function (msg) { 118 if (msg.d.Errors.length > 0) { 119 handleError(); 120 } else { 121 handleSuccess(msg); 122 } 123 _this.resetRecaptcha(); 124 }, 125 error: function () { 126 handleError(); 127 _this.resetRecaptcha(); 128 } 129 }); 130 }; 131 132 _this.constructor(options); 133 return _this; 134} 135 136var ajaxFormHelpers = new function () { 137 var _this = this; 138 _this._containsHtmlRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 139 _this.containsHtml = function () { 140 return re.test(String(form.data.email).toLowerCase()); 141 }; 142 _this.isEmptyOrWhiteSpace = function (str) { 143 return !str || str.match(/^ *$/) !== null; 144 }; 145 _this.setErrorState = function (field, showError) { 146 if (showError) { 147 $(field).addClass("invalid-input"); 148 $(field).prev().addClass("invalid-label"); 149 return; 150 } 151 $(field).removeClass("invalid-input"); 152 $(field).prev().removeClass("invalid-label"); 153 }; 154}; 155 156function getForm(formSelector) { 157 var form = { 158 data: {}, 159 fields: {} 160 }; 161 162 $(formSelector).find("input,textarea,select").each(function () { 163 var name = $(this).attr("name"); 164 if (typeof name !== 'undefined') { 165 var value; 166 if ($(this).is(':checkbox')) { 167 value = $(this).is(':checked'); 168 } else { 169 value = $(this).val(); 170 } 171 form.data[name] = value; 172 form.fields[name] = this; 173 } 174 }); 175 return form; 176};
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.