2 $( document ).on( 'click', '.fancycaptcha-reload', function () {
4 $root = $this.closest( '.fancycaptcha-captcha-container' ),
5 $captchaImage = $root.find( '.fancycaptcha-image' );
7 $this.addClass( 'fancycaptcha-reload-loading' );
9 // AJAX request to get captcha index key
10 new mw.Api().post( { action: 'fancycaptchareload' } ).done( function ( data ) {
11 var captchaIndex = data.fancycaptchareload.index,
13 if ( typeof captchaIndex === 'string' ) {
14 // replace index key with a new one for captcha image
15 imgSrc = $captchaImage.attr( 'src' ).replace( /(wpCaptchaId=)\w+/, '$1' + captchaIndex );
16 $captchaImage.attr( 'src', imgSrc );
18 // replace index key with a new one for hidden tag
19 $( '#mw-input-captchaId' ).val( captchaIndex );
20 $( '#mw-input-captchaWord' ).val( '' ).focus();
22 // now do the same with a selector that works for pre-1.27 login forms
23 $root.find( '[name="wpCaptchaId"]' ).val( captchaIndex );
24 $root.find( '[name="wpCaptchaWord"]' ).val( '' ).focus();
27 .always( function () {
28 $this.removeClass( 'fancycaptcha-reload-loading' );
33 }( jQuery, mediaWiki ) );