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' );
15 function updateForCheckbox() {
16 var checked = $createByMailCheckbox.prop( 'checked' );
18 $( '.mw-row-password' ).hide();
19 $emailLabel.text( requiredText );
21 $( '.mw-row-password' ).show();
22 $emailLabel.text( originalText );
26 $createByMailCheckbox.on( 'change', updateForCheckbox );
30 // Move the FancyCaptcha image into a more attractive container.
31 // This function does need to be run early by ResourceLoader.
32 function adjustFancyCaptcha( $, mw ) {
33 var $content = $( '#mw-content-text' ),
34 $submit = $content.find( '#wpCreateaccount' ),
37 $captchaImageContainer,
38 // JavaScript can't yet parse the message createacct-imgcaptcha-help when it
39 // contains a MediaWiki transclusion, so PHP parses it and sends the HTML.
40 helpMsg = mw.config.get( 'wgCreateacctImgcaptchaHelp' ),
45 * The CAPTCHA is in a div style="captcha" at the top of the form.
46 * If it's a FancyCaptcha, then we remove it and insert it lower down,
47 * in a customized div with just what we need (e.g. no
48 * fancycaptcha-createaccount message).
50 if ( !$submit.length) {
53 tabIndex = $submit.prop( 'tabindex' ) - 1;
54 $captchaStuff = $content.find ( '.captcha' );
56 if ( $captchaStuff.length ) {
58 // The FancyCaptcha has this class in the ConfirmEdit extension
60 $captchaImageContainer = $captchaStuff.find( '.fancycaptcha-image-container' );
61 if ( $captchaImageContainer.length !== 1 ) {
65 $captchaStuff.remove();
68 helpHtml = '<small class="mw-createacct-captcha-assisted">' + helpMsg + '</small>';
71 // Insert another div before the submit button that will include the
72 // repositioned FancyCaptcha div, an input field, and possible help.
73 $submit.closest( 'div' )
76 '<label for="wpCaptchaWord">' + mw.message( 'createacct-captcha' ).escaped() + '</label>',
77 '<div class="mw-createacct-captcha-container">',
78 '<div class="mw-createacct-captcha-and-reload" />',
79 '<input id="wpCaptchaWord" name="wpCaptchaWord" type="text" placeholder="' +
80 mw.message( 'createacct-imgcaptcha-ph' ).escaped() +
81 '" tabindex="' + tabIndex + '" autocapitalize="off" autocorrect="off">',
88 // Stick the FancyCaptcha container inside our bordered and framed parents.
89 $captchaImageContainer
90 .prependTo( $content.find( '.mw-createacct-captcha-and-reload' ) );
92 // Find the input field, add the text (if any) of the existing CAPTCHA
93 // field (although usually it's blanked out on every redisplay),
94 // and after it move over the hidden field that tells the CAPTCHA
96 $content.find( '#wpCaptchaWord' )
97 .val( $captchaStuff.find( '#wpCaptchaWord' ).val() )
98 .after( $captchaStuff.find( '#wpCaptchaId' ) );
102 $( document ).ready( function( $ ) {
103 adjustFancyCaptcha( $, mw);
104 hidePasswordOnEmail( $ );
107 }( mediaWiki, jQuery ) );