diff --git a/drupal-recaptcha.js b/drupal-recaptcha.js new file mode 100644 index 0000000..c369c47 --- /dev/null +++ b/drupal-recaptcha.js @@ -0,0 +1,18 @@ +(function ($) { + +Drupal.behaviors.recaptcha = { + attach: function (context, settings) { + $('.drupal-recaptcha', context).each(function() { + if ($(this).hasClass('drupal-recaptcha-processed')) { + grecaptcha.reset(); + } + else { + grecaptcha.render(this, $(this).data()); + $(this).addClass('drupal-recaptcha-processed'); + } + + }); + } +} + +})(jQuery); diff --git a/recaptcha.module b/recaptcha.module index e0e31e6..710a4a4 100644 --- a/recaptcha.module +++ b/recaptcha.module @@ -105,7 +105,7 @@ function recaptcha_captcha($op, $captcha_type = '') { } $attributes = array( - 'class' => 'g-recaptcha', + 'class' => 'drupal-recaptcha', 'data-sitekey' => $recaptcha_site_key, 'data-theme' => variable_get('recaptcha_theme', 'light'), 'data-type' => variable_get('recaptcha_type', 'image'), @@ -117,6 +117,9 @@ function recaptcha_captcha($op, $captcha_type = '') { $captcha['form']['recaptcha_widget'] = array( '#markup' => '', '#suffix' => $noscript, + '#attached' => array( + 'js' => array(drupal_get_path('module', 'recaptcha') . '/drupal-recaptcha.js'), + ), ); // @todo: #1664602: D7 does not yet support "async" in drupal_add_js().