2013-01-17 02:00:09 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
$( document ).on( 'click', '.fancycaptcha-reload', function () {
|
2015-10-28 19:51:13 +00:00
|
|
|
var $this = $( this ),
|
2017-08-29 12:26:42 +00:00
|
|
|
$root = $this.closest( '.fancycaptcha-captcha-container' ),
|
|
|
|
$captchaImage = $root.find( '.fancycaptcha-image' );
|
2013-01-17 02:00:09 +00:00
|
|
|
|
2013-04-26 23:34:30 +00:00
|
|
|
$this.addClass( 'fancycaptcha-reload-loading' );
|
2013-01-17 02:00:09 +00:00
|
|
|
|
|
|
|
// AJAX request to get captcha index key
|
2017-08-29 12:26:42 +00:00
|
|
|
new mw.Api().post( { action: 'fancycaptchareload' } ).done( function ( data ) {
|
|
|
|
var captchaIndex = data.fancycaptchareload.index,
|
|
|
|
imgSrc;
|
2013-01-17 02:00:09 +00:00
|
|
|
if ( typeof captchaIndex === 'string' ) {
|
|
|
|
// replace index key with a new one for captcha image
|
2017-08-29 12:26:42 +00:00
|
|
|
imgSrc = $captchaImage.attr( 'src' ).replace( /(wpCaptchaId=)\w+/, '$1' + captchaIndex );
|
2013-04-26 23:34:30 +00:00
|
|
|
$captchaImage.attr( 'src', imgSrc );
|
2013-01-17 02:00:09 +00:00
|
|
|
|
|
|
|
// replace index key with a new one for hidden tag
|
2016-04-25 20:58:18 +00:00
|
|
|
$( '#mw-input-captchaId' ).val( captchaIndex );
|
2016-06-09 20:59:37 +00:00
|
|
|
$( '#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();
|
2013-01-17 02:00:09 +00:00
|
|
|
}
|
|
|
|
} )
|
2018-02-04 21:22:31 +00:00
|
|
|
.always( function () {
|
|
|
|
$this.removeClass( 'fancycaptcha-reload-loading' );
|
|
|
|
} );
|
2013-01-17 02:00:09 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
} );
|
2017-01-18 12:52:44 +00:00
|
|
|
}( jQuery, mediaWiki ) );
|