2 * JavaScript for login and signup forms.
5 // Move the FancyCaptcha image into a more attractive container.
6 // The CAPTCHA is in a <div class="captcha"> at the top of the form. If it's a FancyCaptcha,
7 // then we remove it and insert it lower down, in a customized div with just what we need (e.g.
8 // no 'fancycaptcha-createaccount' message).
9 function adjustFancyCaptcha( $content, buttonSubmit ) {
10 var $submit = $content.find( buttonSubmit ),
13 $captchaImageContainer,
14 // JavaScript can't yet parse the message 'createacct-imgcaptcha-help' when it
15 // contains a MediaWiki transclusion, so PHP parses it and sends the HTML.
16 // This is only set for the signup form (and undefined for login).
17 helpMsg = mw.config.get( 'wgCreateacctImgcaptchaHelp' ),
20 if ( !$submit.length ) {
23 tabIndex = $submit.prop( 'tabindex' ) - 1;
24 $captchaStuff = $content.find( '.captcha' );
26 if ( $captchaStuff.length ) {
27 // The FancyCaptcha has this class in the ConfirmEdit extension since 2013-04-18.
28 $captchaImageContainer = $captchaStuff.find( '.fancycaptcha-image-container' );
29 if ( $captchaImageContainer.length !== 1 ) {
33 $captchaStuff.remove();
36 helpHtml = '<small class="mw-createacct-captcha-assisted">' + helpMsg + '</small>';
39 // Insert another div before the submit button that will include the
40 // repositioned FancyCaptcha div, an input field, and possible help.
41 $submit.closest( 'div' ).before( [
43 '<label for="wpCaptchaWord">' + mw.message( 'createacct-captcha' ).escaped() + '</label>',
44 '<div class="mw-createacct-captcha-container">',
45 '<div class="mw-createacct-captcha-and-reload" />',
46 '<input id="wpCaptchaWord" class="mw-ui-input" name="wpCaptchaWord" type="text" placeholder="' +
47 mw.message( 'createacct-imgcaptcha-ph' ).escaped() +
48 '" tabindex="' + tabIndex + '" autocapitalize="off" autocorrect="off">',
54 // Stick the FancyCaptcha container inside our bordered and framed parents.
55 $captchaImageContainer
56 .prependTo( $content.find( '.mw-createacct-captcha-and-reload' ) );
58 // Find the input field, add the text (if any) of the existing CAPTCHA
59 // field (although usually it's blanked out on every redisplay),
60 // and after it move over the hidden field that tells the CAPTCHA
62 $content.find( '#wpCaptchaWord' )
63 .val( $captchaStuff.find( '#wpCaptchaWord' ).val() )
64 .after( $captchaStuff.find( '#wpCaptchaId' ) );
69 // Work with both login and signup form
70 adjustFancyCaptcha( $( '#mw-content-text' ), '#wpCreateaccount, #wpLoginAttempt' );
72 }( mediaWiki, jQuery ) );