mediawiki-extensions-Confir.../FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js
Gergő Tisza 69d7524674 Fix FancyCaptcha reload JS
I0da671a5 broke the FancyCaptcha reload script for the old auth
forms, and didn't get it quite right for AuthManager forms either
(that one mostly works but the textfield is not refocused).
This patch fixes both.

Change-Id: I78300a4f6998e63e71e4516331f4f3408b86864b
2016-06-09 21:00:19 +00:00

46 lines
1.3 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
$( '#mw-input-captchaId' ).val( captchaIndex );
$( '#mw-input-captchaWord' ).val( '' ).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( '' ).focus();
}
} )
.always( function () {
$this.removeClass( 'fancycaptcha-reload-loading' );
} );
return false;
} );
} )( jQuery, mediaWiki );