Re-do svn copy from r106516 preserving history
[lhc/web/wiklou.git] / resources / mediawiki.special / mediawiki.special.changeemail.js
1 /*
2 * JavaScript for Special:ChangeEmail
3 */
4 ( function( $, mw ) {
5
6 /**
7 * Given an email validity status (true, false, null) update the label CSS class
8 */
9 var updateMailValidityLabel = function( mail ) {
10 var isValid = mw.util.validateEmail( mail ),
11 $label = $( '#mw-emailaddress-validity' );
12
13 // We allow empty address
14 if( isValid === null ) {
15 $label.text( '' ).removeClass( 'valid invalid' );
16
17 // Valid
18 } else if ( isValid ) {
19 $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
20
21 // Not valid
22 } else {
23 $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
24 }
25 };
26
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 direct feedback if it was invalid onblur
30 $( '#mw-input-wpemailaddress' ).one( 'blur', function() {
31 if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
32 $(this).after( '<label for="mw-input-wpemailaddress" id="mw-emailaddress-validity"></label>' );
33 }
34 updateMailValidityLabel( $(this).val() );
35 $(this).keyup( function() {
36 updateMailValidityLabel( $(this).val() );
37 } );
38 } );
39
40 } )( jQuery, mediaWiki );