block.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. addOnloadHook(considerChangingExpiryFocus);
  2. function considerChangingExpiryFocus() {
  3. if (!document.getElementById) {
  4. return;
  5. }
  6. var drop = document.getElementById('wpBlockExpiry');
  7. if (!drop) {
  8. return;
  9. }
  10. var field = document.getElementById('wpBlockOther');
  11. if (!field) {
  12. return;
  13. }
  14. var opt = drop.value;
  15. if (opt == 'other') {
  16. field.style.display = '';
  17. } else {
  18. field.style.display = 'none';
  19. }
  20. }
  21. function updateBlockOptions() {
  22. if (!document.getElementById)
  23. return;
  24. var target = document.getElementById('mw-bi-target');
  25. if (!target)
  26. return;
  27. var addy = target.value;
  28. var isEmpty = addy.match(/^\s*$/);
  29. 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+)?$/);
  30. var isIpRange = isIp && addy.match(/\/\d+$/);
  31. var anonymousRow = document.getElementById('wpAnonOnlyRow');
  32. if( anonymousRow ) {
  33. anonymousRow.style.display = (!isIp && !isEmpty) ? 'none' : '';
  34. }
  35. var autoblockRow = document.getElementById('wpEnableAutoblockRow');
  36. if( autoblockRow ) {
  37. autoblockRow.style.display = isIp && !isEmpty ? 'none' : '';
  38. }
  39. var emailblockRow = document.getElementById('wpEnableEmailBan');
  40. if( emailblockRow ) {
  41. emailblockRow.style.display = isIp && !isEmpty ? 'none' : '';
  42. }
  43. var hideuserRow = document.getElementById('wpEnableHideUser');
  44. if( hideuserRow ) {
  45. hideuserRow.style.display = isIp && !isEmpty ? 'none' : '';
  46. }
  47. var watchuserRow = document.getElementById('wpEnableWatchUser');
  48. if( watchuserRow ) {
  49. watchuserRow.style.display = isIpRange && !isEmpty ? 'none' : '';
  50. }
  51. }