2 Commits 4ec77747d8 ... 19668620d6

Author SHA1 Message Date
  Mathieu Lirzin 19668620d6 index: Handle '<' and '>' keys 6 years ago
  Mathieu Lirzin b9f7488595 sidebar: Fix added table of content link 6 years ago
5 changed files with 28 additions and 9 deletions
  1. 8 0
      js/src/actions.js
  2. 3 1
      js/src/index.js
  3. 12 7
      js/src/reducers.js
  4. 2 1
      js/src/sidebar.js
  5. 3 0
      js/src/toc.js

+ 8 - 0
js/src/actions.js

@@ -28,6 +28,14 @@ set_current_url (url)
   return { type: CURRENT_URL, url };
 }
 
+/** Set current URL to the node corresponding to POINTER which is an
+    id refering to a linkid (such as "*TOP*" or "*END*"). */
+export function
+set_current_url_pointer (pointer)
+{
+  return { type: CURRENT_URL, pointer };
+}
+
 export const NAVIGATE = "navigate";
 
 export function

+ 3 - 1
js/src/index.js

@@ -89,7 +89,9 @@ on_keypress.dict = {
   p: [actions.navigate, "prev"],
   u: [actions.navigate, "up"],
   "]": [actions.navigate, "forward"],
-  "[": [actions.navigate, "backward"]
+  "[": [actions.navigate, "backward"],
+  "<": [actions.set_current_url_pointer, "*TOP*"],
+  ">": [actions.set_current_url_pointer, "*END*"]
 };
 
 /*--------------------

+ 12 - 7
js/src/reducers.js

@@ -38,19 +38,24 @@ global_reducer (state, action)
     case CACHE_LINKS:
       {
         let clone = Object.assign ({}, state.loaded_nodes);
-        for (let key in action.links)
-          {
-            if (action.links.hasOwnProperty (key))
+        Object
+          .keys (action.links)
+          .forEach (key => {
+            if (typeof action.links[key] === "object")
               clone[key] = Object.assign ({}, clone[key], action.links[key]);
-          }
+            else
+              clone[key] = action.links[key];
+          });
+
         return Object.assign ({}, state, { loaded_nodes: clone, action });
       }
     case CURRENT_URL:
       {
-        let res = Object.assign ({}, state, { current: action.url, action });
+        let url = (action.pointer) ?
+            state.loaded_nodes[action.pointer] : action.url;
+        let res = Object.assign ({}, state, { current: url, action });
         res.text_input_visible = false;
-        if (!res.loaded_nodes[action.url])
-          res.loaded_nodes[action.url] = {};
+        res.loaded_nodes[url] = res.loaded_nodes[url] || {};
         return res;
       }
     case NAVIGATE:

+ 2 - 1
js/src/sidebar.js

@@ -111,7 +111,6 @@ on_load ()
   document.head.appendChild (base);
 
   let links = Array.from (document.links);
-  fix_links (links);
 
   /* Create a link referencing the Table of content.  */
   let toc_a = document.createElementNS (config.XHTML_NAMESPACE, "a");
@@ -126,6 +125,8 @@ on_load ()
     index_li = index_grand;
   index_li.parentNode.insertBefore (toc_li, index_li.nextSibling);
 
+  links.push (toc_a);
+  fix_links (links);
   scan_toc (document.body, config.INDEX_NAME);
 
   let divs = Array.from (document.querySelectorAll ("div"));

+ 3 - 0
js/src/toc.js

@@ -157,6 +157,9 @@ create_link_dict (nav)
   }
 
   depth_first_walk (nav, add_link, Node.ELEMENT_NODE);
+  /* Add a reference to the first and last node of the manual.  */
+  links["*TOP*"] = config.INDEX_ID;
+  links["*END*"] = prev_id;
   return links;
 }