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