summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.special/mediawiki.special.block.js
blob: aca335ee506313d40872d7d5376cebbf83519d67 (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
36
37
38
39
40
41
42
43
44
45
/*!
 * JavaScript for Special:Block
 */
( function ( mw, $ ) {
	$( function () {
		var $blockTarget = $( '#mw-bi-target' ),
			$anonOnlyRow = $( '#mw-input-wpHardBlock' ).closest( 'tr' ),
			$enableAutoblockRow = $( '#mw-input-wpAutoBlock' ).closest( 'tr' ),
			$hideUser = $( '#mw-input-wpHideUser' ).closest( 'tr' ),
			$watchUser = $( '#mw-input-wpWatch' ).closest( 'tr' );

		function updateBlockOptions( instant ) {
			var blocktarget = $.trim( $blockTarget.val() ),
				isEmpty = blocktarget === '',
				isIp = mw.util.isIPAddress( blocktarget, true ),
				isIpRange = isIp && blocktarget.match( /\/\d+$/ );

			if ( isIp && !isEmpty ) {
				$enableAutoblockRow.goOut( instant );
				$hideUser.goOut( instant );
			} else {
				$enableAutoblockRow.goIn( instant );
				$hideUser.goIn( instant );
			}
			if ( !isIp && !isEmpty ) {
				$anonOnlyRow.goOut( instant );
			} else {
				$anonOnlyRow.goIn( instant );
			}
			if ( isIpRange && !isEmpty ) {
				$watchUser.goOut( instant );
			} else {
				$watchUser.goIn( instant );
			}
		}

		if ( $blockTarget.length ) {
			// Bind functions so they're checked whenever stuff changes
			$blockTarget.keyup( updateBlockOptions );

			// Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
			updateBlockOptions( /* instant= */ true );
		}
	} );
}( mediaWiki, jQuery ) );