Follow-up r92924: move the CSS/JS for e-mail validation to Special:ChangeEmail.
[lhc/web/wiklou.git] / resources / mediawiki.special / mediawiki.special.changeemail.js
1 /*
2 * JavaScript for Special:ChangeEmail
3 */
4 ( function( $, mw ) {
5 /**
6 * Given an email validity status (true, false, null) update the label CSS class
7 */
8 var updateMailValidityLabel = function( mail ) {
9 var isValid = mw.util.validateEmail( mail ),
10 $label = $( '#mw-emailaddress-validity' );
11
12 // We allow empty address
13 if( isValid === null ) {
14 $label.text( '' ).removeClass( 'valid invalid' );
15
16 // Valid
17 } else if ( isValid ) {
18 $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
19
20 // Not valid
21 } else {
22 $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
23 }
24 };
25
26 // Lame tip to let user know if its email is valid. See bug 22449
27 // Only bind once for 'blur' so that the user can fill it in without errors
28 // After that look at every keypress for direct feedback if it was invalid onblur
29 $( '#wpNewEmail' ).one( 'blur', function() {
30 if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
31 $(this).after( '<label for="wpNewEmail" id="mw-emailaddress-validity"></label>' );
32 }
33 updateMailValidityLabel( $(this).val() );
34 $(this).keyup( function() {
35 updateMailValidityLabel( $(this).val() );
36 } );
37 } );
38 } )( jQuery, mediaWiki );