Clean up the history radio button handler a little bit in case someone does
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 16 Mar 2006 01:34:07 +0000 (01:34 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 16 Mar 2006 01:34:07 +0000 (01:34 +0000)
something silly like trying to put other buttons or check boxes in there.
It'll now only operate on the oldid and diff bits; also it uses local
variables instead of globals (yecch).

skins/common/wikibits.js

index 93b1838..63ea593 100644 (file)
@@ -84,12 +84,12 @@ function toggleVisibility(_levelId, _otherId, _linkId) {
 // page history stuff
 // attach event handlers to the input elements on history page
 function histrowinit() {
-       hf = document.getElementById('pagehistory');
+       var hf = document.getElementById('pagehistory');
        if (!hf)
                return;
-       lis = hf.getElementsByTagName('li');
+       var lis = hf.getElementsByTagName('li');
        for (i = 0; i < lis.length; i++) {
-               inputs = lis[i].getElementsByTagName('input');
+               var inputs = historyRadios(lis[i]);
                if (inputs[0] && inputs[1]) {
                        inputs[0].onclick = diffcheck;
                        inputs[1].onclick = diffcheck;
@@ -98,16 +98,26 @@ function histrowinit() {
        diffcheck();
 }
 
+function historyRadios(parent) {
+       var inputs = parent.getElementsByTagName('input');
+       var radios = [];
+       for (var i = 0; i < inputs.length; i++) {
+               if (inputs[i].name == "diff" || inputs[i].name == "oldid")
+                       radios[radios.length] = inputs[i];
+       }
+       return radios;
+}
+
 // check selection and tweak visibility/class onclick
 function diffcheck() {
        var dli = false; // the li where the diff radio is checked
        var oli = false; // the li where the oldid radio is checked
-       hf = document.getElementById('pagehistory');
+       var hf = document.getElementById('pagehistory');
        if (!hf)
                return;
-       lis = hf.getElementsByTagName('li');
+       var lis = hf.getElementsByTagName('li');
        for (i=0;i<lis.length;i++) {
-               inputs = lis[i].getElementsByTagName('input');
+               var inputs = historyRadios(lis[i]);
                if (inputs[1] && inputs[0]) {
                        if (inputs[1].checked || inputs[0].checked) { // this row has a checked radio button
                                if (inputs[1].checked && inputs[0].checked && inputs[0].value == inputs[1].value)