Index: recaptcha/js/recaptcha.invisible.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- recaptcha/js/recaptcha.invisible.js (date 1489595402000) +++ recaptcha/js/recaptcha.invisible.js (revision ) @@ -1,1 +1,58 @@ +/** + * @file + * Invisible reCaptcha behaviors. + */ + +/** + * ID of the form. + * + * @type {string} + */ + +var submittedFormId = ''; +/** + * reCaptcha data-callback that submits the form. + * + * @param token + * The validation token. + */ +function onInvisibleSubmit(token) { + document.getElementById(submittedFormId).submit(); +} + +(function ($) { + /** + * Handles the submission of the form with the invisible reCaptcha. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches the behavior for the invisible reCaptcha. + */ + + Drupal.behaviors.invisibleRecaptcha = { + attach: function(context, settings) { + $('form', context).each(function () { + var $form = $(this); + + if ($form.find('.g-recaptcha[data-size="invisible"]').length) { + $form.find('input[type="submit"]').click(function (e) { + e.preventDefault(); + validateInvisibleCaptcha($form); + }); + } + }); + + /** + * Triggers the reCaptcha to validate the form. + * + * @param {jQuery} $form + * The form object to be validated. + */ + function validateInvisibleCaptcha($form) { + submittedFormId = $form.attr('id'); + grecaptcha.execute(); + } + } + }; +})(jQuery); \ No newline at end of file Index: recaptcha/recaptcha.admin.inc IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- recaptcha/recaptcha.admin.inc (date 1489595402000) +++ recaptcha/recaptcha.admin.inc (revision ) @@ -62,9 +62,26 @@ '#options' => array( '' => t('Normal (default)'), 'compact' => t('Compact'), + 'invisible' => t('Invisible'), ), '#title' => t('Size'), '#type' => 'select', + ); + $form['recaptcha_widget_settings']['recaptcha_badge'] = array( + '#default_value' => variable_get('recaptcha_badge', 'bottomright'), + '#description' => t('Reposition the reCAPTCHA badge. "Inline" allows you to control the CSS.'), + '#options' => array( + 'bottomright' => t('Bottom Right (default)'), + 'bottomleft' => t('Bottom Left'), + 'inline' => t('Inline'), + ), + '#title' => t('Badge'), + '#type' => 'select', + '#states' => array( + 'visible' => array( + ':input[name="recaptcha_size"]' => array('value' => 'invisible'), + ), + ), ); $form['recaptcha_widget_settings']['recaptcha_tabindex'] = array( '#type' => 'textfield', Index: recaptcha/recaptcha.module IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- recaptcha/recaptcha.module (date 1489595402000) +++ recaptcha/recaptcha.module (revision ) @@ -108,6 +108,16 @@ 'data-size' => variable_get('recaptcha_size', ''), 'data-tabindex' => variable_get('recaptcha_tabindex', 0), ); + + if (variable_get('recaptcha_size', '') == 'invisible') { + $attributes['data-callback'] = 'onInvisibleSubmit'; + $attributes['data-badge'] = variable_get('recaptcha_badge', 'bottomright'); + + $captcha['form']['#attached']['js'] = array( + drupal_get_path('module', 'recaptcha') . '/js/recaptcha.invisible.js', + ); + } + // Filter out empty tabindex/size. $attributes = array_filter($attributes);