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