From 3da51fab3d957c487c6b04e137d0d3d391038d95 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Mon, 29 Oct 2018 21:08:12 -0700
Subject: html doc: "collapse all" shouldn't hide whole TOC.

* genman.txr: show the toggle as "expand all" initially.
Assign the sections of the TOC to the "tocsec" class,
and then select the elements by class rather than by the
dl element type. This avoids selecting the dl that wraps
the entire TOC.
(xpanded): New boolean variable.
(toggleall): Base toggle on boolean variable rather than
the state of the first section dl element.
Toggle the xpanded variable.
---
 genman.txr | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/genman.txr b/genman.txr
index 58088e8e..a99996b6 100644
--- a/genman.txr
+++ b/genman.txr
@@ -98,7 +98,7 @@ Content-type: text/html
 <noscript>
 <h3>Please turn on Javascript to use the collapsible contents.</h3>
 </noscript>
-<a href="#/" onclick="toggleall(this)">@clpsall</a>
+<a href="#/" onclick="toggleall(this)">@xpnall</a>
 @      (end)
 @    (or)
 @TOC
@@ -123,7 +123,7 @@ Content-type: text/html
               `<a href="#/" onclick="toggle(this, '@id')" class="toggle">@(if closed closedtxt opentxt)</a>`))
 @    (output :into TOC)
 @TOC
-<dd><dl id="@id"@(if closed " style=\"display: none\"")>
+<dd><dl id="@id" class="tocsec"@(if closed " style=\"display: none\"")>
 @    (end)
 @  (end)
 @(until)
@@ -178,6 +178,7 @@ This document was created by
 .disambiguations dl { margin-bottom: 2048px; }
 </style>
 <script type="text/javascript">
+var xpanded = false;
 function toggle(link, id) {
   var e = document.getElementById(id);
   if (e.style.display == '') {
@@ -190,11 +191,10 @@ function toggle(link, id) {
 }
 function toggleall(link) {
   var toc = document.getElementsByClassName("TOC");
-  var dls = toc[0].getElementsByTagName("DL");
+  var dls = toc[0].getElementsByClassName("tocsec");
   var atoggles = toc[0].getElementsByClassName("toggle");
-  var disp = dls[0].style.display;
-  var ndisp = (disp == '') ? 'none' : '';
-  var nhtml = (disp == '') ? '@closedtxt' : '@opentxt'
+  var ndisp = xpanded ? 'none' : '';
+  var nhtml = xpanded ? '@closedtxt' : '@opentxt'
 
   for (var i = 0; i < dls.length; i++)
     dls[i].style.display = ndisp;
@@ -202,7 +202,9 @@ function toggleall(link) {
   for (var i = 0; i < atoggles.length; i++)
     atoggles[i].innerHTML = nhtml;
 
-  link.innerHTML = (disp == '') ? '@xpnall' : '@clpsall';
+  link.innerHTML = xpanded ? '@xpnall' : '@clpsall';
+
+  xpanded = !xpanded;
 }
 function tocjump(hash) {
   var toc = document.getElementsByClassName("TOC");
-- 
cgit v1.2.3