mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-12-04 20:48:31 +00:00
a8c5016096
* eslint-config-wikimedia: 0.27.0 → 0.28.0 The following rules are failing and were disabled: * ReCaptchaNoCaptcha/resources/ve-confirmedit-reCaptchaNoCaptcha: * no-jquery/no-extend * Turnstile/resources/ve-confirmedit-turnstile: * no-jquery/no-extend * hCaptcha/resources/ve-confirmedit-hCaptcha: * no-jquery/no-extend * grunt-stylelint: 0.19.0 → 0.20.0 * stylelint-config-wikimedia: 0.16.1 → 0.17.1 Change-Id: I8045a843b3e9b6a67e07d580ce07dc6afeaeab2d
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
/* eslint-disable no-jquery/no-global-selector */
|
|
$( document ).on( 'click', '.fancycaptcha-reload', function () {
|
|
const $this = $( this ),
|
|
$root = $this.closest( '.fancycaptcha-captcha-container' ),
|
|
$captchaImage = $root.find( '.fancycaptcha-image' );
|
|
|
|
$this.addClass( 'fancycaptcha-reload-loading' );
|
|
|
|
// AJAX request to get captcha index key
|
|
new mw.Api().post( { action: 'fancycaptchareload' } ).done( ( data ) => {
|
|
const captchaIndex = data.fancycaptchareload.index;
|
|
let imgSrc;
|
|
if ( typeof captchaIndex === 'string' ) {
|
|
// replace index key with a new one for captcha image
|
|
imgSrc = $captchaImage.attr( 'src' ).replace( /(wpCaptchaId=)\w+/, '$1' + captchaIndex );
|
|
$captchaImage.attr( 'src', imgSrc );
|
|
|
|
// replace index key with a new one for hidden tag
|
|
$( '#mw-input-captchaId' ).val( captchaIndex );
|
|
$( '#mw-input-captchaWord' ).val( '' ).trigger( 'focus' );
|
|
|
|
// now do the same with a selector that works for pre-1.27 login forms
|
|
$root.find( '[name="wpCaptchaId"]' ).val( captchaIndex );
|
|
$root.find( '[name="wpCaptchaWord"]' ).val( '' ).trigger( 'focus' );
|
|
|
|
// and make it accessible for other tools, e.g. VisualEditor
|
|
$captchaImage.data( 'captchaId', captchaIndex );
|
|
}
|
|
} )
|
|
.always( () => {
|
|
$this.removeClass( 'fancycaptcha-reload-loading' );
|
|
} );
|
|
|
|
return false;
|
|
} );
|