2013-01-17 02:00:09 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
var api = new mw.Api();
|
|
|
|
$( document ).on( 'click', '.fancycaptcha-reload', function () {
|
2015-10-28 19:51:13 +00:00
|
|
|
var $this = $( this ),
|
|
|
|
$root, $captchaImage;
|
2015-10-22 14:46:13 +00:00
|
|
|
|
|
|
|
$root = $this.closest( '.fancycaptcha-captcha-container' );
|
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
|
|
|
|
2015-10-22 14:46:13 +00:00
|
|
|
$captchaImage = $root.find( '.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;
|
2015-10-22 14:46:13 +00:00
|
|
|
|
2013-01-17 02:00:09 +00:00
|
|
|
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
|
2015-10-22 14:46:13 +00:00
|
|
|
$root.find( '[name="wpCaptchaId"]' ).val( captchaIndex );
|
|
|
|
$root.find( '[name="wpCaptchaWord"]' ).val( '' ).focus();
|
2013-01-17 02:00:09 +00:00
|
|
|
}
|
|
|
|
} )
|
|
|
|
.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 );
|