1 /* JavaScript for Special:Block */
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();
8 return jQuery(this).stop( true, true ).fadeIn();
10 jQuery
.fn
.goOut = function( instantToggle
) {
11 if ( typeof instantToggle
!= 'undefined' && instantToggle
=== true ) {
12 return jQuery(this).hide();
14 return jQuery(this).stop( true, true ).fadeOut();
17 jQuery( function( $ ) {
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' );
25 var considerChangingExpiryFocus = function( instant
) {
26 if ( $blockExpiry
.val() == 'other' ) {
27 $blockOther
.goIn( instant
);
29 $blockOther
.goOut( instant
);
32 var updateBlockOptions = function( instant
) {
33 if ( !$blockTarget
.length
) {
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+$/ );
42 if ( isIp
&& !isEmpty
) {
43 $enableAutoblockRow
.goOut( instant
);
44 $hideUser
.goOut( instant
);
46 $enableAutoblockRow
.goIn( instant
);
47 $hideUser
.goIn( instant
);
49 if ( !isIp
&& !isEmpty
) {
50 $anonOnlyRow
.goOut( instant
);
52 $anonOnlyRow
.goIn( instant
);
54 if ( isIpRange
&& !isEmpty
) {
55 $watchUser
.goOut( instant
);
57 $watchUser
.goIn( instant
);
61 // Bind functions so they're checked whenever stuff changes
62 $blockExpiry
.change( considerChangingExpiryFocus
);
63 $blockTarget
.keyup( updateBlockOptions
);
65 // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
66 considerChangingExpiryFocus( DO_INSTANT
);
67 updateBlockOptions( DO_INSTANT
);