X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=mw-config%2Fconfig.js;h=ab57b7b859fc5ef13fe7911b469e6c522f3e2348;hb=5a166c2a550152e4bcae799c9be7f06fa2a2278d;hp=8b2d6e5ab466c7087574a028cafc433d5f122421;hpb=ca5c234d189fbbf348e3e5a74d0070ac4ee1db4b;p=lhc%2Fweb%2Fwiklou.git diff --git a/mw-config/config.js b/mw-config/config.js index 8b2d6e5ab4..ab57b7b859 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? @@ -83,7 +80,7 @@ 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' ); } @@ -104,5 +101,52 @@ $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 ); + $( 'input[data-name]' ).change( function () { + $( '.mw-ext-with-dependencies input' ).each( function () { + var $this = $( this ), + name = $this.data( 'name' ); + if ( areReqsSatisfied( name ) ) { + // Un-disable it! + $this.prop( 'disabled', false ); + } else { + // Disable the checkbox, and uncheck it if it is checked + $this.prop( 'disabled', true ); + if ( $this.prop( 'checked' ) ) { + $this.prop( 'checked', false ); + } + } + } ); + } ); } ); }( jQuery ) );