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), is_email = currentElement.hasClass('is_email'); 40 if(is_email) currentElement.attr('type','email'); 41 }); 42 } 43 44 45 function checkElements( e ) 46 { 47 // reset validation var and send data 48 send.validationError = false; 49 send.datastring = 'ajax=true'; 50 51 send.formElements.each(function(i) 52 { 53 var currentElement = $(this), 54 surroundingElement = currentElement.parent(), 55 value = currentElement.val(), 56 name = currentElement.attr('name'), 57 classes = currentElement.attr('class'), 58 nomatch = true; 59 60 if(currentElement.is(':checkbox')) 61 { 62 if(currentElement.is(':checked')) { value = true } else {value = ''} 63 } 64 65 send.dataObj[name] = encodeURIComponent(value); 66 67 if(classes && classes.match(/is_empty/)) 68 { 69 if(value == '' || value == null) 70 { 71 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 72 send.validationError = true; 73 } 74 else 75 { 76 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 77 } 78 nomatch = false; 79 } 80 81 if(classes && classes.match(/is_email/)) 82 { 83 if(!value.match(/^[\w|\.|\-]+@\w[\w|\.|\-]*\.[a-zA-Z]{2,20}$/)) 84 { 85 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 86 send.validationError = true; 87 } 88 else 89 { 90 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 91 } 92 nomatch = false; 93 } 94 95 if(classes && classes.match(/is_ext_email/)) 96 { 97 // also allowed would be: ! # $ % & ' * + - / = ? ^ _ ` { | } ~ 98 if( ! value.match( /^[\w|\.|\-|ÃÃÃäöü]+@\w[\w|\.|\-|ÃÃÃäöü]*\.[a-zA-Z]{2,20}$/ ) ) 99 { 100 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 101 send.validationError = true; 102 } 103 else 104 { 105 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 106 } 107 nomatch = false; 108 } 109 110 if(classes && classes.match(/is_phone/)) 111 { 112 if(!value.match(/^(\d|\s|\-|\/|\(|\)|\[|\]|e|x|t|ension|\.|\+|\_|\,|\:|\;){3,}$/)) 113 { 114 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 115 send.validationError = true; 116 } 117 else 118 { 119 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 120 } 121 nomatch = false; 122 } 123 124 if(classes && classes.match(/is_number/)) 125 { 126 if(!($.isNumeric(value)) || value == "") 127 { 128 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 129 send.validationError = true; 130 } 131 else 132 { 133 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 134 } 135 nomatch = false; 136 } 137 138 if(classes && classes.match(/captcha/)) 139 { 140 var verifier = form.find("#" + name + "_verifier").val(), 141 lastVer = verifier.charAt(verifier.length-1), 142 finalVer = verifier.charAt(lastVer); 143 144 if(value != finalVer) 145 {
146 surroundingElement.removeClass("valid error ajax_alert").addClass("error"); 147 send.validationError = true; 148 } 149 else 150 { 151 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 152 } 153 nomatch = false; 154 } 155 156 if(nomatch && value != '') 157 { 158 surroundingElement.removeClass("valid error ajax_alert").addClass("valid"); 159 } 160 }); 161 162 if(send.validationError == false) 163 { 164 if(form.data('av-custom-send')) 165 { 166 mailchimp_send(); 167 } 168 else 169 { 170 send_ajax_form(); 171 } 172 } 173 174 return false; 175 } 176 177 178 function send_ajax_form() 179 { 180 if(form_sent){ return false; } 181 182 form_sent = true; 183 send.button.addClass('av-sending-button'); 184 send.button.val(send.button.data('sending-label')); 185 186 var redirect_to = form.data('avia-redirect') || false, 187 action = form.attr('action'), 188 label = form.is( '.av-form-labels-style' ); 189 190 if( label ) return; 191 192 responseContainer.load(action+' '+options.responseContainer, send.dataObj, function() 193 { 194 if(redirect_to && action != redirect_to) 195 { 196 form.attr('action', redirect_to); 197 location.href = redirect_to; 198 // form.submit(); 199 } 200 else 201 { 202 responseContainer.removeClass('hidden').css({display:"block"}); 203 form.slideUp(400, function(){responseContainer.slideDown(400, function(){ $('body').trigger('av_resize_finished'); }); send.formElements.val('');}); 204 } 205 }); 206 } 207 208 209 function mailchimp_send() 210 { 211 if(form_sent){ return false; } 212 213 form_sent = true; 214 215 var original_label = send.button.val(); 216 217 send.button.addClass('av-sending-button'); 218 send.button.val(send.button.data('sending-label')); 219 send.dataObj.ajax_mailchimp = true; 220 221 var redirect_to = form.data('avia-redirect') || false, 222 action = form.attr('action'), 223 error_msg_container = form.find('.av-form-error-container'), 224 form_id = form.data('avia-form-id'); 225 226 $.ajax({ 227 url: action, 228 type: "POST", 229 data:send.dataObj, 230 beforeSend: function() 231 { 232 if(error_msg_container.length) 233 { 234 error_msg_container.slideUp(400, function() 235 { 236 error_msg_container.remove(); 237 $('body').trigger('av_resize_finished'); 238 }); 239 } 240 }, 241 success: function(responseText) 242 { 243 var response = jQuery("<div>").append(jQuery.parseHTML(responseText)), 244 error = response.find('.av-form-error-container'); 245 246 if(error.length) 247 { 248 form_sent = false; 249 form.prepend(error); 250 error.css({display:"none"}).slideDown(400, function() 251 { 252 $('body').trigger('av_resize_finished'); 253 }); 254 255 send.button.removeClass('av-sending-button'); 256 send.button.val(original_label); 257 } 258 else 259 { 260 if(redirect_to && action != redirect_to) 261 { 262 form.attr('action', redirect_to); 263 location.href = redirect_to; 264 // form.submit(); 265 } 266 else 267 { 268 var success_text = response.find(options.responseContainer + "_" + form_id); 269 270 responseContainer.html(success_text).removeClass('hidden').css({display:"block"}); 271 272 form.slideUp(400, function() 273 { 274 responseContainer.slideDown(400, function() 275 { 276 $('body').trigger('av_resize_finished'); 277 }); 278 279 send.formElements.val(''); 280 }); 281 } 282 } 283 284 }, 285 error: function() 286 { 287 288 }, 289 complete: function() 290 { 291 292 } 293 }); 294 295 } 296 297 298 }); 299 }; 300})(jQuery); 301 302 303 304
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.