/*! * native-validator-bootstrap v0.0.6 * Copyright 2020 Iskandar Jamil */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Validator=e():t.Validator=e()}(window,function(){return r={},n.m=i=[function(n,t,e){(function(t){function g(){return r.Date.now()}var s=NaN,a="[object Symbol]",o=/^\s+|\s+$/g,l=/^[-+]0x[0-9a-f]+$/i,u=/^0b[01]+$/i,c=/^0o[0-7]+$/i,h=parseInt,e="object"==typeof t&&t&&t.Object===Object&&t,i="object"==typeof self&&self&&self.Object===Object&&self,r=e||i||Function("return this")(),d=Object.prototype.toString,b=Math.max,E=Math.min;function S(t){var e=typeof t;return t&&("object"==e||"function"==e)}function k(t){if("number"==typeof t)return t;if("symbol"==typeof(e=t)||(i=e)&&"object"==typeof i&&d.call(e)==a)return s;var e,i,r;if(S(t)&&(t=S(r="function"==typeof t.valueOf?t.valueOf():t)?r+"":r),"string"!=typeof t)return 0===t?t:+t;t=t.replace(o,"");var n=u.test(t);return n||c.test(t)?h(t.slice(2),n?2:8):l.test(t)?s:+t}n.exports=function(r,n,t){var s,a,o,l,u,c,h=0,d=!1,f=!1,e=!0;if("function"!=typeof r)throw new TypeError("Expected a function");function v(t){var e=s,i=a;return s=a=void 0,h=t,l=r.apply(i,e)}function p(t){var e=t-c;return void 0===c||n<=e||e<0||f&&o<=t-h}function y(){var t,e,i=g();if(p(i))return m(i);u=setTimeout(y,(e=n-((t=i)-c),f?E(e,o-(t-h)):e))}function m(t){return u=void 0,e&&s?v(t):(s=a=void 0,l)}function i(){var t,e=g(),i=p(e);if(s=arguments,a=this,c=e,i){if(void 0===u)return h=t=c,u=setTimeout(y,n),d?v(t):l;if(f)return u=setTimeout(y,n),v(c)}return void 0===u&&(u=setTimeout(y,n)),l}return n=k(n)||0,S(t)&&(d=!!t.leading,f="maxWait"in t,o=f?b(k(t.maxWait)||0,n):o,e="trailing"in t?!!t.trailing:e),i.cancel=function(){void 0!==u&&clearTimeout(u),s=c=a=u=void(h=0)},i.flush=function(){return void 0===u?l:m(g())},i}}).call(this,e(2))},function(t,e,i){var r=i(5).default;r.plugin=r.prototype.plugin,r.plugin("match",i(3).default),r.plugin("email",i(4).default),t.exports=r},function(t,e){var i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";i.r(e),e.default={install:function(){},validate:function(t,e){return t.value===document.querySelector(e).value}}},function(t,e,i){"use strict";i.r(e),e.default={install:function(){},validate:function(t){return/^[_A-z0-9._%+-]+@[_A-z0-9.-]+\.[_A-z]{2,}$/.test(t.value)}}},function(t,e,i){"use strict";i.r(e),i.d(e,"default",function(){return l});var r=i(0),n=i.n(r);function s(t,e){for(Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(t){for(var e=(this.document||this.ownerDocument).querySelectorAll(t),i=e.length;0<=--i&&e.item(i)!==this;);return-1 991) { //store in a constant, as we wont be able to get from the element once it is changed var mainTopMarginOriginal = parseInt($("body").css("margin-top")); fixedheader(); $(window).on("scroll",function(event){ fixedheader(); }); function fixedheader() { var superHeaderHeight = 0; var headerHeight = parseInt($("header").outerHeight(true)); //when we scroll to past the height of superheader if($(window).scrollTop() > superHeaderHeight){ //make header fixed $("header").addClass("is-fixed"); $("body").addClass("is-nav"); //add the height of header to the margin of main $("body").css("margin-top",headerHeight + mainTopMarginOriginal + "px"); } else { $("header").removeClass("is-fixed"); $("body").removeClass("is-nav"); $("body").css("margin-top",mainTopMarginOriginal + "px"); } } } $(function() { $(".lazy").Lazy(); }); $(document).ready(function() { try { $('.popup-gallery, .div-gallery').magnificPopup({ delegate: 'a', type: 'image', tLoading: 'Loading image #%curr%...', mainClass: 'mfp-img-mobile', gallery: { enabled: true, navigateByImgClick: true, preload: [0,1] }, image: { tError: 'The image #%curr% could not be loaded.', titleSrc: function(item) { return "" + (item.el.attr('title') || "") + "

" + (item.el.data('description') || "") + "

"; } } }); } catch (e) { } }); new WOW().init(); Validator.plugin("phone", { install() {}, validate(el, attribute) { return /^(\+44|01|02|03|04|05|06|07|08|09)[0-9 ()-]+$/.test(el.value); } }); Validator.plugin("spam", { install() {}, validate(el, attribute) { var a = el.getAttribute("data-vc").trim(); var b = el.value.trim(); var c = a == b; if(c) { var pn = el.parentNode.parentNode; var spamCheckInput = pn.querySelector('[name="spamCheck"]'); spamCheckInput.value = a; } return c; } }); var validator = new Validator(document.querySelector("form"), { // options here }); /* * Ajax driven forms with ajax errors and callbacks * */ function AUTOFORM_NODE(form) { var fn_success = form.getAttribute("data-af-success"); var fn_fail = form.getAttribute("data-af-fail"); var loadingClass = form.getAttribute("data-af-loading"); var isFileUploader = form.classList.contains("af-mult"); var formvalid = false; /* Check if it has JQUERY validation */ if(typeof form.hasValidator !== "undefined") { form.hasValidator.runAllValidation(); if(document.querySelectorAll("form input.is-invalid").length == 0) { formvalid = true; } } else { formvalid = true; } if(formvalid) { var formData = new FormData(form); if(loadingClass !== "") document.body.classList.add(loadingClass); form.querySelector("button.af-submit").classList.add("af-processing"); var ajaxConfig = { method: "POST", body: formData }; if(!isFileUploader) { ajaxConfig.headers = { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' } ajaxConfig.body = new URLSearchParams(formData); } fetch(form.getAttribute("action"), ajaxConfig) .then(response => { if(response.ok) { return response.json(); } else { throw response; } }) .then(data => { document.querySelectorAll(".error-message").forEach(el => el.remove()); form.querySelector("button.af-submit").classList.remove("af-processing"); var fn = window[fn_success]; if(typeof fn === 'function') { fn(form, data); } else { af_success(form, data); } setTimeout(function() { if(loadingClass !== "") document.body.classList.remove(loadingClass); }, 1500); }) .catch(error => { error.text().then(text => { var errJSON = JSON.parse(text); document.querySelectorAll(".invalid-feedback").forEach(el => el.innerHTML = ""); form.querySelector("button.af-submit").classList.remove("af-processing"); /* If error set error message text */ for (var errobj in errJSON.errors) { var field = form.querySelector('[name="' + errobj + '"]'); if(field) { field.classList.remove("is-valid"); field.classList.add("is-invalid"); //field.parentElement.classList.remove("has-success"); //field.parentElement.classList.add("has-error"); var invalidFeedbacks = []; var nextSibling = field.nextElementSibling; while (nextSibling) { if (nextSibling.classList.contains("invalid-feedback")) { invalidFeedbacks.push(nextSibling); break; } nextSibling = nextSibling.nextElementSibling; } var errorMessage = nextSibling; if(errorMessage) { errorMessage.innerHTML = errJSON.errors[errobj].msg; } } } /* Fail Callback */ var fn = window[fn_fail]; if(typeof fn === 'function') { fn(form, text); } else { console.log(errJSON); } }); }); } } document.addEventListener("DOMContentLoaded", function() { var forms = document.querySelectorAll('form[data-af-success] button.af-submit'); forms.forEach(function(btn) { btn.addEventListener("click", function(e) { if(e.target.classList.contains("af-processing")) return; var form = e.target.closest("form") || null; if(form) AUTOFORM_NODE(form); }); }); }); function af_success() { parent.showAlert("fa-check", "Success", "Thank you for your interest", "#FFFFFF", false); } function af_fail() { parent.showAlert("fa-times", "Fail", "There was an error with the form, please make sure all required information is entered and try again.", "#FFFFFF", false); }