* sry about that :S ... 10x Aaron
[mediawiki.git] / skins / common / config.js
blob23f7302cb8be50b98c2b5f8d488e4cd767d4ac14
1 (function( $ ) {
2         $( document ).ready( function() {
5                 // Set up the help system
6                 $( '.mw-help-field-data' )
7                         .hide()
8                         .closest( '.mw-help-field-container' )
9                                 .find( '.mw-help-field-hint' )
10                                         .show()
11                                         .click( function() {
12                                                 $(this)
13                                                         .closest( '.mw-help-field-container' )
14                                                                 .find( '.mw-help-field-data' )
15                                                                         .slideToggle( 'fast' );
16                                         } );
17                 
18                 // Show/hide code for DB-specific options
19                 // FIXME: Do we want slow, fast, or even non-animated (instantaneous) showing/hiding here?
20                 $( '.dbRadio' ).each( function() { $( '#' + $(this).attr( 'rel' ) ).hide(); } );
21                 $( '#' + $( '.dbRadio:checked' ).attr( 'rel' ) ).show();
22                 $( '.dbRadio' ).click( function() {
23                         var $checked = $( '.dbRadio:checked' );
24                         var $wrapper = $( '#' + $checked.attr( 'rel' ) );
25                         if ( !$wrapper.is( ':visible' ) ) {
26                                 $( '.dbWrapper' ).hide( 'slow' );
27                                 $wrapper.show( 'slow' );
28                         }
29                 } );
30                 
31                 // Scroll to the bottom of upgrade log
32                 $( '#config-live-log' ).find( '> textarea' ).each( function() { this.scrollTop = this.scrollHeight; } );
33                 
34                 // Show/hide Creative Commons thingy
35                 $( '.licenseRadio' ).click( function() {
36                         var $wrapper = $( '#config-cc-wrapper' );
37                         if ( $( '#config__LicenseCode_cc-choose' ).is( ':checked' ) ) {
38                                 $wrapper.show( 'slow' );
39                         } else {
40                                 $wrapper.hide( 'slow' );
41                         }
42                 } );
43                 
44                 // Show/hide random stuff (email, upload)
45                 $( '.showHideRadio' ).click( function() {
46                         var $wrapper = $( '#' + $(this).attr( 'rel' ) );
47                         if ( $(this).is( ':checked' ) ) {
48                                 $wrapper.show( 'slow' );
49                         } else {
50                                 $wrapper.hide( 'slow' );
51                         }
52                 } );
53                 $( '.hideShowRadio' ).click( function() {
54                         var $wrapper = $( '#' + $(this).attr( 'rel' ) );
55                         if ( $(this).is( ':checked' ) ) {
56                                 $wrapper.hide( 'slow' );
57                         } else {
58                                 $wrapper.show( 'slow' );
59                         }
60                 } );
62                 // Hide "other" textboxes by default
63                 // Should not be done in CSS for javascript disabled compatibility
64                 $( '.enabledByOther' ).closest( '.config-block' ).hide();
66                 // Enable/disable "other" textboxes
67                 $( '.enableForOther' ).click( function() {
68                         var $textbox = $( '#' + $(this).attr( 'rel' ) );
69                         if ( $(this).val() == 'other' ) { // FIXME: Ugh, this is ugly
70                                 $textbox.removeProp( 'readonly' ).closest( '.config-block' ).slideDown( 'fast' );
71                         } else {
72                                 $textbox.prop( 'readonly', true ).closest( '.config-block' ).slideUp( 'fast' );
73                         }
74                 } );
75                 
76                 // Synchronize radio button label for sitename with textbox
77                 $label = $( 'label[for=config__NamespaceType_site-name]' );
78                 labelText = $label.text();
79                 $label.text( labelText.replace( '$1', '' ) );
80                 $( '#config_wgSitename' ).bind( 'keyup change', syncText ).each( syncText );
81                 function syncText() {
82                         var value = $(this).val()
83                                 .replace( /[\[\]\{\}|#<>%+? ]/g, '_' )
84                                 .replace( /&/, '&amp;' )
85                                 .replace( /__+/g, '_' )
86                                 .replace( /^_+/, '' )
87                                 .replace( /_+$/, '' );
88                         value = value.substr( 0, 1 ).toUpperCase() + value.substr( 1 );
89                         $label.text( labelText.replace( '$1', value ) );
90                 }
92                 // Show/Hide memcached servers when needed
93                 $("input[name$='config_wgMainCacheType']").change( function() {
94                         var $memc = $( "#config-memcachewrapper" );
95                         if( $( "input[name$='config_wgMainCacheType']:checked" ).val() == 'memcached' ) {
96                                 $memc.show( 'slow' );
97                         } else {
98                                 $memc.hide( 'slow' );
99                         }
100                 } );
101         } );
102 })(jQuery);