Merge "Revert "Setting up a way to have uploading by URL, but not on Special:Upload""
[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 function updateMailValidityLabel( 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 $( document ).ready( function () {
28 // Lame tip to let user know if its email is valid. See bug 22449
29 // Only bind once for 'blur' so that the user can fill it in without errors
30 // After that look at every keypress for direct feedback if it was invalid onblur
31 $( '#wpNewEmail' ).one( 'blur', function () {
32 if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
33 $(this).after( '<label for="wpNewEmail" id="mw-emailaddress-validity"></label>' );
34 }
35 updateMailValidityLabel( $(this).val() );
36 $(this).keyup( function () {
37 updateMailValidityLabel( $(this).val() );
38 } );
39 } );
40 } );
41
42 }( mediaWiki, jQuery ) );