2 * JavaScript for Special:ChangeEmail
6 * Given an email validity status (true, false, null) update the label CSS class
8 var updateMailValidityLabel = function( mail
) {
9 var isValid
= mw
.util
.validateEmail( mail
),
10 $label
= $( '#mw-emailaddress-validity' );
12 // We allow empty address
13 if( isValid
=== null ) {
14 $label
.text( '' ).removeClass( 'valid invalid' );
17 } else if ( isValid
) {
18 $label
.text( mw
.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
22 $label
.text( mw
.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
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>' );
33 updateMailValidityLabel( $(this).val() );
34 $(this).keyup( function() {
35 updateMailValidityLabel( $(this).val() );
38 } )( jQuery
, mediaWiki
);