| 1 |
|
| 2 |
$( document ).on( 'click', '.fancycaptcha-reload', function () { |
| 3 |
const $this = $( this ), |
| 4 |
$root = $this.closest( '.fancycaptcha-captcha-container' ), |
| 5 |
$captchaImage = $root.find( '.fancycaptcha-image' ); |
| 6 |
|
| 7 |
$this.addClass( 'fancycaptcha-reload-loading' ); |
| 8 |
|
| 9 |
|
| 10 |
new mw.Api().post( { action: 'fancycaptchareload' } ).done( ( data ) => { |
| 11 |
const captchaIndex = data.fancycaptchareload.index; |
| 12 |
let imgSrc; |
| 13 |
if ( typeof captchaIndex === 'string' ) { |
| 14 |
|
| 15 |
imgSrc = $captchaImage.attr( 'src' ).replace( /(wpCaptchaId=)\w+/, '$1' + captchaIndex ); |
| 16 |
$captchaImage.attr( 'src', imgSrc ); |
| 17 |
|
| 18 |
|
| 19 |
$( '#mw-input-captchaId' ).val( captchaIndex ); |
| 20 |
$( '#mw-input-captchaWord' ).val( '' ).trigger( 'focus' ); |
| 21 |
|
| 22 |
|
| 23 |
$root.find( '[name="wpCaptchaId"]' ).val( captchaIndex ); |
| 24 |
$root.find( '[name="wpCaptchaWord"]' ).val( '' ).trigger( 'focus' ); |
| 25 |
|
| 26 |
|
| 27 |
$captchaImage.data( 'captchaId', captchaIndex ); |
| 28 |
} |
| 29 |
} ) |
| 30 |
.always( () => { |
| 31 |
$this.removeClass( 'fancycaptcha-reload-loading' ); |
| 32 |
} ); |
| 33 |
|
| 34 |
return false; |
| 35 |
} ); |