history.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. function historyRadios(parent) {
  2. var inputs = parent.getElementsByTagName('input');
  3. var radios = [];
  4. for (var i = 0; i < inputs.length; i++) {
  5. if (inputs[i].name == "diff" || inputs[i].name == "oldid") {
  6. radios[radios.length] = inputs[i];
  7. }
  8. }
  9. return radios;
  10. }
  11. // check selection and tweak visibility/class onclick
  12. function diffcheck() {
  13. var dli = false; // the li where the diff radio is checked
  14. var oli = false; // the li where the oldid radio is checked
  15. var hf = document.getElementById('pagehistory');
  16. if (!hf) {
  17. return true;
  18. }
  19. var lis = hf.getElementsByTagName('li');
  20. for (var i=0;i<lis.length;i++) {
  21. var inputs = historyRadios(lis[i]);
  22. if (inputs[1] && inputs[0]) {
  23. if (inputs[1].checked || inputs[0].checked) { // this row has a checked radio button
  24. if (inputs[1].checked && inputs[0].checked && inputs[0].value == inputs[1].value) {
  25. return false;
  26. }
  27. if (oli) { // it's the second checked radio
  28. if (inputs[1].checked) {
  29. if ( (typeof oli.className) != 'undefined') {
  30. oli.classNameOriginal = oli.className.replace( 'selected', '' );
  31. } else {
  32. oli.classNameOriginal = '';
  33. }
  34. oli.className = "selected "+oli.classNameOriginal;
  35. return false;
  36. }
  37. } else if (inputs[0].checked) {
  38. return false;
  39. }
  40. if (inputs[0].checked) {
  41. dli = lis[i];
  42. }
  43. if (!oli) {
  44. inputs[0].style.visibility = 'hidden';
  45. }
  46. if (dli) {
  47. inputs[1].style.visibility = 'hidden';
  48. }
  49. if ( (typeof lis[i].className) != 'undefined') {
  50. lis[i].classNameOriginal = lis[i].className.replace( 'selected', '' );
  51. } else {
  52. lis[i].classNameOriginal = '';
  53. }
  54. lis[i].className = "selected "+lis[i].classNameOriginal;
  55. oli = lis[i];
  56. } else { // no radio is checked in this row
  57. if (!oli) {
  58. inputs[0].style.visibility = 'hidden';
  59. } else {
  60. inputs[0].style.visibility = 'visible';
  61. }
  62. if (dli) {
  63. inputs[1].style.visibility = 'hidden';
  64. } else {
  65. inputs[1].style.visibility = 'visible';
  66. }
  67. lis[i].className = lis[i].classNameOriginal;
  68. }
  69. }
  70. }
  71. return true;
  72. }
  73. // page history stuff
  74. // attach event handlers to the input elements on history page
  75. function histrowinit() {
  76. var hf = document.getElementById('pagehistory');
  77. if (!hf) {
  78. return;
  79. }
  80. var lis = hf.getElementsByTagName('li');
  81. for (var i = 0; i < lis.length; i++) {
  82. var inputs = historyRadios(lis[i]);
  83. if (inputs[0] && inputs[1]) {
  84. inputs[0].onclick = diffcheck;
  85. inputs[1].onclick = diffcheck;
  86. }
  87. }
  88. diffcheck();
  89. }
  90. hookEvent("load", histrowinit);