X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=mw-config%2Fconfig.js;h=99290f445370724ca480814b8a4fc65a4244a29a;hp=c745ce44a771422f060766a3e4f15968557897a6;hb=0e6f6b592df4e513648fb1114f80e6b10387b7cf;hpb=b95ca29602793f39191c06cd6941e3f32ab1bbb8 diff --git a/mw-config/config.js b/mw-config/config.js index c745ce44a7..99290f4453 100644 --- a/mw-config/config.js +++ b/mw-config/config.js @@ -1,3 +1,4 @@ +/* global extDependencyMap */ ( function ( $ ) { $( function () { var $label, labelText; @@ -72,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 ); @@ -100,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 ) );