Merge "Align "What's this" vertically"
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.block.js
1 /*!
2 * JavaScript for Special:Block
3 */
4 ( function ( mw, $ ) {
5 $( function () {
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' );
13
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 );
25
26 if ( isNonEmptyIp ) {
27 $enableAutoblockRow.goOut( instant );
28 } else {
29 $enableAutoblockRow.goIn( instant );
30 }
31 if ( isNonEmptyIp || !isIndefinite ) {
32 $hideUser.goOut( instant );
33 } else {
34 $hideUser.goIn( instant );
35 }
36 if ( !isIp && !isEmpty ) {
37 $anonOnlyRow.goOut( instant );
38 } else {
39 $anonOnlyRow.goIn( instant );
40 }
41 if ( isIpRange && !isEmpty ) {
42 $watchUser.goOut( instant );
43 } else {
44 $watchUser.goIn( instant );
45 }
46 }
47
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 );
53
54 // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
55 updateBlockOptions( /* instant= */ true );
56 }
57 } );
58 }( mediaWiki, jQuery ) );