-
Notifications
You must be signed in to change notification settings - Fork 3
/
frontendforms.min.js
1 lines (1 loc) · 4.23 KB
/
frontendforms.min.js
1
let frontendformsmain=function(){function e(){let e=document.getElementById("timecounter");if(e){let t=parseInt(document.getElementById("minTime").getAttribute("data-time")),n=document.getElementById("minTime").getAttribute("data-unit");n=n.split(";");let a=setInterval((function(){t<=0&&(clearInterval(a),e.remove());let i=n[0];t<=1&&(i=n[1]),e.innerText=t+" "+i,t-=1}),1e3)}}function t(e,t){t.preventDefault();let n=document.getElementById(e);if(n){let e=n.src;e=function(e,t){let n=e.split("?");if(n.length>=2){let a=encodeURIComponent(t)+"=",i=n[1].split(/[&;]/g);for(let e=i.length;e-- >0;)-1!==i[e].lastIndexOf(a,0)&&i.splice(e,1);return e=n[0]+"?"+i.join("&")}return e}(e,"time"),n.src=e+"&time="+Date.now()}}window.addEventListener("load",(function(){e(),d(),function(){const e=new URLSearchParams(window.location.search),t=e.get("fc-anchor");t&&(e.delete("fc-anchor"),location.hash="#"+t)}(),function(){const e=document.querySelector("textarea");if(!e)return;e.addEventListener("input",e=>{const t=e.currentTarget,n=t.getAttribute("maxlength");if(n){const e=t.value.length,a=document.getElementById(t.id+"-char_count");a&&(e===n?a.innerHTML=a.dataset.maxreached:a.children[0].innerHTML=n-e)}})}();let t=document.getElementsByTagName("form");if(t.length>0)for(let e=0;e<t.length;e++){let n=t[e].id;n&&"undefined"!=typeof mfConditionalFields&&mfConditionalFields("#"+n,{rules:"inline",dynamic:!0,debug:!0})}})),document.addEventListener("click",(function(e){if(e.target.classList.contains("pwtoggle")){let t=e.target.parentNode.previousElementSibling;"password"===t.type?t.type="text":t.type="password"}}));let n=document.querySelectorAll("input");for(let e=0;e<n.length;e++)n[e].addEventListener("change",a,!1),n[e].addEventListener("change",l,!1);function a(){let e=this.id.replace(this.form.id+"-",""),t=document.querySelectorAll("[data-ff_field="+e+"]");if(t.length>0)for(let e=0;e<t.length;e++){let n=document.getElementById(t[e].id);if(n){let e=n.dataset.ff_attribute,t=n.dataset.ff_validator,a=this.value;e&&a&&(t&&("dateBeforeField"===t&&(a=i(-1,a),a=a.toISOString().split("T")[0]),"dateAfterField"===t&&(a=i(1,a),a=a.toISOString().split("T")[0])),n.setAttribute(e,a))}}}function i(e,t){let n=new Date(t);return n.setDate(n.getDate()+e),n}function l(){this.id.replace(this.form.id+"-","");let e=document.querySelectorAll("[data-ff_validator]");if(e.length>0)for(let t=0;t<e.length;t++){let n=document.getElementById(e[t].id);if(n&&("dateWithinDaysRange"===n.dataset.ff_validator||"dateOutsideOfDaysRange"===n.dataset.ff_validator)){let e=n.dataset.ff_attribute,t=this.value,a=n.dataset.ff_days;if("min"===e){if(e&&t){let e=r(t,a,"+");e=new Date(e).toISOString().slice(0,10),"dateOutsideOfDaysRange"===n.dataset.ff_validator?a>0?n.setAttribute("min",e):a<0?n.setAttribute("max",e):n.removeAttribute("max"):a>0?(n.setAttribute("min",t),n.setAttribute("max",e)):(n.setAttribute("max",t),n.setAttribute("min",e))}}else n.removeAttribute("max")}}}function r(e,t,n){let a=new Date(e);return"+"===n?a.setDate(a.getDate()+parseInt(t)):a.setDate(a.getDate()-parseInt(t)),a}function o(e){let t=location.href;location.href="#"+e,history.replaceState(null,null,t)}function d(e=null){if(e){s(document.getElementById(e))}else{let e=document.querySelectorAll("[data-submitajax]");if(e.length){let t=0;for(;t<e.length;t++)s(e[t])}}}function s(n){"string"==typeof n&&(n=document.getElementById(n)),n&&n.addEventListener("submit",(function(a){a.preventDefault();let i=n.dataset.submitajax,l=n.getAttribute("action"),r=document.getElementById(i+"-form-submission");r&&(r.style.display=null);let s=l.split(/#(.*)/)[1];"undefined"!==s&&(s=i+"-ajax-wrapper");let u=new XMLHttpRequest;u.onload=function(){let n=this.responseText;let l=(new DOMParser).parseFromString(n,"text/html").getElementById(i+"-ajax-wrapper"),r=l.innerHTML;if(4===u.readyState&&200===u.status){let n=i+"-ajax_redirect",u=c.get(n);if("1"===l.dataset.validated){let e="";if(u){let t=u.split("#");if(t.length>1){u=t[0],e="?fc-anchor="+t[1]}window.location=u+e}else document.getElementById(i+"-ajax-wrapper").innerHTML=r,o(s)}else document.getElementById(i+"-ajax-wrapper").innerHTML=r,o(s),t(i+"-captcha-image",a),d(),e(),listenToSliderCaptchaCheckboxes()}},u.open("POST",l),u.setRequestHeader("X-Requested-With","XMLHttpRequest");let c=new FormData(n);u.send(c)}))}}();