| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
$( () => { |
| 5 |
|
| 6 |
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Import' ) { |
| 7 |
return; |
| 8 |
} |
| 9 |
|
| 10 |
let projectDropdownInput, subprojectDropdownInput; |
| 11 |
|
| 12 |
function updateImportSubprojectList() { |
| 13 |
const project = projectDropdownInput.getValue(); |
| 14 |
subprojectDropdownInput.dropdownWidget.getMenu().getItems().forEach( ( item ) => { |
| 15 |
item.toggle( item.getData().indexOf( project + '::' ) === 0 ); |
| 16 |
} ); |
| 17 |
|
| 18 |
const firstItem = subprojectDropdownInput.dropdownWidget.menu.findFirstSelectableItem(); |
| 19 |
subprojectDropdownInput.toggle( !!firstItem ); |
| 20 |
subprojectDropdownInput.dropdownWidget.menu.selectItem( firstItem ); |
| 21 |
} |
| 22 |
|
| 23 |
const $subprojectInput = $( '#mw-input-subproject' ); |
| 24 |
if ( $subprojectInput.length ) { |
| 25 |
projectDropdownInput = OO.ui.infuse( $( '#mw-input-interwiki' ) ); |
| 26 |
subprojectDropdownInput = OO.ui.infuse( $subprojectInput ); |
| 27 |
|
| 28 |
projectDropdownInput.on( 'change', updateImportSubprojectList ); |
| 29 |
updateImportSubprojectList(); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
const sources = [ 'upload', 'interwiki' ]; |
| 34 |
sources.forEach( ( name ) => { |
| 35 |
|
| 36 |
const $mappingInput = $( '#mw-import-mapping-' + name ); |
| 37 |
|
| 38 |
const $namespaceInput = $( '#mw-import-namespace-' + name ); |
| 39 |
|
| 40 |
if ( $mappingInput.length && $namespaceInput.length ) { |
| 41 |
const mappingWidget = OO.ui.infuse( $mappingInput ); |
| 42 |
const namespaceWidget = OO.ui.infuse( $namespaceInput ); |
| 43 |
|
| 44 |
const $namespaceRadio = mappingWidget.radioSelectWidget.findItemFromData( 'namespace' ).$element; |
| 45 |
const $namespaceField = namespaceWidget.$element.closest( '.oo-ui-fieldLayout' ); |
| 46 |
$namespaceRadio.after( $namespaceField ); |
| 47 |
} |
| 48 |
} ); |
| 49 |
} ); |