Split page history radio button tweaks out from wikibits.js to history.js
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 9 May 2008 20:51:32 +0000 (20:51 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 9 May 2008 20:51:32 +0000 (20:51 +0000)
Only include it when it's needed -- don't force it on every reader!

includes/DefaultSettings.php
includes/PageHistory.php
skins/common/history.js [new file with mode: 0644]
skins/common/wikibits.js

index 5992757..81a7149 100644 (file)
@@ -1347,7 +1347,7 @@ $wgCacheEpoch = '20030516000000';
  * to ensure that client-side caches don't keep obsolete copies of global
  * styles.
  */
-$wgStyleVersion = '142';
+$wgStyleVersion = '143';
 
 
 # Server-side caching:
index 1002d7b..13b021c 100644 (file)
@@ -81,6 +81,7 @@ class PageHistory {
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
                $wgOut->setSyndicated( true );
                $wgOut->setFeedAppendQuery( 'action=history' );
+               $wgOut->addScriptFile( 'history.js' );
 
                $logPage = SpecialPage::getTitleFor( 'Log' );
                $logLink = $this->mSkin->makeKnownLinkObj( $logPage, wfMsgHtml( 'viewpagelogs' ), 'page=' . $this->mTitle->getPrefixedUrl() );
diff --git a/skins/common/history.js b/skins/common/history.js
new file mode 100644 (file)
index 0000000..57e6184
--- /dev/null
@@ -0,0 +1,83 @@
+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
+       var hf = document.getElementById('pagehistory');
+       if (!hf) {
+               return true;
+       }
+       var lis = hf.getElementsByTagName('li');
+       for (var i=0;i<lis.length;i++) {
+               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) {
+                                       return false;
+                               }
+                               if (oli) { // it's the second checked radio
+                                       if (inputs[1].checked) {
+                                               oli.className = "selected";
+                                               return false;
+                                       }
+                               } else if (inputs[0].checked) {
+                                       return false;
+                               }
+                               if (inputs[0].checked) {
+                                       dli = lis[i];
+                               }
+                               if (!oli) {
+                                       inputs[0].style.visibility = 'hidden';
+                               }
+                               if (dli) {
+                                       inputs[1].style.visibility = 'hidden';
+                               }
+                               lis[i].className = "selected";
+                               oli = lis[i];
+                       }  else { // no radio is checked in this row
+                               if (!oli) {
+                                       inputs[0].style.visibility = 'hidden';
+                               } else {
+                                       inputs[0].style.visibility = 'visible';
+                               }
+                               if (dli) {
+                                       inputs[1].style.visibility = 'hidden';
+                               } else {
+                                       inputs[1].style.visibility = 'visible';
+                               }
+                               lis[i].className = "";
+                       }
+               }
+       }
+       return true;
+}
+
+// page history stuff
+// attach event handlers to the input elements on history page
+function histrowinit() {
+       var hf = document.getElementById('pagehistory');
+       if (!hf) {
+               return;
+       }
+       var lis = hf.getElementsByTagName('li');
+       for (var i = 0; i < lis.length; i++) {
+               var inputs = historyRadios(lis[i]);
+               if (inputs[0] && inputs[1]) {
+                       inputs[0].onclick = diffcheck;
+                       inputs[1].onclick = diffcheck;
+               }
+       }
+       diffcheck();
+}
+
+hookEvent("load", histrowinit);
index 3546545..c16c924 100644 (file)
@@ -76,88 +76,6 @@ function toggleVisibility(_levelId, _otherId, _linkId) {
        }
 }
 
-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
-       var hf = document.getElementById('pagehistory');
-       if (!hf) {
-               return true;
-       }
-       var lis = hf.getElementsByTagName('li');
-       for (var i=0;i<lis.length;i++) {
-               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) {
-                                       return false;
-                               }
-                               if (oli) { // it's the second checked radio
-                                       if (inputs[1].checked) {
-                                               oli.className = "selected";
-                                               return false;
-                                       }
-                               } else if (inputs[0].checked) {
-                                       return false;
-                               }
-                               if (inputs[0].checked) {
-                                       dli = lis[i];
-                               }
-                               if (!oli) {
-                                       inputs[0].style.visibility = 'hidden';
-                               }
-                               if (dli) {
-                                       inputs[1].style.visibility = 'hidden';
-                               }
-                               lis[i].className = "selected";
-                               oli = lis[i];
-                       }  else { // no radio is checked in this row
-                               if (!oli) {
-                                       inputs[0].style.visibility = 'hidden';
-                               } else {
-                                       inputs[0].style.visibility = 'visible';
-                               }
-                               if (dli) {
-                                       inputs[1].style.visibility = 'hidden';
-                               } else {
-                                       inputs[1].style.visibility = 'visible';
-                               }
-                               lis[i].className = "";
-                       }
-               }
-       }
-       return true;
-}
-
-// page history stuff
-// attach event handlers to the input elements on history page
-function histrowinit() {
-       var hf = document.getElementById('pagehistory');
-       if (!hf) {
-               return;
-       }
-       var lis = hf.getElementsByTagName('li');
-       for (var i = 0; i < lis.length; i++) {
-               var inputs = historyRadios(lis[i]);
-               if (inputs[0] && inputs[1]) {
-                       inputs[0].onclick = diffcheck;
-                       inputs[1].onclick = diffcheck;
-               }
-       }
-       diffcheck();
-}
-
 // generate toc from prefs form, fold sections
 // XXX: needs testing on IE/Mac and safari
 // more comments to follow
@@ -1209,7 +1127,6 @@ function runOnloadHook() {
        // might cause the function to terminate prematurely
        doneOnloadHook = true;
 
-       histrowinit();
        unhidetzbutton();
        tabbedprefs();
        updateTooltipAccessKeys( null );