/* * formcheck.js * Forms * * www.anwalt-schulrecht-berlin.de * © 2014 Anreas Jakubietz Berlin * */ // language if (typeof lang !== "undefined") var lang = "de"; // list of required fields to set titles and to check // message array "mail_msg" comes from separate file var msg_id_array = ["subject", "message", "firstname", "lastname", "zip", "location", "street", "email", "phone"]; $(document).ready(function () { /* ================================================== Check HTML5 forms support ================================================== */ var supports = {}; var input = document.createElement('input'); supports.autofocus = "autofocus" in input; supports.required = "required" in input; supports.placeholder = "placeholder" in input; var form = document.createElement('form'); supports.validate = 'noValidate' in form; // Fallbacks if (!supports.autofocus) { // $("#subject").focus(); } if (!supports.required) {} if (!supports.placeholder) {} if (!supports.validate) {} // check if the checkValidity() function exists // typeof document.createElement('input').checkValidity=='function' var html5_validation=supports.validate?1:0; // alert(html5_validation); // test var deviceAgent = navigator.userAgent.toLowerCase(); if (deviceAgent.match(/(iphone|ipod|ipad)/)) html5_validation=0; // due to bug in Safari /* ================================================== Remove spambot honeypot field ================================================== */ var e = document.getElementById("bot_test"); e.parentNode.removeChild(e); /* ================================================== Sroll to invalid field ================================================== */ function scrollToInvalid() { // pageYOffset propertiy returns the pixels the current document has // been scrolled from the upper left corner of the window vertically // Offset of the first invalid input element var invalid_el = $('input:invalid').first().offset().top; // If the invalid element is already within the window view, return true // If you return false, the validation will stop if (invalid_el>window.pageYOffset && invalid_el<(window.pageYOffset+window.innerHeight)) { return true; } else { // scroll to first invalid input if it is not within current view $('html, body').scrollTop(invalid_el + 200); } } /* ================================================== Set HTML5 form validation error messages ================================================== */ var offset = -100; if (html5_validation) { setValidityMessage = function (msg_id, msg) { $('#' + msg_id).on("change invalid", function () { var field = $(this).get(0); field.setCustomValidity(''); if (!field.validity.valid) { field.setCustomValidity(msg); // field.addClass('validate_error'); // removeClass // alert("#" + msg_id + ' (' + msg + '): ' + document.getElementById(msg_id).validity.valid); } }); } for(var i=0; i1) { if (counter >2)return false; alert(mail_msg['click_counter']); return false; } else { return true; } } // form reset confirmation function confirmReset() { if (confirm(mail_msg['confirm_reset'])) { $("#message").val(""); return true; } else { return false; } } /* ================================================== Write Meta Infos into Hidden Fields ================================================== */ var form = $('#contact_mobile'); // user agent var hidden_fields_str = ''; // user screen screen_width=screen.width?screen.width:window.innerWidth?window.innerWidth:""; screen_height=screen.height?screen.height:window.innerHeight?window.innerHeight:""; screen_width=addPoints(screen_width); screen_height=addPoints(screen_height); var retina=window.devicePixelRatio>=2?' (Retina Display)':''; hidden_fields_str += ''; // external and internal referer if ($.cookie("externalreferer")) hidden_fields_str += ''; if ($.cookie("internalreferer")) hidden_fields_str += ''; // alert(hidden_fields_str); // test form.append(hidden_fields_str); function addPoints(str) { str += ''; var rgx = /(\d+)(\d{3})/; while(rgx.test(str)) str = str.replace(rgx, '$1'+'.'+'$2'); return str; } /* ================================================== Retina Images ================================================== */ if (retina==true) { $("#staticmap").attr("src", "https://maps.googleapis.com/maps/api/staticmap?markers=52.501252,13.317683¢er=52.5028,13.317743&zoom=13&size=250x158&scale=2&sensor=false"); } }); // end $(document).ready