Merge "Define pt as fallback for tet"
[lhc/web/wiklou.git] / mw-config / config.js
1 /* global extDependencyMap */
2 ( function ( $ ) {
3 $( function () {
4 var $label, labelText;
5
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 }
16
17 // Set up the help system
18 $( '.config-help-field-data' ).hide()
19 .closest( '.config-help-field-container' ).find( '.config-help-field-hint' )
20 .show()
21 .click( function () {
22 $( this ).closest( '.config-help-field-container' ).find( '.config-help-field-data' )
23 .slideToggle( 'fast' );
24 } );
25
26 // Show/hide code for DB-specific options
27 // FIXME: Do we want slow, fast, or even non-animated (instantaneous) showing/hiding here?
28 $( '.dbRadio' ).each( function () {
29 $( document.getElementById( $( this ).attr( 'rel' ) ) ).hide();
30 } );
31 $( document.getElementById( $( '.dbRadio:checked' ).attr( 'rel' ) ) ).show();
32 $( '.dbRadio' ).click( function () {
33 var $checked = $( '.dbRadio:checked' ),
34 $wrapper = $( document.getElementById( $checked.attr( 'rel' ) ) );
35 if ( $wrapper.is( ':hidden' ) ) {
36 $( '.dbWrapper' ).hide( 'slow' );
37 $wrapper.show( 'slow' );
38 }
39 } );
40
41 // Scroll to the bottom of upgrade log
42 $( '#config-live-log' ).children( 'textarea' ).each( function () {
43 this.scrollTop = this.scrollHeight;
44 } );
45
46 // Show/hide Creative Commons thingy
47 $( '.licenseRadio' ).click( function () {
48 var $wrapper = $( '#config-cc-wrapper' );
49 if ( $( '#config__LicenseCode_cc-choose' ).is( ':checked' ) ) {
50 $wrapper.show( 'slow' );
51 } else {
52 $wrapper.hide( 'slow' );
53 }
54 } );
55
56 // Show/hide random stuff (email, upload)
57 $( '.showHideRadio' ).click( function () {
58 var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
59 if ( $( this ).is( ':checked' ) ) {
60 $wrapper.show( 'slow' );
61 } else {
62 $wrapper.hide( 'slow' );
63 }
64 } );
65 $( '.hideShowRadio' ).click( function () {
66 var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
67 if ( $( this ).is( ':checked' ) ) {
68 $wrapper.hide( 'slow' );
69 } else {
70 $wrapper.show( 'slow' );
71 }
72 } );
73
74 // Hide "other" textboxes by default
75 // Should not be done in CSS for javascript disabled compatibility
76 $( '.enabledByOther' ).closest( '.config-block' ).hide();
77
78 // Enable/disable "other" textboxes
79 $( '.enableForOther' ).click( function () {
80 var $textbox = $( document.getElementById( $( this ).attr( 'rel' ) ) );
81 // FIXME: Ugh, this is ugly
82 if ( $( this ).val() === 'other' ) {
83 $textbox.prop( 'readonly', false ).closest( '.config-block' ).slideDown( 'fast' );
84 } else {
85 $textbox.prop( 'readonly', true ).closest( '.config-block' ).slideUp( 'fast' );
86 }
87 } );
88
89 // Synchronize radio button label for sitename with textbox
90 $label = $( 'label[for="config__NamespaceType_site-name"]' );
91 labelText = $label.text();
92 $label.text( labelText.replace( '$1', '' ) );
93 $( '#config_wgSitename' ).on( 'keyup change', syncText ).each( syncText );
94
95 // Show/Hide memcached servers when needed
96 $( 'input[name$="config__MainCacheType"]' ).change( function () {
97 var $memc = $( '#config-memcachewrapper' );
98 if ( $( 'input[name$="config__MainCacheType"]:checked' ).val() === 'memcached' ) {
99 $memc.show( 'slow' );
100 } else {
101 $memc.hide( 'slow' );
102 }
103 } );
104
105 function areReqsSatisfied( name ) {
106 var i, ext, skin, node;
107 if ( !extDependencyMap[ name ] ) {
108 return true;
109 }
110
111 if ( extDependencyMap[ name ].extensions ) {
112 for ( i in extDependencyMap[ name ].extensions ) {
113 ext = extDependencyMap[ name ].extensions[ i ];
114 node = document.getElementById( 'config_ext-' + ext );
115 if ( !node || !node.checked ) {
116 return false;
117 }
118 }
119 }
120 if ( extDependencyMap[ name ].skins ) {
121 for ( i in extDependencyMap[ name ].skins ) {
122 skin = extDependencyMap[ name ].skins[ i ];
123 node = document.getElementById( 'config_skin-' + skin );
124 if ( !node || !node.checked ) {
125 return false;
126 }
127 }
128 }
129
130 return true;
131 }
132
133 // Disable checkboxes if the extension has dependencies
134 $( '.mw-ext-with-dependencies input' ).prop( 'disabled', true );
135 $( '.config-ext-input[data-name]' ).on( 'change', function () {
136 $( '.mw-ext-with-dependencies input' ).each( function () {
137 var name = this.getAttribute( 'data-name' );
138 if ( areReqsSatisfied( name ) ) {
139 // Re-enable it!
140 this.disabled = false;
141 } else {
142 // Uncheck and disable the checkbox
143 this.checked = false;
144 this.disabled = true;
145 }
146 } );
147 } );
148 } );
149 }( jQuery ) );