1// ------------------------------------------------------------------------------------------- 2// contact form ajax 3// ------------------------------------------------------------------------------------------- 4 5(function($) 6{ 7 $.fn.avia_ajax_form = function(variables) 8 { 9 var defaults = 10 { 11 sendPath: 'send.php', 12 responseContainer: '.ajaxresponse' 13 }; 14 15 var options = $.extend(defaults, variables); 16 17 return this.each(function() 18 { 19 var form = $(this), 20 form_sent = false, 21 send = 22 { 23 formElements: form.find('textarea, select, input[type=text], input[type=checkbox], input[type=hidden]'), 24 validationError:false, 25 button : form.find('input:submit'), 26 dataObj : {} 27 }, 28 29 responseContainer = form.next(options.responseContainer).eq( 0 ); 30 31 send.button.on('click', checkElements); 32 33 34 //change type of email forms on mobile so the e-mail keyboard with @ sign is used 35 if($.avia_utilities.isMobile) 36 { 37 send.formElements.each(function(i) 38 { 39 var currentElement = $(this), 40 is_email = currentElement.hasClass('is_email'); 41 42 if(is_email) currentElement.attr('type','email'); 43 }); 44 } 45 46 47 function checkElements( e ) 48 { 49 // reset validation var and send data 50 send.validationError = false; 51 send.datastring = 'ajax=true'; 52 53 // Get in js added element (e.g. from reCAPTCHA) 54 send.formElements = form.find('textarea, select, input[type=text], input[type=checkbox], input[type=hidden], input[type=email]'); 55 56 send.formElements.each(function(i) 57 { 58 var currentElement = $(this), 59 surroundingElement = currentElement.parent(), 60 value = currentElement.val(), 61 name = currentElement.attr('name'), 62 classes = currentElement.attr('class'), 63 nomatch = true; 64 65 if(currentElement.is(':checkbox')) 66 { 67 if(currentElement.is(':checked')) { value = true; } else { value = ''; } 68 } 69 70 send.dataObj[name] = encodeURIComponent(value); 71 72 if(classes && classes.match(/is_empty/)) 73 { 74 if(value == '' || value == null) 75 { 76 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 77 send.validationError = true; 78 } 79 else 80 { 81 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 82 } 83 nomatch = false; 84 } 85 86 if(classes && classes.match(/is_email/)) 87 { 88 if( ! value.match(/^[\w|\.|\-]+@\w[\w|\.|\-]*\.[a-zA-Z]{2,20}$/)) 89 { 90 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 91 send.validationError = true; 92 } 93 else 94 { 95 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 96 } 97 nomatch = false; 98 } 99 100 if(classes && classes.match(/is_ext_email/)) 101 { 102 if( ! value.match( /^[\w\.\-ÃÃÃäöü]+@\w[\w\.\-ÃÃÃäöü]*\.[a-zA-Z]{2,20}$/ ) ) 103 { 104 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 105 send.validationError = true; 106 } 107 else 108 { 109 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 110 } 111 nomatch = false; 112 } 113 114 if(classes && classes.match(/is_special_email/)) 115 { 116 // also allowed would be: ! # $ % & ' * + - / = ? ^ _ ` { | } ~ see https://de.wikipedia.org/wiki/E-Mail-Adresse#Der_Lokalteil_(Local_Part) 117 if( ! value.match( /^[a-zA-Z0-9.!#$%&'*+\-\/=?^_`{|}~ÃÃÃäöü]+@\w[\w\.\-ÃÃÃäöü]*\.[a-zA-Z]{2,20}$/ ) ) 118 { 119 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 120 send.validationError = true; 121 } 122 else 123 { 124 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 125 } 126 nomatch = false; 127 } 128 129 if(classes && classes.match(/is_phone/)) 130 { 131 if( ! value.match(/^(\d|\s|\-|\/|\(|\)|\[|\]|e|x|t|ension|\.|\+|\_|\,|\:|\;){3,}$/)) 132 { 133 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 134 send.validationError = true; 135 } 136 else 137 {
138 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 139 } 140 nomatch = false; 141 } 142 143 if(classes && classes.match(/is_number/)) 144 { 145 if( ! value.match( /^-?\s*(0|[1-9]\d*)([\.,]\d+)?$/ ) ) 146 { 147 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 148 send.validationError = true; 149 } 150 else 151 { 152 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 153 } 154 nomatch = false; 155 } 156 157 if(classes && classes.match(/is_positiv_number/)) 158 { 159 if( ! ( av_isNumeric( value ) ) || value == "" || value < 0 ) 160 { 161 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 162 send.validationError = true; 163 } 164 else 165 { 166 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 167 } 168 nomatch = false; 169 } 170 171 if(classes && classes.match(/captcha/) && ! classes.match(/recaptcha/) ) 172 { 173 var verifier = form.find("#" + name + "_verifier").val(), 174 lastVer = verifier.charAt(verifier.length-1), 175 finalVer = verifier.charAt(lastVer); 176 177 if(value != finalVer) 178 { 179 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 180 send.validationError = true; 181 } 182 else 183 { 184 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 185 } 186 nomatch = false; 187 } 188 189 if(nomatch && value != '') 190 { 191 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 192 } 193 }); 194 195 if(send.validationError == false) 196 { 197 if(form.data('av-custom-send')) 198 { 199 mailchimp_send(); 200 } 201 else 202 { 203 send_ajax_form(); 204 } 205 } 206 207 return false; 208 } 209 210 211 function send_ajax_form() 212 { 213 if(form_sent){ return false; } 214 215 if( send.button.hasClass( 'avia_button_inactive' ) ) 216 { 217 return false; 218 } 219 220 form_sent = true; 221 send.button.addClass('av-sending-button'); 222 send.button.val(send.button.data('sending-label')); 223 224 var redirect_to = form.data('avia-redirect') || false, 225 action = form.attr('action'), 226 label = form.is( '.av-form-labels-style' ); 227 228 if( label ) return; 229 230 responseContainer.load(action+' '+options.responseContainer, send.dataObj, function() 231 { 232 if(redirect_to && action != redirect_to) 233 { 234 form.attr('action', redirect_to); 235 location.href = redirect_to; 236 // form.submit(); 237 } 238 else 239 { 240 responseContainer.removeClass('hidden').css({display:"block"}); 241 form.slideUp(400, function(){responseContainer.slideDown(400, function(){ $('body').trigger('av_resize_finished'); }); send.formElements.val('');}); 242 } 243 }); 244 } 245 246 247 function mailchimp_send() 248 { 249 if(form_sent){ return false; } 250 251 form_sent = true; 252 253 var original_label = send.button.val(); 254 255 send.button.addClass('av-sending-button'); 256 send.button.val(send.button.data('sending-label')); 257 send.dataObj.ajax_mailchimp = true; 258 259 var redirect_to = form.data('avia-redirect') || false, 260 action = form.attr('action'), 261 error_msg_container = form.find('.av-form-error-container'), 262 form_id = form.data('avia-form-id'); 263 264 $.ajax({ 265 url: action, 266 type: "POST", 267 data:send.dataObj, 268 beforeSend: function() 269 { 270 if(error_msg_container.length) 271 { 272 error_msg_container.slideUp(400, function() 273 { 274 error_msg_container.remove(); 275 $('body').trigger('av_resize_finished'); 276 }); 277 } 278 }, 279 success: function(responseText) 280 { 281 var response = jQuery("<div>").append(jQuery.parseHTML(responseText)), 282 error = response.find('.av-form-error-container'); 283 284 if(error.length) 285 { 286 form_sent = false; 287 form.prepend(error); 288 error.css({display:"none"}).slideDown(400, function() 289 { 290 $('body').trigger('av_resize_finished'); 291 }); 292 293 send.button.removeClass('av-sending-button'); 294 send.button.val(original_label); 295 } 296 else 297 { 298 if(redirect_to && action != redirect_to) 299 { 300 form.attr('action', redirect_to); 301 location.href = redirect_to; 302 // form.submit(); 303 } 304 else 305 { 306 var success_text = response.find(options.responseContainer + "_" + form_id); 307 308 responseContainer.html(success_text).removeClass('hidden').css({display:"block"}); 309 310 form.slideUp(400, function() 311 { 312 responseContainer.slideDown(400, function() 313 { 314 $('body').trigger('av_resize_finished'); 315 }); 316 317 send.formElements.val(''); 318 }); 319 } 320 } 321 322 }, 323 error: function() 324 { 325 326 }, 327 complete: function() 328 { 329 330 } 331 }); 332 333 } 334 335 /** 336 * jQuery.isNumeric() is deprecated with 3.3 337 * This is the replacement implementation 338 * 339 * As of jQuery 3.0, isNumeric is limited to strings and numbers (primitives or objects) that can be coerced to finite numbers (gh-2662) 340 * parseFloat NaNs numeric-cast false positives ("") ...but misinterprets leading-number strings, particularly hex literals ("0x...") 341 * subtraction forces infinities to NaN 342 * 343 * @since 4.9.1 344 * @param {mixed} obj 345 * @returns {boolean} 346 */ 347 function av_isNumeric( obj ) 348 { 349 // Fix for Android < 2.3 from jQuery has been skipped (release date 2010) 350 var type = typeof obj; 351 return ( type === "number" || type === "string" ) && ! isNaN( obj - parseFloat( obj ) ); 352 } 353 354 }); 355 }; 356})(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.