Localisation updates from https://translatewiki.net.
[mediawiki.git] / resources / mediawiki.special / mediawiki.special.changeemail.js
blobbc2a0a2688cba55e356632f16ec5a4ff7fe01f5d
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         function updateMailValidityLabel( mail ) {
9                 var isValid = mw.util.validateEmail( mail ),
10                         $label = $( '#mw-emailaddress-validity' );
12                 // Set up the validity notice if it doesn't already exist
13                 if ( $label.length === 0 ) {
14                         $label = $( '<label for="wpNewEmail" id="mw-emailaddress-validity"></label>' )
15                                 .insertAfter( '#wpNewEmail' );
16                 }
18                 // We allow empty address
19                 if ( isValid === null ) {
20                         $label.text( '' ).removeClass( 'valid invalid' );
22                 // Valid
23                 } else if ( isValid ) {
24                         $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
26                 // Not valid
27                 } else {
28                         $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
29                 }
30         }
32         $( function () {
33                 $( '#wpNewEmail' )
34                         // Lame tip to let user know if its email is valid. See bug 22449.
35                         // Only bind once for 'blur' so that the user can fill it in without errors;
36                         // after that, look at every keypress for immediate feedback.
37                         .one( 'blur', function () {
38                                 var $this = $( this );
39                                 updateMailValidityLabel( $this.val() );
40                                 $this.keyup( function () {
41                                         updateMailValidityLabel( $this.val() );
42                                 } );
43                         } )
44                         // Supress built-in validation notice and just call updateMailValidityLabel(),
45                         // to avoid double notice. See bug 40909.
46                         .on( 'invalid', function ( e ) {
47                                 e.preventDefault();
48                                 updateMailValidityLabel( $( this ).val() );
49                         } );
50         } );
51 }( mediaWiki, jQuery ) );