Fixed return type of getContentNamespaces()
[mediawiki.git] / resources / mediawiki.special / mediawiki.special.createAccount.js
blobaa61a1eca2f239eb5ccce3447a94ba5c6dd4e394
1 /**
2  * JavaScript for Create account form (Special:UserLogin?type=signup).
3  */
4 ( function ( mw, $ ) {
6         // When sending password by email, hide the password input fields.
7         // This function doesn't need to be loaded early by ResourceLoader, but is tiny.
8         function hidePasswordOnEmail( $ ) {
9                 $( '#wpCreateaccountMail' )
10                         .on( 'change', function() {
11                                 $( '.mw-row-password' ).toggle( !$( this ).attr( 'checked' ) );
12                         } )
13                         .trigger( 'change' );
14         }
16         // Move the FancyCaptcha image into a more attractive container.
17         // This function does need to be run early by ResourceLoader.
18         function adjustFancyCaptcha( $, mw ) {
19                 var $content = $( '#mw-content-text' ),
20                         $submit = $content.find( '#wpCreateaccount' ),
21                         tabIndex,
22                         $captchaStuff,
23                         $captchaImageContainer,
24                         // JavaScript can't yet parse the message createacct-imgcaptcha-help when it
25                         // contains a MediaWiki transclusion, so PHP parses it and sends the HTML.
26                         helpMsg = mw.config.get( 'wgCreateacctImgcaptchaHelp' ),
27                         helpHtml = '';
29                 /*
30                  * CAPTCHA
31                  * The CAPTCHA is in a div style="captcha" at the top of the form.
32                  * If it's a FancyCaptcha, then we remove it and insert it lower down,
33                  * in a customized div with just what we need (e.g. no
34                  * fancycaptcha-createaccount message).
35                  */
36                 if ( !$submit.length) {
37                         return;
38                 }
39                 tabIndex = $submit.prop( 'tabindex' ) - 1;
40                 $captchaStuff = $content.find ( '.captcha' );
42                 if ( $captchaStuff.length ) {
44                         // The FancyCaptcha has this class in the ConfirmEdit extension
45                         // after 2013-04-18.
46                         $captchaImageContainer = $captchaStuff.find( '.fancycaptcha-image-container' );
47                         if ( $captchaImageContainer.length !== 1 ) {
48                                 return;
49                         }
51                         $captchaStuff.remove();
53                         if ( helpMsg) {
54                                 helpHtml = '<small class="mw-createacct-captcha-assisted">' + helpMsg + '</small>';
55                         }
57                         // Insert another div before the submit button that will include the
58                         // repositioned FancyCaptcha div, an input field, and possible help.
59                         $submit.closest( 'div' )
60                                 .before( [
61                         '<div>',
62                                 '<label for="wpCaptchaWord">' + mw.message( 'createacct-captcha' ).escaped() + '</label>',
63                                 '<div class="mw-createacct-captcha-container">',
64                                         '<div class="mw-createacct-captcha-and-reload" />',
65                                         '<input id="wpCaptchaWord" name="wpCaptchaWord" type="text" placeholder="' +
66                                                 mw.message( 'createacct-imgcaptcha-ph' ).escaped() +
67                                                 '" tabindex="' + tabIndex + '" autocapitalize="off" autocorrect="off">',
68                                                 helpHtml,
69                                 '</div>',
70                         '</div>'
71                                         ].join( '' )
72                                 );
74                         // Stick the FancyCaptcha container inside our bordered and framed parents.
75                         $captchaImageContainer
76                                 .prependTo( $content.find( '.mw-createacct-captcha-and-reload' ) );
78                         // Find the input field, add the text (if any) of the existing CAPTCHA
79                         // field (although usually it's blanked out on every redisplay),
80                         // and after it move over the hidden field that tells the CAPTCHA
81                         // what to do.
82                         $content.find( '#wpCaptchaWord' )
83                                 .val( $captchaStuff.find( '#wpCaptchaWord' ).val() )
84                                 .after( $captchaStuff.find( '#wpCaptchaId' ) );
85                 }
86         }
88         $( document ).ready( function( $ ) {
89                 adjustFancyCaptcha( $, mw);
90                 hidePasswordOnEmail( $ );
91         } );
93 }( mediaWiki, jQuery ) );