Merge "jquery.makeCollapsible: Only trigger custom events once per collapsible"
[lhc/web/wiklou.git] / resources / mediawiki.special / mediawiki.special.changeemail.js
1 /**
2 * JavaScript for Special:ChangeEmail
3 */
4 ( function ( mw, $ ) {
5 /**
6 * Given an email validity status (true, false, null) update the label CSS class
7 */
8 function updateMailValidityLabel( mail ) {
9 var isValid = mw.util.validateEmail( mail ),
10 $label = $( '#mw-emailaddress-validity' );
11
12 // We allow empty address
13 if ( isValid === null ) {
14 $label.text( '' ).removeClass( 'valid invalid' );
15
16 // Valid
17 } else if ( isValid ) {
18 $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
19
20 // Not valid
21 } else {
22 $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
23 }
24 }
25
26 $( 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>' );
34 }
35
36 updateMailValidityLabel( $this.val() );
37 $this.keyup( function () {
38 updateMailValidityLabel( $this.val() );
39 } );
40 } );
41 } );
42 }( mediaWiki, jQuery ) );