46 lines
2 KiB
TypeScript
46 lines
2 KiB
TypeScript
export default {
|
|
methods: {
|
|
// * Set recaptcha window variables and init it.
|
|
init(forms: Array<HTMLFormElement>) {
|
|
if(forms.length) {
|
|
window.__CN_Recaptcha = function () {
|
|
forms.map((form) => {
|
|
if (!form.querySelector(".r_captcha > div")) {
|
|
const newDiv = document.createElement("div");
|
|
newDiv.classList.add("g-recaptcha");
|
|
form.querySelector(".r_captcha")?.appendChild(newDiv);
|
|
}
|
|
form.inert = true;
|
|
});
|
|
(function(d, t) {
|
|
const g = d.createElement(t) as HTMLIFrameElement,
|
|
s = d.getElementsByTagName(t)[0];
|
|
g.src = "https://www.google.com/recaptcha/api.js?render=explicit&onload=__CN_Recaptcha_Loaded";
|
|
s.parentNode?.insertBefore(g, s);
|
|
}(document, "script"));
|
|
};
|
|
window.__CN_Recaptcha_Reset = function() {
|
|
forms.map((form) => {
|
|
form.querySelector(".r_captcha > div")?.remove();
|
|
form.inert = true;
|
|
});
|
|
};
|
|
window.__CN_Recaptcha_Loaded = function() {
|
|
forms.map((form) => {
|
|
form.inert = false;
|
|
if (form.querySelector(".r_captcha > div") !== null) {
|
|
// @ts-ignore
|
|
grecaptcha.render(document.querySelector(".r_captcha > div"), {
|
|
"sitekey": form.dataset.recaptchaKey ?? ""
|
|
});
|
|
}
|
|
});
|
|
};
|
|
// @ts-ignore
|
|
if (window.WebCookieNotice.getCnCookieStatus("recaptcha") === "true") {
|
|
window.__CN_Recaptcha();
|
|
}
|
|
}
|
|
},
|
|
},
|
|
};
|