summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.special/mediawiki.special.import.js
blob: a9a985ebd4eb82fba0e37906af7f14d70076b2a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*!
 * JavaScript for Special:Import
 */
( function ( $ ) {
	function updateImportSubprojectList() {
		var $projectField = $( '#mw-import-table-interwiki #interwiki' ),
			$subprojectField = $projectField.parent().find( '#subproject' ),
			$selected = $projectField.find( ':selected' ),
			oldValue = $subprojectField.val(),
			option, options;

		if ( $selected.attr( 'data-subprojects' ) ) {
			options = $.map( $selected.attr( 'data-subprojects' ).split( ' ' ), function ( el ) {
				option = document.createElement( 'option' );
				option.appendChild( document.createTextNode( el ) );
				option.setAttribute( 'value', el );
				if ( oldValue === el ) {
					option.setAttribute( 'selected', 'selected' );
				}
				return option;
			} );
			$subprojectField.show().empty().append( options );
		} else {
			$subprojectField.hide();
		}
	}

	$( function () {
		var $projectField = $( '#mw-import-table-interwiki #interwiki' );
		if ( $projectField.length ) {
			$projectField.change( updateImportSubprojectList );
			updateImportSubprojectList();
		}
	} );
}( jQuery ) );