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 // also allowed would be: ! # $ % & ' * + - / = ? ^ _ ` { | } ~ 103 if( ! value.match( /^[\w|\.|\-|ÃÃÃäöü]+@\w[\w|\.|\-|ÃÃÃäöü]*\.[a-zA-Z]{2,20}$/ ) ) 104 { 105 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 106 send.validationError = true; 107 } 108 else 109 { 110 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 111 } 112 nomatch = false; 113 } 114 115 if(classes && classes.match(/is_phone/)) 116 { 117 if( ! value.match(/^(\d|\s|\-|\/|\(|\)|\[|\]|e|x|t|ension|\.|\+|\_|\,|\:|\;){3,}$/)) 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_number/)) 130 { 131 if( ! value.match( /^-?\s*(0|[1-9]\d*)([\.,]\d+)?$/ ) ) 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 144 if(classes && classes.match(/is_positiv_number/)) 145 { 146 if(!($.isNumeric(value)) || value == "" || value < 0 ) 147 { 148 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 149 send.validationError = true; 150 } 151 else 152 { 153 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 154 } 155 nomatch = false; 156 } 157 158 if(classes && classes.match(/captcha/) && ! classes.match(/recaptcha/) ) 159 { 160 var verifier = form.find("#" + name + "_verifier").val(), 161 lastVer = verifier.charAt(verifier.length-1), 162 finalVer = verifier.charAt(lastVer); 163 164 if(value != finalVer) 165 { 166 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 167 send.validationError = true; 168 } 169 else 170 { 171 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 172 } 173 nomatch = false; 174 } 175 176 if(nomatch && value != '') 177 { 178 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 179 } 180 }); 181 182 if(send.validationError == false) 183 { 184 if(form.data('av-custom-send')) 185 { 186 mailchimp_send(); 187 } 188 else 189 { 190 send_ajax_form(); 191 } 192 } 193 194 return false; 195 } 196 197 198 function send_ajax_form() 199 { 200 if(form_sent){ return false; } 201 202 if( send.button.hasClass( 'avia_button_inactive' ) ) 203 { 204 return false; 205 } 206 207 form_sent = true; 208 send.button.addClass('av-sending-button'); 209 send.button.val(send.button.data('sending-label')); 210 211 var redirect_to = form.data('avia-redirect') || false, 212 action = form.attr('action'), 213 label = form.is( '.av-form-labels-style' ); 214 215 if( label ) return; 216 217 responseContainer.load(action+' '+options.responseContainer, send.dataObj, function() 218 { 219 if(redirect_to && action != redirect_to) 220 { 221 form.attr('action', redirect_to); 222 location.href = redirect_to; 223 // form.submit(); 224 } 225 else 226 { 227 responseContainer.removeClass('hidden').css({display:"block"}); 228 form.slideUp(400, function(){responseContainer.slideDown(400, function(){ $('body').trigger('av_resize_finished'); }); send.formElements.val('');}); 229 } 230 }); 231 } 232 233 234 function mailchimp_send() 235 { 236 if(form_sent){ return false; } 237 238 form_sent = true; 239 240 var original_label = send.button.val(); 241 242 send.button.addClass('av-sending-button'); 243 send.button.val(send.button.data('sending-label')); 244 send.dataObj.ajax_mailchimp = true; 245 246 var redirect_to = form.data('avia-redirect') || false, 247 action = form.attr('action'), 248 error_msg_container = form.find('.av-form-error-container'), 249 form_id = form.data('avia-form-id'); 250 251 $.ajax({ 252 url: action, 253 type: "POST", 254 data:send.dataObj, 255 beforeSend: function() 256 { 257 if(error_msg_container.length) 258 { 259 error_msg_container.slideUp(400, function() 260 { 261 error_msg_container.remove(); 262 $('body').trigger('av_resize_finished'); 263 }); 264 } 265 }, 266 success: function(responseText) 267 { 268 var response = jQuery("<div>").append(jQuery.parseHTML(responseText)), 269 error = response.find('.av-form-error-container'); 270 271 if(error.length) 272 { 273 form_sent = false; 274 form.prepend(error); 275 error.css({display:"none"}).slideDown(400, function() 276 { 277 $('body').trigger('av_resize_finished'); 278 }); 279 280 send.button.removeClass('av-sending-button'); 281 send.button.val(original_label); 282 } 283 else 284 { 285 if(redirect_to && action != redirect_to) 286 { 287 form.attr('action', redirect_to); 288 location.href = redirect_to; 289 // form.submit(); 290 } 291 else 292 { 293 var success_text = response.find(options.responseContainer + "_" + form_id); 294 295 responseContainer.html(success_text).removeClass('hidden').css({display:"block"}); 296 297 form.slideUp(400, function() 298 { 299 responseContainer.slideDown(400, function() 300 { 301 $('body').trigger('av_resize_finished'); 302 }); 303 304 send.formElements.val(''); 305 }); 306 } 307 } 308 309 }, 310 error: function() 311 { 312 313 }, 314 complete: function() 315 { 316 317 } 318 }); 319 320 } 321 322 323 }); 324 }; 325})(jQuery); 326 327 328 329
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.