X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=mw-config%2Fconfig.js;h=99290f445370724ca480814b8a4fc65a4244a29a;hb=4d8248ff97278627902974bd1726c6a3c0a70f50;hp=8b2d6e5ab466c7087574a028cafc433d5f122421;hpb=57eaa2bf04ce1b48bd89c10defe4de5b7d31f047;p=lhc%2Fweb%2Fwiklou.git diff --git a/mw-config/config.js b/mw-config/config.js index 8b2d6e5ab4..99290f4453 100644 --- a/mw-config/config.js +++ b/mw-config/config.js @@ -1,10 +1,11 @@ +/* global extDependencyMap */ ( function ( $ ) { $( function () { var $label, labelText; function syncText() { var value = $( this ).val() - .replace( /[\[\]\{\}|#<>%+? ]/g, '_' ) + .replace( /[\[\]{}|#<>%+? ]/g, '_' ) // eslint-disable-line no-useless-escape .replace( /&/, '&' ) .replace( /__+/g, '_' ) .replace( /^_+/, '' ) @@ -14,17 +15,13 @@ } // Set up the help system - $( '.config-help-field-data' ) - .hide() - .closest( '.config-help-field-container' ) - .find( '.config-help-field-hint' ) - .show() - .click( function () { - $( this ) - .closest( '.config-help-field-container' ) - .find( '.config-help-field-data' ) - .slideToggle( 'fast' ); - } ); + $( '.config-help-field-data' ).hide() + .closest( '.config-help-field-container' ).find( '.config-help-field-hint' ) + .show() + .click( function () { + $( this ).closest( '.config-help-field-container' ).find( '.config-help-field-data' ) + .slideToggle( 'fast' ); + } ); // Show/hide code for DB-specific options // FIXME: Do we want slow, fast, or even non-animated (instantaneous) showing/hiding here? @@ -76,21 +73,23 @@ // Hide "other" textboxes by default // Should not be done in CSS for javascript disabled compatibility - $( '.enabledByOther' ).closest( '.config-block' ).hide(); + if ( !$( '#config__NamespaceType_other' ).is( ':checked' ) ) { + $( '.enabledByOther' ).closest( '.config-block' ).hide(); + } // Enable/disable "other" textboxes $( '.enableForOther' ).click( function () { var $textbox = $( document.getElementById( $( this ).attr( 'rel' ) ) ); // FIXME: Ugh, this is ugly if ( $( this ).val() === 'other' ) { - $textbox.removeProp( 'readonly' ).closest( '.config-block' ).slideDown( 'fast' ); + $textbox.prop( 'readonly', false ).closest( '.config-block' ).slideDown( 'fast' ); } else { $textbox.prop( 'readonly', true ).closest( '.config-block' ).slideUp( 'fast' ); } } ); // Synchronize radio button label for sitename with textbox - $label = $( 'label[for=config__NamespaceType_site-name]' ); + $label = $( 'label[for="config__NamespaceType_site-name"]' ); labelText = $label.text(); $label.text( labelText.replace( '$1', '' ) ); $( '#config_wgSitename' ).on( 'keyup change', syncText ).each( syncText ); @@ -104,5 +103,49 @@ $memc.hide( 'slow' ); } } ); + + function areReqsSatisfied( name ) { + var i, ext, skin, node; + if ( !extDependencyMap[ name ] ) { + return true; + } + + if ( extDependencyMap[ name ].extensions ) { + for ( i in extDependencyMap[ name ].extensions ) { + ext = extDependencyMap[ name ].extensions[ i ]; + node = document.getElementById( 'config_ext-' + ext ); + if ( !node || !node.checked ) { + return false; + } + } + } + if ( extDependencyMap[ name ].skins ) { + for ( i in extDependencyMap[ name ].skins ) { + skin = extDependencyMap[ name ].skins[ i ]; + node = document.getElementById( 'config_skin-' + skin ); + if ( !node || !node.checked ) { + return false; + } + } + } + + return true; + } + + // Disable checkboxes if the extension has dependencies + $( '.mw-ext-with-dependencies input' ).prop( 'disabled', true ); + $( '.config-ext-input[data-name]' ).on( 'change', function () { + $( '.mw-ext-with-dependencies input' ).each( function () { + var name = this.getAttribute( 'data-name' ); + if ( areReqsSatisfied( name ) ) { + // Re-enable it! + this.disabled = false; + } else { + // Uncheck and disable the checkbox + this.checked = false; + this.disabled = true; + } + } ); + } ); } ); }( jQuery ) );