config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ( function ( $ ) {
  2. $( function () {
  3. var $label, labelText;
  4. function syncText() {
  5. var value = $( this ).val()
  6. .replace( /[\[\]\{\}|#<>%+? ]/g, '_' )
  7. .replace( /&/, '&amp;' )
  8. .replace( /__+/g, '_' )
  9. .replace( /^_+/, '' )
  10. .replace( /_+$/, '' );
  11. value = value.charAt( 0 ).toUpperCase() + value.slice( 1 );
  12. $label.text( labelText.replace( '$1', value ) );
  13. }
  14. // Set up the help system
  15. $( '.config-help-field-data' )
  16. .hide()
  17. .closest( '.config-help-field-container' )
  18. .find( '.config-help-field-hint' )
  19. .show()
  20. .click( function () {
  21. $( this )
  22. .closest( '.config-help-field-container' )
  23. .find( '.config-help-field-data' )
  24. .slideToggle( 'fast' );
  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. // Scroll to the bottom of upgrade log
  41. $( '#config-live-log' ).children( 'textarea' ).each( function () {
  42. this.scrollTop = this.scrollHeight;
  43. } );
  44. // Show/hide Creative Commons thingy
  45. $( '.licenseRadio' ).click( function () {
  46. var $wrapper = $( '#config-cc-wrapper' );
  47. if ( $( '#config__LicenseCode_cc-choose' ).is( ':checked' ) ) {
  48. $wrapper.show( 'slow' );
  49. } else {
  50. $wrapper.hide( 'slow' );
  51. }
  52. } );
  53. // Show/hide random stuff (email, upload)
  54. $( '.showHideRadio' ).click( function () {
  55. var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
  56. if ( $( this ).is( ':checked' ) ) {
  57. $wrapper.show( 'slow' );
  58. } else {
  59. $wrapper.hide( 'slow' );
  60. }
  61. } );
  62. $( '.hideShowRadio' ).click( function () {
  63. var $wrapper = $( '#' + $( this ).attr( 'rel' ) );
  64. if ( $( this ).is( ':checked' ) ) {
  65. $wrapper.hide( 'slow' );
  66. } else {
  67. $wrapper.show( 'slow' );
  68. }
  69. } );
  70. // Hide "other" textboxes by default
  71. // Should not be done in CSS for javascript disabled compatibility
  72. $( '.enabledByOther' ).closest( '.config-block' ).hide();
  73. // Enable/disable "other" textboxes
  74. $( '.enableForOther' ).click( function () {
  75. var $textbox = $( document.getElementById( $( this ).attr( 'rel' ) ) );
  76. // FIXME: Ugh, this is ugly
  77. if ( $( this ).val() === 'other' ) {
  78. $textbox.removeProp( 'readonly' ).closest( '.config-block' ).slideDown( 'fast' );
  79. } else {
  80. $textbox.prop( 'readonly', true ).closest( '.config-block' ).slideUp( 'fast' );
  81. }
  82. } );
  83. // Synchronize radio button label for sitename with textbox
  84. $label = $( 'label[for=config__NamespaceType_site-name]' );
  85. labelText = $label.text();
  86. $label.text( labelText.replace( '$1', '' ) );
  87. $( '#config_wgSitename' ).on( 'keyup change', syncText ).each( syncText );
  88. // Show/Hide memcached servers when needed
  89. $( 'input[name$="config__MainCacheType"]' ).change( function () {
  90. var $memc = $( '#config-memcachewrapper' );
  91. if ( $( 'input[name$="config__MainCacheType"]:checked' ).val() === 'memcached' ) {
  92. $memc.show( 'slow' );
  93. } else {
  94. $memc.hide( 'slow' );
  95. }
  96. } );
  97. } );
  98. }( jQuery ) );