Skip to content

Commit

Permalink
Merge pull request #83 from albertcht/develop
Browse files Browse the repository at this point in the history
try to avoid conflict with window.onload event
  • Loading branch information
albertcht authored May 15, 2018
2 parents 7daa583 + c659e18 commit 6a34a1c
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 6a34a1c

Please sign in to comment.