2 * JavaScript for Special:ChangeEmail
6 * Given an email validity status (true, false, null) update the label CSS class
8 function updateMailValidityLabel( 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 $( document
).ready( function () {
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 immediate feedback.
30 $( '#wpNewEmail' ).one( 'blur', function () {
31 var $this = $( this );
32 if ( $( '#mw-emailaddress-validity' ).length
=== 0 ) {
33 $this.after( '<label for="wpNewEmail" id="mw-emailaddress-validity"></label>' );
36 updateMailValidityLabel( $this.val() );
37 $this.keyup( function () {
38 updateMailValidityLabel( $this.val() );
42 }( mediaWiki
, jQuery
) );