2 * JavaScript for Special:Block
6 var $blockTarget
= $( '#mw-bi-target' ),
7 $anonOnlyRow
= $( '#mw-input-wpHardBlock' ).closest( 'tr' ),
8 $enableAutoblockRow
= $( '#mw-input-wpAutoBlock' ).closest( 'tr' ),
9 $hideUser
= $( '#mw-input-wpHideUser' ).closest( 'tr' ),
10 $watchUser
= $( '#mw-input-wpWatch' ).closest( 'tr' ),
11 $expiry
= $( '#mw-input-wpExpiry' ),
12 $otherExpiry
= $( '#mw-input-wpExpiry-other' );
14 function updateBlockOptions( instant
) {
15 var blocktarget
= $.trim( $blockTarget
.val() ),
16 isEmpty
= blocktarget
=== '',
17 isIp
= mw
.util
.isIPAddress( blocktarget
, true ),
18 isIpRange
= isIp
&& blocktarget
.match( /\/\d+$/ ),
19 isNonEmptyIp
= isIp
&& !isEmpty
,
20 expiryValue
= $expiry
.val(),
21 // infinityValues are the values the SpecialBlock class accepts as infinity (sf. wfIsInfinity)
22 infinityValues
= [ 'infinite', 'indefinite', 'infinity', 'never' ],
23 isIndefinite
= $.inArray( expiryValue
, infinityValues
) !== -1 ||
24 ( expiryValue
=== 'other' && $.inArray( $otherExpiry
.val(), infinityValues
) !== -1 );
27 $enableAutoblockRow
.goOut( instant
);
29 $enableAutoblockRow
.goIn( instant
);
31 if ( isNonEmptyIp
|| !isIndefinite
) {
32 $hideUser
.goOut( instant
);
34 $hideUser
.goIn( instant
);
36 if ( !isIp
&& !isEmpty
) {
37 $anonOnlyRow
.goOut( instant
);
39 $anonOnlyRow
.goIn( instant
);
41 if ( isIpRange
&& !isEmpty
) {
42 $watchUser
.goOut( instant
);
44 $watchUser
.goIn( instant
);
48 if ( $blockTarget
.length
) {
49 // Bind functions so they're checked whenever stuff changes
50 $blockTarget
.keyup( updateBlockOptions
);
51 $expiry
.change( updateBlockOptions
);
52 $otherExpiry
.keyup( updateBlockOptions
);
54 // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
55 updateBlockOptions( /* instant= */ true );
58 }( mediaWiki
, jQuery
) );