Skip to content

Commit

Permalink
try to avoid conflict with window.onload event
Browse files Browse the repository at this point in the history
  • Loading branch information
albertcht committed Apr 29, 2018
1 parent f3e02c2 commit c659e18
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/InvisibleReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ public function render($lang = null)
{
$html = '<script src="' . $this->getPolyfillJs() . '"></script>' . PHP_EOL;
$html .= '<div id="_g-recaptcha"></div>' . PHP_EOL;
if ($this->getOption('hideBadge', false)) {
$html .= '<style>.grecaptcha-badge{display:none;!important}</style>' . PHP_EOL;
}
$html .= '<div class="g-recaptcha" data-sitekey="' . $this->siteKey .'" ';
$html .= 'data-size="invisible" data-callback="_submitForm" data-badge="' . $this->getOption('dataBadge', 'bottomright') . '"></div>';
$html .= '<script src="' . $this->getCaptchaJs($lang) . '" async defer></script>' . PHP_EOL;
$html .= '<script>var _submitForm,_captchaForm,_captchaSubmit,_execute=true;</script>';
$html .= '<script>window.onload=function(){';
$html .= "<script>window.addEventListener('load', _loadCaptcha);" . PHP_EOL;
$html .= "function _loadCaptcha(){";
if ($this->getOption('hideBadge', false)) {
$html .= "document.querySelector('.grecaptcha-badge').style = 'display:none;!important'" . PHP_EOL;
}
$html .= '_captchaForm=document.querySelector("#_g-recaptcha").closest("form");';
$html .= "_captchaSubmit=_captchaForm.querySelector('[type=submit]');";
$html .= '_submitForm=function(){if(typeof _submitEvent==="function"){_submitEvent();';
Expand Down

0 comments on commit c659e18

Please sign in to comment.