2 * JavaScript for Create account form (Special:UserLogin?type=signup).
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 // Always required if checked, otherwise it depends, so we use the original
10 var $emailLabel = $( 'label[for="wpEmail"]' ),
11 originalText = $emailLabel.text(),
12 requiredText = mw.message( 'createacct-emailrequired' ).text(),
13 $createByMailCheckbox = $( '#wpCreateaccountMail' ),
14 $beforePwds = $( '.mw-row-password:first' ).prev(),
17 function updateForCheckbox() {
18 var checked = $createByMailCheckbox.prop( 'checked' );
20 $pwds = $( '.mw-row-password' ).detach();
21 $emailLabel.text( requiredText );
24 $beforePwds.after( $pwds );
27 $emailLabel.text( originalText );
31 $createByMailCheckbox.on( 'change', updateForCheckbox );
35 // Move the FancyCaptcha image into a more attractive container.
36 // This function does need to be run early by ResourceLoader.
37 function adjustFancyCaptcha() {
38 var $content = $( '#mw-content-text' ),
39 $submit = $content.find( '#wpCreateaccount' ),
42 $captchaImageContainer,
43 // JavaScript can't yet parse the message createacct-imgcaptcha-help when it
44 // contains a MediaWiki transclusion, so PHP parses it and sends the HTML.
45 helpMsg = mw.config.get( 'wgCreateacctImgcaptchaHelp' ),
50 * The CAPTCHA is in a div style="captcha" at the top of the form.
51 * If it's a FancyCaptcha, then we remove it and insert it lower down,
52 * in a customized div with just what we need (e.g. no
53 * fancycaptcha-createaccount message).
55 if ( !$submit.length) {
58 tabIndex = $submit.prop( 'tabindex' ) - 1;
59 $captchaStuff = $content.find ( '.captcha' );
61 if ( $captchaStuff.length ) {
63 // The FancyCaptcha has this class in the ConfirmEdit extension
65 $captchaImageContainer = $captchaStuff.find( '.fancycaptcha-image-container' );
66 if ( $captchaImageContainer.length !== 1 ) {
70 $captchaStuff.remove();
73 helpHtml = '<small class="mw-createacct-captcha-assisted">' + helpMsg + '</small>';
76 // Insert another div before the submit button that will include the
77 // repositioned FancyCaptcha div, an input field, and possible help.
78 $submit.closest( 'div' )
81 '<label for="wpCaptchaWord">' + mw.message( 'createacct-captcha' ).escaped() + '</label>',
82 '<div class="mw-createacct-captcha-container">',
83 '<div class="mw-createacct-captcha-and-reload" />',
84 '<input id="wpCaptchaWord" name="wpCaptchaWord" type="text" placeholder="' +
85 mw.message( 'createacct-imgcaptcha-ph' ).escaped() +
86 '" tabindex="' + tabIndex + '" autocapitalize="off" autocorrect="off">',
93 // Stick the FancyCaptcha container inside our bordered and framed parents.
94 $captchaImageContainer
95 .prependTo( $content.find( '.mw-createacct-captcha-and-reload' ) );
97 // Find the input field, add the text (if any) of the existing CAPTCHA
98 // field (although usually it's blanked out on every redisplay),
99 // and after it move over the hidden field that tells the CAPTCHA
101 $content.find( '#wpCaptchaWord' )
102 .val( $captchaStuff.find( '#wpCaptchaWord' ).val() )
103 .after( $captchaStuff.find( '#wpCaptchaId' ) );
108 adjustFancyCaptcha();
109 hidePasswordOnEmail();
112 }( mediaWiki, jQuery ) );