mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-12-18 02:41:01 +00:00
9ef3132dce
Change-Id: I1e6c500b8a79f8d01b3050dabdece36e77d17706
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
/* eslint-disable no-jquery/no-global-selector */
|
|
$( document ).on( 'click', '.fancycaptcha-reload', function () {
|
|
var $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( function ( data ) {
|
|
var captchaIndex = data.fancycaptchareload.index,
|
|
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' );
|
|
}
|
|
} )
|
|
.always( function () {
|
|
$this.removeClass( 'fancycaptcha-reload-loading' );
|
|
} );
|
|
|
|
return false;
|
|
} );
|