config.js 5.4 KB

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