Debian Codegraph @

extensions/ConfirmEdit/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js

raw symbols SCIP
1 /* eslint-disable no-jquery/no-global-selector */
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 // AJAX request to get captcha index key
10 new mw.Api().post( { action: 'fancycaptchareload' } ).done( ( data ) => {
11 const captchaIndex = data.fancycaptchareload.index;
12 let imgSrc;
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 );
17
18 // replace index key with a new one for hidden tag
19 $( '#mw-input-captchaId' ).val( captchaIndex );
20 $( '#mw-input-captchaWord' ).val( '' ).trigger( 'focus' );
21
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( '' ).trigger( 'focus' );
25
26 // and make it accessible for other tools, e.g. VisualEditor
27 $captchaImage.data( 'captchaId', captchaIndex );
28 }
29 } )
30 .always( () => {
31 $this.removeClass( 'fancycaptcha-reload-loading' );
32 } );
33
34 return false;
35 } );