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