]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - extensions/ConfirmEdit/FancyCaptcha/resources/ext.confirmEdit.fancyCaptcha.js
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / extensions / ConfirmEdit / FancyCaptcha / resources / ext.confirmEdit.fancyCaptcha.js
1 ( function ( $, mw ) {
2         $( document ).on( 'click', '.fancycaptcha-reload', function () {
3                 var $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( function ( data ) {
11                         var captchaIndex = data.fancycaptchareload.index,
12                                 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( '' ).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( '' ).focus();
25                         }
26                 } )
27                 .always( function () {
28                         $this.removeClass( 'fancycaptcha-reload-loading' );
29                 } );
30
31                 return false;
32         } );
33 }( jQuery, mediaWiki ) );