* Consistent single quotes
[lhc/web/wiklou.git] / resources / mediawiki.special / mediawiki.special.preferences.js
1 /*
2 * JavaScript for Special:Preferences
3 */
4
5 $( '#prefsubmit' ).attr( 'id', 'prefcontrol' );
6 $( '#preferences' )
7 .addClass( 'jsprefs' )
8 .before( $( '<ul id="preftoc"></ul>' ) )
9 .children( 'fieldset' )
10 .hide()
11 .addClass( 'prefsection' )
12 .children( 'legend' )
13 .addClass( 'mainLegend' )
14 .each( function( i ) {
15 $(this).parent().attr( 'id', 'prefsection-' + i );
16 if ( i === 0 ) {
17 $(this).parent().show();
18 }
19 $( '#preftoc' ).append(
20 $( '<li></li>' )
21 .addClass( i === 0 ? 'selected' : null )
22 .append(
23 $( '<a></a>')
24 .text( $(this).text() )
25 .attr( 'href', '#prefsection-' + i )
26 .mousedown( function( e ) {
27 $(this).parent().parent().find( 'li' ).removeClass( 'selected' );
28 $(this).parent().addClass( 'selected' );
29 e.preventDefault();
30 return false;
31 } )
32 .click( function( e ) {
33 $( '#preferences > fieldset' ).hide();
34 $( '#prefsection-' + i ).show();
35 e.preventDefault();
36 return false;
37 } )
38 )
39 );
40 } );
41
42 /**
43 * Given an email validity status (true, false, null) update the label CSS class
44 */
45 var updateMailValidityLabel = function( mail ) {
46 var isValid = mw.util.validateEmail( mail ),
47 $label = $( '#mw-emailaddress-validity' );
48
49 // We allow empty address
50 if( isValid === null ) {
51 $label.text( '' ).removeClass( 'valid invalid' );
52
53 // Valid
54 } else if ( isValid ) {
55 $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
56
57 // Not valid
58 } else {
59 $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
60 }
61 };
62
63 // Lame tip to let user know if its email is valid. See bug 22449
64 // Only bind once for 'blur' so that the user can fill it in without errors
65 // After that look at every keypress for direct feedback if it was invalid onblur
66 $( '#mw-input-wpemailaddress' ).one( 'blur', function() {
67 if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
68 $(this).after( '<label for="mw-input-wpemailaddress" id="mw-emailaddress-validity"></label>' );
69 }
70 updateMailValidityLabel( $(this).val() );
71 $(this).keyup( function() {
72 updateMailValidityLabel( $(this).val() );
73 } );
74 } );