config.js 4.7 KB

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