traversal indention. Follow-up r79924
[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 /**
44 * Given an email validity status (true, false, null) update the label CSS class
45 */
46 var updateMailValidityLabel = function( mail ) {
47 var isValid = mw.util.validateEmail( mail ),
48 $label = $( '#mw-emailaddress-validity' );
49
50 // We allow empty address
51 if( isValid === null ) {
52 $label.text( '' ).removeClass( 'valid invalid' );
53
54 // Valid
55 } else if ( isValid ) {
56 $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
57
58 // Not valid
59 } else {
60 $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
61 }
62 };
63
64 // Lame tip to let user know if its email is valid. See bug 22449
65 // Only bind once for 'blur' so that the user can fill it in without errors
66 // After that look at every keypress for direct feedback if it was invalid onblur
67 $( '#mw-input-wpemailaddress' ).one( 'blur', function() {
68 if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
69 $(this).after( '<label for="mw-input-wpemailaddress" id="mw-emailaddress-validity"></label>' );
70 }
71 updateMailValidityLabel( $(this).val() );
72 $(this).keyup( function() {
73 updateMailValidityLabel( $(this).val() );
74 } );
75 } );