Add a simple hide/show goodie for the TOC in JavaScript.
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 6 Jul 2003 04:37:22 +0000 (04:37 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 6 Jul 2003 04:37:22 +0000 (04:37 +0000)
TODO: toggle the display of 'hide/show' button, save info in cookie.

includes/Skin.php
stylesheets/wikibits.js

index 927e4b3..b7c1ed1 100644 (file)
@@ -1694,7 +1694,9 @@ class Skin {
        return
        "<table border=\"0\" bgcolor=\"#8888aa\" cellpadding=\"0\" cellspacing=\"1\"><tr><td>\n" .
        "<table border=\"0\" bgcolor=\"#f3f3ff\" CELLPADDING=5><tr><td>\n".
-       "<b>".wfMsg("toc")."</b><p>\n".
+       "<b>".wfMsg("toc")."</b>" .
+       " <script type='text/javascript'>showTocToggle(\"" . wfMsg("showtoc") . "\",\"" . wfMsg("hidetoc") . "\")</script>" .
+       "</td></tr><tr id='tocinside'><td>\n".
        $toc."</td></tr></table></td></tr></table><P>\n";
        }
 
index c2b37a8..471153a 100644 (file)
@@ -34,6 +34,7 @@ function checkTimezone( tz, msg ) {
 // in [-][H]H format...
 // won't yet work with non-even tzs
 function fetchTimezone() {
+       // FIXME: work around Safari bug
        var localclock = new Date();
        // returns negative offset from GMT in minutes
        var tzRaw = localclock.getTimezoneOffset();
@@ -45,3 +46,27 @@ function fetchTimezone() {
 function guessTimezone(box) {
        document.preferences.wpHourDiff.value = fetchTimezone();
 }
+
+var tocShow, tocHide;
+function showTocToggle(show,hide) {
+       if(document.getElementById) {
+               document.writeln('<small>[<a href="javascript:toggleToc()" id="toctoggle">' +
+                       hide + '/' + show + '</a>]</small>');
+               tocShow = show;
+               tocHide = hide;
+       }
+}
+
+function toggleToc() {
+       var toc = document.getElementById('tocinside');
+       var tog = document.getElementById('toctoggle');
+       if(toc.style.display == 'none') {
+               toc.style.display = tocWas;
+               // tog.innerHtml = tocHide;
+       } else {
+               tocWas = toc.style.display;
+               toc.style.display = 'none';
+               // tog.innerHtml = tocShow;
+       }
+}
+