Use capability testing instead of UA sniffing
[lhc/web/wiklou.git] / skins / common / block.js
1 addOnloadHook(considerChangingExpiryFocus);
2
3 function considerChangingExpiryFocus() {
4 if (!document.getElementById) {
5 return;
6 }
7 var drop = document.getElementById('wpBlockExpiry');
8 if (!drop) {
9 return;
10 }
11 var field = document.getElementById('wpBlockOther');
12 if (!field) {
13 return;
14 }
15 var opt = drop.value;
16 if (opt == 'other') {
17 field.style.display = '';
18 } else {
19 field.style.display = 'none';
20 }
21 }
22
23 function updateBlockOptions() {
24 if (!document.getElementById)
25 return;
26
27 var target = document.getElementById('mw-bi-target');
28 if (!target)
29 return;
30
31 var addy = target.value;
32 var isEmpty = addy.match(/^\s*$/);
33 var isIp = addy.match(/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7})(\/\d+)?$/);
34 var isIpRange = isIp && addy.match(/\/\d+$/);
35
36 var anonymousRow = document.getElementById('wpAnonOnlyRow');
37 if( anonymousRow ) {
38 anonymousRow.style.display = (!isIp && !isEmpty) ? 'none' : '';
39 }
40
41 var autoblockRow = document.getElementById('wpEnableAutoblockRow');
42 if( autoblockRow ) {
43 autoblockRow.style.display = isIp && !isEmpty ? 'none' : '';
44 }
45
46 var hideuserRow = document.getElementById('wpEnableHideUser');
47 if( hideuserRow ) {
48 hideuserRow.style.display = isIp && !isEmpty ? 'none' : '';
49 }
50
51 var watchuserRow = document.getElementById('wpEnableWatchUser');
52 if( watchuserRow ) {
53 watchuserRow.style.display = isIpRange && !isEmpty ? 'none' : '';
54 }
55 }