texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: * js/info.js: Fix [Contents] link by creating a f


From: Per Bothner
Subject: branch master updated: * js/info.js: Fix [Contents] link by creating a fresh page-node for the ToC.
Date: Tue, 16 Feb 2021 17:51:26 -0500

This is an automated email from the git hooks/post-receive script.

bothner pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new b08e252  * js/info.js: Fix [Contents] link by creating a fresh 
page-node for the ToC.
b08e252 is described below

commit b08e25221d28ff13d10d5c4b07500cf3358aa2b1
Author: Per Bothner <per@bothner.com>
AuthorDate: Tue Feb 16 14:50:55 2021 -0800

    * js/info.js: Fix [Contents] link by creating a fresh page-node for the ToC.
    
    This is done by cloning the ToC from the index.html.
    Cloning is needed because the same table is used for the Sidebar.
---
 ChangeLog  |  6 ++++++
 js/info.js | 35 +++++++++++++++++++++--------------
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cbd750a..5b389fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-02-16  Per Bothner  <per@bothner.com>
+
+       * js/info.js: Fix [Contents] link by creating a fresh page-node for
+       the ToC.  This is done by cloning the ToC from the index.html.
+       Cloning is needed because the same table is used for the Sidebar.
+
 2021-02-16  Gavin Smith  <gavinsmith0123@gmail.com>
 
        srclist-txi fixes
diff --git a/js/info.js b/js/info.js
index dcedcdb..3da6f60 100644
--- a/js/info.js
+++ b/js/info.js
@@ -29,7 +29,8 @@
     EXT: ".html",
     INDEX_NAME: "index.html",
     INDEX_ID: "index",
-    MAIN_ANCHORS: ["Top", "SEC_Contents"],
+    CONTENTS_ID: "SEC_Contents",
+    MAIN_ANCHORS: ["Top"],
     WARNING_TIMEOUT: 3000,
     SCREEN_MIN_WIDTH: 700,
 
@@ -680,15 +681,20 @@
     `----------------------------*/
 
     function
-    Sidebar ()
+    Sidebar (contents_node)
     {
       this.element = document.createElement ("div");
       this.element.setAttribute ("id", "slider");
       var div = document.createElement ("div");
       div.classList.add ("toc-sidebar");
-      var toc = document.querySelector (".contents");
+      var toc = document.querySelector ("#SEC_Contents");
       toc.remove ();
 
+      contents_node.appendChild(toc.cloneNode(true));
+
+      /* Remove table of contents header.  */
+      toc = toc.querySelector(".contents"); // skip ToC header
+
       /* Move contents of <body> into a a fresh <div> to let the components
          treat the index page like other iframe page.  */
       var nav = document.createElement ("nav");
@@ -701,9 +707,6 @@
       div$.appendChild (nav);
       div.appendChild (div$);
       this.element.appendChild (div);
-
-      /* Remove table of contents header.  */
-      document.querySelector (".contents-heading").remove ();
     }
 
     /* Render 'sidebar' according to STATE which is a new state. */
@@ -746,6 +749,7 @@
       this.element.appendChild (div);
       if (linkid_contains_index (pageid))
         load_page (pageid);
+      return div;
     };
 
     Pages.prototype.render = function render (state) {
@@ -872,8 +876,8 @@
         }
 
       /* Create iframe if necessary unless the div is refering to the Index
-         page.  */
-      if ((pageid === config.INDEX_ID) && visible)
+         or Contents page.  */
+      if (pageid === config.INDEX_ID || pageid === config.CONTENTS_ID)
         {
           div.removeAttribute ("hidden");
           /* Unlike iframes, Elements are unlikely to be scrollable (CSSOM
@@ -959,7 +963,7 @@
     function
     post_message (pageid, msg)
     {
-      if (pageid === config.INDEX_ID)
+      if (pageid === config.INDEX_ID || pageid === config.CONTENTS_ID)
         window.postMessage (msg, "*");
       else
         {
@@ -1018,7 +1022,7 @@
             {
               var link = linkid_split (state.current);
               var elem = document.getElementById (link.pageid);
-              if (link.pageid !== config.INDEX_ID)
+              if (link.pageid !== config.INDEX_ID && link.pageid !== 
config.CONTENTS_ID)
                 elem.querySelector ("iframe").focus ();
               else
                 {
@@ -1030,9 +1034,10 @@
             }
         }
       };
-
-      components.add (new Pages (index_div));
-      components.add (new Sidebar ());
+      var pages = new Pages (index_div);
+      components.add (pages);
+      var contents_node = pages.add_div(config.CONTENTS_ID);
+      components.add (new Sidebar (contents_node));
       components.add (new Help_page ());
       components.add (new Minibuffer ());
       components.add (new Echo_area ());
@@ -1167,7 +1172,7 @@
       }
 
       var ul = elem.querySelector ("ul");
-      if (linkid === config.INDEX_ID)
+      if (linkid === config.INDEX_ID || linkid === config.CONTENTS_ID)
         {
           hide_grand_child_nodes (ul);
           res = document.getElementById(linkid);
@@ -1378,6 +1383,8 @@
                   && !external_manual_url_p (href))
               {
                 var linkid = href_hash (href) || config.INDEX_ID;
+                if (linkid === "index.SEC_Contents")
+                    linkid = config.CONTENTS_ID;
                 store.dispatch (actions.set_current_url (linkid));
                 event.preventDefault ();
                 event.stopPropagation ();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]