Get rid of ParserOptions::setTidy()
[mediawiki.git] / mw-config / config.js
blob6f899f83cdef07d32cc43c92f07137f42d36f2df
1 /* global extDependencyMap */
2 ( function () {
3         $( function () {
4                 var $label, labelText;
6                 function syncText() {
7                         var value = $( this ).val()
8                                 .replace( /[\[\]{}|#<>%+? ]/g, '_' ) // eslint-disable-line no-useless-escape
9                                 .replace( /&/, '&amp;' )
10                                 .replace( /__+/g, '_' )
11                                 .replace( /^_+/, '' )
12                                 .replace( /_+$/, '' );
13                         value = value.charAt( 0 ).toUpperCase() + value.slice( 1 );
14                         $label.text( labelText.replace( '$1', value ) );
15                 }
17                 // Show/hide code for DB-specific options
18                 // FIXME: Do we want slow, fast, or even non-animated (instantaneous) showing/hiding here?
19                 $( '.dbRadio' ).each( function () {
20                         $( document.getElementById( $( this ).attr( 'rel' ) ) ).hide();
21                 } );
22                 $( document.getElementById( $( '.dbRadio:checked' ).attr( 'rel' ) ) ).show();
23                 $( '.dbRadio' ).on( 'click', function () {
24                         var $checked = $( '.dbRadio:checked' ),
25                                 $wrapper = $( document.getElementById( $checked.attr( 'rel' ) ) );
26                         // eslint-disable-next-line no-jquery/no-sizzle
27                         if ( $wrapper.is( ':hidden' ) ) {
28                                 // FIXME: Use CSS transition
29                                 // eslint-disable-next-line no-jquery/no-animate-toggle
30                                 $( '.dbWrapper' ).hide( 'slow' );
31                                 // eslint-disable-next-line no-jquery/no-animate-toggle
32                                 $wrapper.show( 'slow' );
33                         }
34                 } );
36                 // Scroll to the bottom of upgrade log
37                 $( '#config-live-log' ).children( 'textarea' ).each( function () {
38                         this.scrollTop = this.scrollHeight;
39                 } );
41                 // Show/hide Creative Commons thingy
42                 $( '.licenseRadio' ).on( 'click', function () {
43                         var $wrapper = $( '#config-cc-wrapper' );
44                         if ( $( '#config__LicenseCode_cc-choose' ).is( ':checked' ) ) {
45                                 // FIXME: Use CSS transition
46                                 // eslint-disable-next-line no-jquery/no-animate-toggle
47                                 $wrapper.show( 'slow' );
48                         } else {
49                                 // eslint-disable-next-line no-jquery/no-animate-toggle
50                                 $wrapper.hide( 'slow' );
51                         }
52                 } );
54                 // Show/hide random stuff (email, upload)
55                 $( '.showHideRadio' ).on( 'click', function () {
56                         var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
57                         if ( $( this ).is( ':checked' ) ) {
58                                 // FIXME: Use CSS transition
59                                 // eslint-disable-next-line no-jquery/no-animate-toggle
60                                 $wrapper.show( 'slow' );
61                         } else {
62                                 // eslint-disable-next-line no-jquery/no-animate-toggle
63                                 $wrapper.hide( 'slow' );
64                         }
65                 } );
66                 $( '.hideShowRadio' ).on( 'click', function () {
67                         var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
68                         if ( $( this ).is( ':checked' ) ) {
69                                 // FIXME: Use CSS transition
70                                 // eslint-disable-next-line no-jquery/no-animate-toggle
71                                 $wrapper.hide( 'slow' );
72                         } else {
73                                 // eslint-disable-next-line no-jquery/no-animate-toggle
74                                 $wrapper.show( 'slow' );
75                         }
76                 } );
78                 // Hide "other" textboxes by default
79                 // Should not be done in CSS for javascript disabled compatibility
80                 if ( !$( '#config__NamespaceType_other' ).is( ':checked' ) ) {
81                         $( '.enabledByOther' ).closest( '.config-block' ).hide();
82                 }
84                 // Enable/disable "other" textboxes
85                 $( '.enableForOther' ).on( 'click', function () {
86                         var $textbox = $( document.getElementById( $( this ).attr( 'rel' ) ) );
87                         // FIXME: Ugh, this is ugly
88                         if ( $( this ).val() === 'other' ) {
89                                 // FIXME: Use CSS transition
90                                 // eslint-disable-next-line no-jquery/no-slide
91                                 $textbox.prop( 'readonly', false ).closest( '.config-block' ).slideDown( 'fast' );
92                         } else {
93                                 // eslint-disable-next-line no-jquery/no-slide
94                                 $textbox.prop( 'readonly', true ).closest( '.config-block' ).slideUp( 'fast' );
95                         }
96                 } );
98                 // Synchronize radio button label for sitename with textbox
99                 $label = $( 'label[for="config__NamespaceType_site-name"]' );
100                 labelText = $label.text();
101                 $label.text( labelText.replace( '$1', '' ) );
102                 $( '#config_wgSitename' ).on( 'keyup change', syncText ).each( syncText );
104                 // Show/Hide memcached servers when needed
105                 $( 'input[name$="config__MainCacheType"]' ).on( 'change', function () {
106                         var $memc = $( '#config-memcachewrapper' );
107                         if ( $( 'input[name$="config__MainCacheType"]:checked' ).val() === 'memcached' ) {
108                                 // FIXME: Use CSS transition
109                                 // eslint-disable-next-line no-jquery/no-animate-toggle
110                                 $memc.show( 'slow' );
111                         } else {
112                                 // eslint-disable-next-line no-jquery/no-animate-toggle
113                                 $memc.hide( 'slow' );
114                         }
115                 } );
117                 function areReqsSatisfied( name ) {
118                         var i, ext, skin, node;
119                         if ( !extDependencyMap[ name ] ) {
120                                 return true;
121                         }
123                         if ( extDependencyMap[ name ].extensions ) {
124                                 for ( i in extDependencyMap[ name ].extensions ) {
125                                         ext = extDependencyMap[ name ].extensions[ i ];
126                                         node = document.getElementById( 'config_ext-' + ext );
127                                         if ( !node || !node.checked ) {
128                                                 return false;
129                                         }
130                                 }
131                         }
132                         if ( extDependencyMap[ name ].skins ) {
133                                 for ( i in extDependencyMap[ name ].skins ) {
134                                         skin = extDependencyMap[ name ].skins[ i ];
135                                         node = document.getElementById( 'config_skin-' + skin );
136                                         if ( !node || !node.checked ) {
137                                                 return false;
138                                         }
139                                 }
140                         }
142                         return true;
143                 }
145                 // Disable checkboxes if the extension has dependencies
146                 $( '.mw-ext-with-dependencies input' ).prop( 'disabled', true );
147                 $( '.config-ext-input[data-name]' ).on( 'change', function () {
148                         $( '.mw-ext-with-dependencies input' ).each( function () {
149                                 var name = this.getAttribute( 'data-name' );
150                                 if ( areReqsSatisfied( name ) ) {
151                                         // Re-enable it!
152                                         this.disabled = false;
153                                 } else {
154                                         // Uncheck and disable the checkbox
155                                         this.checked = false;
156                                         this.disabled = true;
157                                 }
158                         } );
159                 } );
160         } );
161 }() );