Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
himiklab committed Nov 8, 2017
1 parent c900ad0 commit 64daf4d
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@ class ReCaptcha extends InputWidget
/** @var array Additional html widget options, such as `class`. */
public $widgetOptions = [];

public function init()
{
parent::init();

$view = $this->view;
$view->registerJs($this->render('onload'), $view::POS_BEGIN);
}
protected static $firstWidget = true;

public function run()
{
Expand All @@ -102,17 +96,22 @@ public function run()
}
}

$arguments = http_build_query([
'hl' => $this->getLanguageSuffix(),
'render' => 'explicit',
'onload' => 'recaptchaOnloadCallback',
]);

$view = $this->view;
$view->registerJsFile(
self::JS_API_URL . '?' . $arguments,
['position' => $view::POS_END, 'async' => true, 'defer' => true]
);
if (self::$firstWidget) {
$view = $this->view;
$arguments = http_build_query([
'hl' => $this->getLanguageSuffix(),
'render' => 'explicit',
'onload' => 'recaptchaOnloadCallback',
]);
$view->registerJsFile(
self::JS_API_URL . '?' . $arguments,
['position' => $view::POS_END, 'async' => true, 'defer' => true]
);

$view->registerJs($this->render('onload'), $view::POS_BEGIN);

self::$firstWidget = false;
}

$this->customFieldPrepare();
echo Html::tag('div', '', $this->buildDivOptions());
Expand Down

0 comments on commit 64daf4d

Please sign in to comment.