diff options
Diffstat (limited to 'phpBB/assets/javascript')
-rw-r--r-- | phpBB/assets/javascript/core.js | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 5218a8c1be..bb38441622 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1492,7 +1492,7 @@ phpbb.colorPalette = function(dir, width, height) { * @param {jQuery} el jQuery object for the palette container. */ phpbb.registerPalette = function(el) { - var orientation = el.attr('data-orientation'), + var orientation = el.attr('data-color-palette'), height = el.attr('data-height'), width = el.attr('data-width'), target = el.attr('data-target'), @@ -1650,6 +1650,50 @@ phpbb.lazyLoadAvatars = function loadAvatars() { }); }; +var recaptchaForm = $('.g-recaptcha').parents('form'); +var submitButton = null; +var programaticallySubmitted = false; + +phpbb.recaptchaOnLoad = function () { + // Listen to submit buttons in order to know which one was pressed + $('input[type="submit"]').each(function () { + $(this).on('click', function () { + submitButton = this; + }); + }); + + recaptchaForm.on('submit', function (e) { + if (!programaticallySubmitted) { + grecaptcha.execute(); + e.preventDefault(); + } + }); +} + +phpbb.recaptchaOnSubmit = function () { + programaticallySubmitted = true; + // If concrete button was clicked (e.g. preview instead of submit), + // let's trigger the same action + if (submitButton) { + submitButton.click(); + } else { + // Rename input[name="submit"] so that we can submit the form + if (typeof recaptchaForm.submit !== 'function') { + recaptchaForm.submit.name = 'submit_btn'; + } + recaptchaForm.submit(); + } +} + +// reCAPTCHA doesn't accept callback functions nested inside objects +// so we need to make this helper functions here +window.phpbbRecaptchaOnLoad = function() { + phpbb.recaptchaOnLoad(); +} +window.phpbbRecaptchaOnSubmit = function() { + phpbb.recaptchaOnSubmit(); +} + $(window).on('load', phpbb.lazyLoadAvatars); /** @@ -1662,7 +1706,7 @@ $(function() { phpbb.registerPageDropdowns(); - $('[data-orientation]').each(function() { + $('[data-color-palette]').each(function() { phpbb.registerPalette($(this)); }); |