1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-04 15:57:45 +02:00

Merge branch '3.3.x'

This commit is contained in:
Marc Alexander
2020-04-29 21:52:01 +02:00
9 changed files with 641 additions and 39 deletions

View File

@@ -1744,49 +1744,81 @@ phpbb.lazyLoadAvatars = function loadAvatars() {
});
};
var recaptchaForm = $('.g-recaptcha').parents('form');
var submitButton = null;
var programaticallySubmitted = false;
phpbb.recaptcha = {
button: null,
ready: 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;
token: $('input[name="recaptcha_token"]'),
form: $('.g-recaptcha').parents('form'),
v3: $('[data-recaptcha-v3]'),
load: function() {
phpbb.recaptcha.bindButton();
phpbb.recaptcha.bindForm();
},
bindButton: function() {
phpbb.recaptcha.form.find('input[type="submit"]').on('click', function() {
// Listen to all the submit buttons for the form that has reCAPTCHA protection,
// and store it so we can click the exact same button later on when we are ready.
phpbb.recaptcha.button = this;
});
});
},
bindForm: function() {
phpbb.recaptcha.form.on('submit', function(e) {
// If ready is false, it means the user pressed a submit button.
// And the form was not submitted by us, after the token was loaded.
if (!phpbb.recaptcha.ready) {
// If version 3 is used, we need to make a different execution,
// including the action and the site key.
if (phpbb.recaptcha.v3.length) {
grecaptcha.execute(
phpbb.recaptcha.v3.data('recaptcha-v3'),
{action: phpbb.recaptcha.v3.val()}
).then(function(token) {
// Place the token inside the form
phpbb.recaptcha.token.val(token);
recaptchaForm.on('submit', function (e) {
if (!programaticallySubmitted) {
grecaptcha.execute();
e.preventDefault();
}
});
}
// And now we submit the form.
phpbb.recaptcha.submitForm();
});
} else {
// Regular version 2 execution
grecaptcha.execute();
}
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';
// Do not submit the form
e.preventDefault();
}
});
},
submitForm: function() {
// Now we are ready, so set it to true.
// so the 'submit' event doesn't run multiple times.
phpbb.recaptcha.ready = true;
if (phpbb.recaptcha.button) {
// If there was a specific button pressed initially, trigger the same button
phpbb.recaptcha.button.click();
} else {
if (typeof phpbb.recaptcha.form.submit !== 'function') {
// Rename input[name="submit"] so that we can submit the form
phpbb.recaptcha.form.submit.name = 'submit_btn';
}
phpbb.recaptcha.form.submit();
}
recaptchaForm.submit();
}
}
};
// reCAPTCHA doesn't accept callback functions nested inside objects
// reCAPTCHA v2 doesn't accept callback functions nested inside objects
// so we need to make this helper functions here
window.phpbbRecaptchaOnLoad = function() {
phpbb.recaptchaOnLoad();
}
phpbb.recaptcha.load();
};
window.phpbbRecaptchaOnSubmit = function() {
phpbb.recaptchaOnSubmit();
}
phpbb.recaptcha.submitForm();
};
$(window).on('load', phpbb.lazyLoadAvatars);
@@ -1794,6 +1826,11 @@ $(window).on('load', phpbb.lazyLoadAvatars);
* Apply code editor to all textarea elements with data-bbcode attribute
*/
$(function() {
// reCAPTCHA v3 needs to be initialized
if (phpbb.recaptcha.v3.length) {
phpbb.recaptcha.load();
}
$('textarea[data-bbcode]').each(function() {
phpbb.applyCodeEditor(this);
});