Blank some new Create account messages by default
[lhc/web/wiklou.git] / resources / mediawiki.special / mediawiki.special.createAccount.vform.js
1 /**
2 * JavaScript for Create account form (Special:UserLogin?type=signup).
3 */
4 ( function ( mw, $ ) {
5
6 $( document ).ready( function( $ ) {
7 var $content = $( '#mw-content-text' ),
8 $submit = $content.find( '#wpCreateaccount' ),
9 tabIndex,
10 $captchaStuff,
11 $captchaImageContainer,
12 // JavaScript can't yet parse the message createacct-imgcaptcha-help when it
13 // contains a MediaWiki transclusion, so PHP parses it and sends the HTML.
14 helpMsg = mw.config.get( 'wgCreateacctImgcaptchaHelp' ),
15 helpHtml = '';
16
17 /*
18 * CAPTCHA
19 * The CAPTCHA is in a div style="captcha" at the top of the form.
20 * If it's a FancyCaptcha, then we remove it and insert it lower down,
21 * in a customized div with just what we need (e.g. no
22 * fancycaptcha-createaccount message).
23 */
24 if ( !$submit.length) {
25 return;
26 }
27 tabIndex = $submit.prop( 'tabindex' ) - 1;
28 $captchaStuff = $content.find ( '.captcha' );
29
30 if ( $captchaStuff.length ) {
31
32 // The FancyCaptcha has this class in the ConfirmEdit extension
33 // after 2013-04-18.
34 $captchaImageContainer = $captchaStuff.find( '.fancycaptcha-image-container' );
35 if ( $captchaImageContainer.length !== 1 ) {
36 return;
37 }
38
39 $captchaStuff.remove();
40
41 if ( helpMsg) {
42 helpHtml = '<small class="mw-createacct-captcha-assisted">' + helpMsg + '</small>';
43 }
44
45 // Insert another div before the submit button that will include the
46 // repositioned FancyCaptcha div, an input field, and possible help.
47 $submit.closest( 'div' )
48 .before( [
49 '<div>',
50 '<label for="wpCaptchaWord">' + mw.message( 'createacct-captcha' ).escaped() + '</label>',
51 '<div class="mw-createacct-captcha-container">',
52 '<div class="mw-createacct-captcha-and-reload" />',
53 '<input id="wpCaptchaWord" name="wpCaptchaWord" type="text" placeholder="' +
54 mw.message( 'createacct-imgcaptcha-ph' ).escaped() +
55 '" tabindex="' + tabIndex + '" autocapitalize="off" autocorrect="off">',
56 helpHtml,
57 '</div>',
58 '</div>'
59 ].join( '' )
60 );
61
62 // Stick the FancyCaptcha container inside our bordered and framed parents.
63 $captchaImageContainer
64 .prependTo( $content.find( '.mw-createacct-captcha-and-reload' ) );
65
66 // Find the input field, add the text (if any) of the existing CAPTCHA
67 // field (although usually it's blanked out on every redisplay),
68 // and after it move over the hidden field that tells the CAPTCHA
69 // what to do.
70 $content.find( '#wpCaptchaWord' )
71 .val( $captchaStuff.find( '#wpCaptchaWord' ).val() )
72 .after( $captchaStuff.find( '#wpCaptchaId' ) );
73 }
74
75 } );
76
77 }( mediaWiki, jQuery ) );