ed0fa61beb29170b8fce452469cdde2f446323e0
[lhc/web/wiklou.git] / resources / mediawiki.special / mediawiki.special.block.js
1 /* JavaScript for Special:Block */
2
3 // Fade or snap depending on argument
4 jQuery.fn.goIn = function( instantToggle ) {
5 if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
6 return jQuery(this).show();
7 }
8 return jQuery(this).stop( true, true ).fadeIn();
9 };
10 jQuery.fn.goOut = function( instantToggle ) {
11 if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
12 return jQuery(this).hide();
13 }
14 return jQuery(this).stop( true, true ).fadeOut();
15 };
16
17 jQuery( function( $ ) {
18
19 var DO_INSTANT = true,
20 $blockExpiry = $( '#wpBlockExpiry' ), $blockOther = $( '#wpBlockOther' ),
21 $blockTarget = $( '#mw-bi-target' ), $anonOnlyRow = $( '#wpAnonOnlyRow' ),
22 $enableAutoblockRow = $( '#wpEnableAutoblockRow' ),
23 $hideUser = $( '#wpEnableHideUser' ), $watchUser = $( '#wpEnableWatchUser' );
24
25 var considerChangingExpiryFocus = function( instant ) {
26 if ( $blockExpiry.val() == 'other' ) {
27 $blockOther.goIn( instant );
28 } else {
29 $blockOther.goOut( instant );
30 }
31 };
32 var updateBlockOptions = function( instant ) {
33 if ( !$blockTarget.length ) {
34 return;
35 }
36
37 var blocktarget = $.trim( $blockTarget.val() );
38 var isEmpty = ( blocktarget === '' );
39 var isIp = mw.util.isIPv4Address( blocktarget, true ) || mw.util.isIPv6Address( blocktarget, true );
40 var isIpRange = isIp && blocktarget.match( /\/\d+$/ );
41
42 if ( isIp && !isEmpty ) {
43 $enableAutoblockRow.goOut( instant );
44 $hideUser.goOut( instant );
45 } else {
46 $enableAutoblockRow.goIn( instant );
47 $hideUser.goIn( instant );
48 }
49 if ( !isIp && !isEmpty ) {
50 $anonOnlyRow.goOut( instant );
51 } else {
52 $anonOnlyRow.goIn( instant );
53 }
54 if ( isIpRange && !isEmpty ) {
55 $watchUser.goOut( instant );
56 } else {
57 $watchUser.goIn( instant );
58 }
59 };
60
61 // Bind functions so they're checked whenever stuff changes
62 $blockExpiry.change( considerChangingExpiryFocus );
63 $blockTarget.keyup( updateBlockOptions );
64
65 // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
66 considerChangingExpiryFocus( DO_INSTANT );
67 updateBlockOptions( DO_INSTANT );
68 });