2013-01-17 02:00:09 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
var api = new mw.Api();
|
|
|
|
$( document ).on( 'click', '.fancycaptcha-reload', function () {
|
2013-04-26 23:34:30 +00:00
|
|
|
var $this = $( this ), $captchaImage;
|
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
|
|
|
|
2013-04-26 23:34:30 +00:00
|
|
|
$captchaImage = $( '.fancycaptcha-image' );
|
2013-01-17 02:00:09 +00:00
|
|
|
|
|
|
|
// 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
|
2013-04-26 23:34:30 +00:00
|
|
|
imgSrc = $captchaImage.attr( 'src' )
|
2013-01-17 02:00:09 +00:00
|
|
|
.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
|
|
|
|
$( '#wpCaptchaId' ).val( captchaIndex );
|
|
|
|
$( '#wpCaptchaWord' ).val( '' ).focus();
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.always( function () {
|
2013-04-26 23:34:30 +00:00
|
|
|
$this.removeClass( 'fancycaptcha-reload-loading' );
|
2013-01-17 02:00:09 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
} )( jQuery, mediaWiki );
|