mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-28 01:50:18 +00:00
12361c5f31
This adds HTML, CSS, and JS to FancyCaptcha output to refresh the image, which requests it via a new fancycaptchareload API. It also cleans up the Asirra class a little. Bug: 14230 Change-Id: I4e476f32de199534c9798fc78e8490b3ef91dd45
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
( function ( $, mw ) {
|
|
var api = new mw.Api();
|
|
$( document ).on( 'click', '.fancycaptcha-reload', function () {
|
|
var staticImageDirectory = mw.config.get( 'wgExtensionAssetsPath' ) + '/ConfirmEdit/images/',
|
|
$this = $( this ), reloadButtonImage, captchaImage;
|
|
|
|
reloadButtonImage = $this
|
|
.find( '.fancycaptcha-reload-button' )
|
|
.attr( 'src', staticImageDirectory + 'ajax-loader-10x10.gif' );
|
|
|
|
captchaImage = $( '.fancycaptcha-image' );
|
|
|
|
// 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
|
|
imgSrc = captchaImage.attr( 'src' )
|
|
.replace( /(wpCaptchaId=)\w+/, '$1' + captchaIndex );
|
|
captchaImage.attr( 'src', imgSrc );
|
|
|
|
// replace index key with a new one for hidden tag
|
|
$( '#wpCaptchaId' ).val( captchaIndex );
|
|
$( '#wpCaptchaWord' ).val( '' ).focus();
|
|
}
|
|
} )
|
|
.always( function () {
|
|
reloadButtonImage.attr( 'src', staticImageDirectory + 'fancycaptcha-reload-icon.png' );
|
|
} );
|
|
|
|
return false;
|
|
} );
|
|
} )( jQuery, mediaWiki );
|