2 * JavaScript for Special:ChangeEmail
6 * Given an email validity status (true, false, null) update the label CSS class
10 function updateMailValidityLabel( mail
) {
11 var isValid
= mw
.util
.validateEmail( mail
),
12 $label
= $( '#mw-emailaddress-validity' );
14 // Set up the validity notice if it doesn't already exist
15 if ( $label
.length
=== 0 ) {
16 $label
= $( '<label for="wpNewEmail" id="mw-emailaddress-validity"></label>' )
17 .insertAfter( '#wpNewEmail' );
20 // We allow empty address
21 if ( isValid
=== null ) {
22 $label
.text( '' ).removeClass( 'valid invalid' );
25 } else if ( isValid
) {
26 $label
.text( mw
.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
30 $label
.text( mw
.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
36 // Lame tip to let user know if its email is valid. See bug 22449.
37 // Only bind once for 'blur' so that the user can fill it in without errors;
38 // after that, look at every keypress for immediate feedback.
39 .one( 'blur', function () {
40 var $this = $( this );
41 updateMailValidityLabel( $this.val() );
42 $this.keyup( function () {
43 updateMailValidityLabel( $this.val() );
46 // Supress built-in validation notice and just call updateMailValidityLabel(),
47 // to avoid double notice. See bug 40909.
48 .on( 'invalid', function ( e
) {
50 updateMailValidityLabel( $( this ).val() );
53 }( mediaWiki
, jQuery
) );