2 * JavaScript for Create account form (Special:UserLogin?type=signup).
5 // When sending password by email, hide the password input fields.
6 // This function doesn't need to be loaded early by ResourceLoader, but is tiny.
7 function hidePasswordOnEmail() {
8 // Always required if checked, otherwise it depends, so we use the original
9 var $emailLabel = $( 'label[for="wpEmail"]' ),
10 originalText = $emailLabel.text(),
11 requiredText = mw.message( 'createacct-emailrequired' ).text(),
12 $createByMailCheckbox = $( '#wpCreateaccountMail' ),
13 $beforePwds = $( '.mw-row-password:first' ).prev(),
16 function updateForCheckbox() {
17 var checked = $createByMailCheckbox.prop( 'checked' );
19 $pwds = $( '.mw-row-password' ).detach();
20 $emailLabel.text( requiredText );
23 $beforePwds.after( $pwds );
26 $emailLabel.text( originalText );
30 $createByMailCheckbox.on( 'change', updateForCheckbox );
34 // Move the FancyCaptcha image into a more attractive container.
35 // This function does need to be run early by ResourceLoader.
36 function adjustFancyCaptcha( $content, buttonSubmit ) {
37 var $submit = $content.find( buttonSubmit ),
40 $captchaImageContainer,
41 // JavaScript can't yet parse the message createacct-imgcaptcha-help when it
42 // contains a MediaWiki transclusion, so PHP parses it and sends the HTML.
43 helpMsg = mw.config.get( 'wgCreateacctImgcaptchaHelp' ),
48 * The CAPTCHA is in a div style="captcha" at the top of the form.
49 * If it's a FancyCaptcha, then we remove it and insert it lower down,
50 * in a customized div with just what we need (e.g. no
51 * fancycaptcha-createaccount message).
53 if ( !$submit.length) {
56 tabIndex = $submit.prop( 'tabindex' ) - 1;
57 $captchaStuff = $content.find ( '.captcha' );
59 if ( $captchaStuff.length ) {
61 // The FancyCaptcha has this class in the ConfirmEdit extension
63 $captchaImageContainer = $captchaStuff.find( '.fancycaptcha-image-container' );
64 if ( $captchaImageContainer.length !== 1 ) {
68 $captchaStuff.remove();
71 helpHtml = '<small class="mw-createacct-captcha-assisted">' + helpMsg + '</small>';
74 // Insert another div before the submit button that will include the
75 // repositioned FancyCaptcha div, an input field, and possible help.
76 $submit.closest( 'div' )
79 '<label for="wpCaptchaWord">' + mw.message( 'createacct-captcha' ).escaped() + '</label>',
80 '<div class="mw-createacct-captcha-container">',
81 '<div class="mw-createacct-captcha-and-reload" />',
82 '<input id="wpCaptchaWord" name="wpCaptchaWord" type="text" placeholder="' +
83 mw.message( 'createacct-imgcaptcha-ph' ).escaped() +
84 '" tabindex="' + tabIndex + '" autocapitalize="off" autocorrect="off">',
91 // Stick the FancyCaptcha container inside our bordered and framed parents.
92 $captchaImageContainer
93 .prependTo( $content.find( '.mw-createacct-captcha-and-reload' ) );
95 // Find the input field, add the text (if any) of the existing CAPTCHA
96 // field (although usually it's blanked out on every redisplay),
97 // and after it move over the hidden field that tells the CAPTCHA
99 $content.find( '#wpCaptchaWord' )
100 .val( $captchaStuff.find( '#wpCaptchaWord' ).val() )
101 .after( $captchaStuff.find( '#wpCaptchaId' ) );
106 // Checks if the current page is Special:UserLogin
108 $content = $( '#mw-content-text' ),
109 buttonSubmit = '#wpCreateaccount';
111 if ( $content.find( buttonSubmit ).length === 0 ) {
112 buttonSubmit = '#wpLoginAttempt';
116 adjustFancyCaptcha( $content, buttonSubmit );
119 hidePasswordOnEmail();
124 }( mediaWiki, jQuery ) );