| 1 |
document.addEventListener("DOMContentLoaded",function(){function c(e){const o=[];if(typeof e=="object"&&e.join===void 0)for(const n in e)o.push(c(e[n]));else if(typeof e=="object"&&e.join!==void 0)for(const n in e)o.push(c(e[n]));else typeof e=="function"||typeof e=="string"&&o.push(e);return o.join("<br />")}function s(e,o=null,n=null){if(e&&n)if(e=c(e),o){const i=n.querySelector(`[name="${o}"]`);if(!i){s(e,null,n);return}const a=document.createElement("div");a.className="fcom_field_error fcom_field_error",a.innerHTML=e;let r=i.closest(".fcom_form-group");r?(r.classList.add("fcom_has_error"),r.appendChild(a)):s(e,null,n)}else{const i=document.createElement("div");i.className="fcom_field_error fcom_global_error",i.innerHTML=e,n.appendChild(i)}}function f(e){e.querySelectorAll(".fcom_form_input input").forEach(function(o){o.addEventListener("blur",function(){o.closest(".fcom_form-group").classList.remove("fcom_has_error")})}),e.addEventListener("submit",function(o){o.preventDefault(),e.querySelectorAll(".fcom_field_error").forEach(function(t){t.remove()}),e.querySelectorAll(".fcom_has_error").forEach(function(t){t.classList.remove("fcom_has_error")});const i=e.querySelector('button[type="submit"]');i.classList.add("fcom_loading"),i.setAttribute("disabled","disabled");const a=new FormData(e),r=new XMLHttpRequest;r.open("POST",window.fluentComRegistration.ajax_url,!0),r.send(a),r.onload=function(){if(i.classList.remove("fcom_loading"),i.removeAttribute("disabled"),r.status>=200&&r.status<300){let t=r.responseText;if(!t||t.indexOf("<!DOCTYPE html>")!==-1){s("Something went wrong. Please try again later",null,e),window.location.reload();return}const l=JSON.parse(r.responseText);if(l.verifcation_html){let _=e.getElementsByClassName("fcom_form_main_fields");_.length>0&&(_[0].style.display="none");let p=e.querySelector(".fcom_verification_wrap");p&&p.remove();let u=document.createElement("div");u.className="fcom_verification_wrap",u.innerHTML=l.verifcation_html,e.appendChild(u)}else if(l.redirect_url){window.location.href=l.redirect_url,i.innerText="Redirecting...";return}else l.success_html?document.getElementById("fcom_user_onboard_wrap").innerHTML=l.success_html:s("Something went wrong. Please try again later",null,e)}else{const t=JSON.parse(r.responseText);if((!t||!t.message)&&s("Something went wrong. Please try again later",null,e),s(t.message,null,e),t.errors)for(const l in t.errors)s(t.errors[l],l,e)}}})}let d=document.getElementById("fcom_user_registration_form");d&&f(d);let m=document.getElementById("fcom_user_login_form");if(m&&f(m),window.fluentComRegistration&&window.fluentComRegistration.is_logged_in){const e=document.getElementById("fcom_user_accept_form");e&&e.addEventListener("submit",function(o){o.preventDefault();const n=e.querySelector('button[type="submit"]');n.classList.add("fcom_loading"),n.setAttribute("disabled","disabled"),e.querySelectorAll(".fcom_field_error").forEach(function(t){t.remove()});const a=new FormData(e),r=new XMLHttpRequest;r.open("POST",window.fluentComRegistration.ajax_url,!0),r.send(a),r.onload=function(){if(n.classList.remove("fcom_loading"),n.removeAttribute("disabled"),r.status>=200&&r.status<300){const t=JSON.parse(r.responseText);if(t.redirect_url){window.location.href=t.redirect_url,n.innerText="Redirecting...";return}else s("Something went wrong. Please try again later",null,e)}else{const t=JSON.parse(r.responseText);!t||!t.message?s("Something went wrong. Please try again later",null,e):s(t.message,null,e)}}})}}); |