FIX: Google Captcha

This commit is contained in:
Tony Air 2024-04-29 23:04:58 +02:00
parent e1915341c8
commit fedd6e33a2
2 changed files with 17 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@a2nt/ss-bootstrap-ui-webpack-boilerplate-react", "name": "@a2nt/ss-bootstrap-ui-webpack-boilerplate-react",
"version": "5.3.8", "version": "5.3.9",
"description": "This UI Kit allows you to build Bootstrap 5 webapp with some extra UI features. It's easy to extend and easy to convert HTML templates to CMS templates.", "description": "This UI Kit allows you to build Bootstrap 5 webapp with some extra UI features. It's easy to extend and easy to convert HTML templates to CMS templates.",
"author": "Tony Air <tony@twma.pro>", "author": "Tony Air <tony@twma.pro>",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",

View File

@ -29,7 +29,7 @@ const CaptchaUI = ((window) => {
const widgetid = grecaptcha.render(el, el.dataset) const widgetid = grecaptcha.render(el, el.dataset)
el.dataset.widgetid = widgetid el.dataset.widgetid = widgetid
if(el.dataset.size === 'invisible' && !el.dataset.callback){ if (el.dataset.size === 'invisible' && !el.dataset.callback) {
grecaptcha.execute(widgetid) grecaptcha.execute(widgetid)
form.addEventListener('submit', submitListener) form.addEventListener('submit', submitListener)
} }
@ -39,32 +39,34 @@ const CaptchaUI = ((window) => {
}) })
} }
const loadScript = (callback) => {
if(typeof window.grecaptcha !== 'undefined'){ window.noCaptchaFieldRender = attachCaptcha
callback()
const loadScript = () => {
if (document.getElementById('captchaAPI')) {
console.log(`${NAME}: Already loading API`)
return
} }
console.log(`${NAME}: Loading Captcha API ...`) console.log(`${NAME}: Loading Captcha API ...`)
const script = document.createElement('script'); const script = document.createElement('script');
script.id = 'captchaAPI'; script.id = 'captchaAPI';
script.src = `https://www.google.com/recaptcha/api.js?render=explicit&hl=${ document.querySelector('html').getAttribute('lang').substr(0,2)}` script.src = `https://www.google.com/recaptcha/api.js?onload=noCaptchaFieldRender&render=explicit&hl=${document.querySelector('html').getAttribute('lang').substr(0, 2)}`
script.async = true script.async = true
script.onload = function() {
console.log(`${NAME}: Captcha API is loaded.`)
callback()
}
document.body.append(script) document.body.append(script)
} }
if(document.querySelectorAll('.g-recaptcha').length){ if (document.querySelectorAll('.g-recaptcha').length) {
loadScript(attachCaptcha); if (typeof window.grecaptcha !== 'undefined') {
}else{ attachCaptcha()
}
loadScript();
} else {
console.log(`${NAME}: No Captcha fields.`) console.log(`${NAME}: No Captcha fields.`)
} }
window.noCaptchaFieldRender = attachCaptcha
} }
window.addEventListener(`${Events.LODEDANDREADY}`, init) window.addEventListener(`${Events.LODEDANDREADY}`, init)