mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-15 03:35:15 +00:00
843620632a
There can be more then one CAPTCHA on the page in AJAX scenarios, so it's important one reload not affect separate CAPTCHAs. Also, drop the legacy createacct naming, except for the one that is actually specific to CreateAccount. The following patch must be merged immediately after this: * Core - I8924d537cad3e39adace99fb20626247128d9bd9 Change-Id: I0e55a159efd66a73cd217d9a5e86b2bced90f57a
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
( function ( $, mw ) {
|
|
var api = new mw.Api();
|
|
$( document ).on( 'click', '.fancycaptcha-reload', function () {
|
|
var $this = $( this ), $root, $captchaImage;
|
|
|
|
$root = $this.closest( '.fancycaptcha-captcha-container' );
|
|
|
|
$this.addClass( 'fancycaptcha-reload-loading' );
|
|
|
|
$captchaImage = $root.find( '.fancycaptcha-image' );
|
|
|
|
// AJAX request to get captcha index key
|
|
api.post( {
|
|
action: 'fancycaptchareload',
|
|
format: 'xml'
|
|
}, {
|
|
dataType: 'xml'
|
|
} )
|
|
.done( function ( xmldata ) {
|
|
var imgSrc, captchaIndex;
|
|
|
|
captchaIndex = $( xmldata ).find( 'fancycaptchareload' ).attr( 'index' );
|
|
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
|
|
$root.find( '[name="wpCaptchaId"]' ).val( captchaIndex );
|
|
$root.find( '[name="wpCaptchaWord"]' ).val( '' ).focus();
|
|
}
|
|
} )
|
|
.always( function () {
|
|
$this.removeClass( 'fancycaptcha-reload-loading' );
|
|
} );
|
|
|
|
return false;
|
|
} );
|
|
} )( jQuery, mediaWiki );
|