Merge "Fix HTMLForm's documentation example"
[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 helpMsg = mw.config.get( 'wgCreateacctImgcaptchaHelp' ),
12 captchaImage;
13
14 /*
15 * CAPTCHA
16 * The CAPTCHA is in a div style="captcha" at the top of the form.
17 * If it's a FancyCaptcha, then we remove it and insert it lower down,
18 * in a customized div with just what we need (e.g. no
19 * fancycaptcha-createaccount message).
20 */
21 if ( !$submit.length) {
22 return;
23 }
24 tabIndex = $submit.prop( 'tabindex' ) - 1;
25 $captchaStuff = $content.find ( '.captcha' );
26
27 if ( $captchaStuff.length ) {
28
29 // The FancyCaptcha image has this class in the ConfirmEdit extension
30 // after 2013-04-18.
31 captchaImage = $captchaStuff.find( 'img.fancycaptcha-image' );
32 if ( captchaImage.length !== 1 ) {
33 return;
34 }
35
36 $captchaStuff.remove();
37
38 // Insert another div before the submit button.
39 $submit.closest( 'div' )
40 .before( [
41 '<div>',
42 '<label for="wpCaptchaWord">' + mw.message( 'createacct-captcha' ).escaped() + '</label>',
43 '<div class="mw-createacct-captcha-container">',
44 '<div class="mw-createacct-captcha-and-reload">',
45 '<div class="mw-createacct-captcha-image-container">',
46 '<img id="mw-createacct-captcha" alt="PLACEHOLDER">',
47 '</div>',
48 '</div>',
49 '<input id="wpCaptchaWord" name="wpCaptchaWord" type="text" placeholder="' +
50 mw.message( 'createacct-imgcaptcha-ph' ).escaped() +
51 '" tabindex="' + tabIndex + '" autocapitalize="off" autocorrect="off">',
52 '<small class="mw-createacct-captcha-assisted">' + helpMsg + '</small>',
53 '</div>',
54 '</div>'
55 ].join( '' )
56 );
57
58 // Replace the placeholder img with the img from the old CAPTCHA.
59 captchaImage.replaceAll( $content.find( '#mw-createacct-captcha' ) );
60
61 // Append CAPTCHA reload, if any.
62 $( '.mw-createacct-captcha-and-reload' ).append( $captchaStuff.find( '.confirmedit-captcha-reload' ) );
63
64 // Find the input field, add the text (if any) of the existing CAPTCHA
65 // field (although usually it's blanked out on every redisplay),
66 // and after it move over the hidden field that tells the CAPTCHA
67 // what to do.
68 $content.find( '#wpCaptchaWord' )
69 .val( $captchaStuff.find( '#wpCaptchaWord' ).val() )
70 .after( $captchaStuff.find( '#wpCaptchaId' ) );
71 }
72
73 });
74
75 }( mediaWiki, jQuery ) );