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