From 1c29d7d3acee72e35eab9743df24e5de87abb97d Mon Sep 17 00:00:00 2001 From: "Felix W. Dekker" Date: Sun, 17 May 2020 21:06:26 +0200 Subject: [PATCH] Allow arbitrary nesting of nav entries Fixes #1. --- package-lock.json | Bin 337231 -> 337991 bytes package.json | 2 +- src/main/css/nav.css | 8 +++++++- src/main/js/Template.js | 9 ++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index eb78abd76817433dc41ec6724e1f1027a24b72a4..71e6d44c6327f6d42a51fe0ec2169e007282917c 100644 GIT binary patch delta 552 zcmYjOO-NKx80EY7J*LK)`^1LH5>l*1v=DAcoWo&I2mW=-qNUc$Kg*Cy>!0j{)^?ror zMKD~r#bQ3KTAHGB1bdjQGBJv?REw5P>cs2PQ@Z+b^ zjKYDwdh!F!aR2!lx=e0nJr+h=57$C2@_M8b>{uBF&I%9V_B%QSHyzkf@$#=rePJ{$ z(skL|6_t^rLb+e*rcotgaEs=V-r-TSZ1Co+#bW=nkT+H>q;|LoCu3MB3Et}qe6EVC wR4{|PJx6=BwMJ>bJrDOaJBi&fotOPdplMvkTswXGadDk=FEyYDcG6>x?Lr1B-zBi=9H{A1`@0{;D_uHxU ul, .nav ul li:focus-within > ul, .nav ul li ul:hover { @@ -70,5 +75,6 @@ } .nav ul li ul li { + min-width: 7em; width: 100%; } diff --git a/src/main/js/Template.js b/src/main/js/Template.js index d4d48b9..77f7eb7 100644 --- a/src/main/js/Template.js +++ b/src/main/js/Template.js @@ -61,15 +61,18 @@ export const nav = function () { * Unpacks a navigation entry returned from the navigation API into an HTML element. * * @param entry {Object} the entry to unpack + * @param [depth] {Object} the current nesting level * @returns {HTMLElement} the navigation list entry as HTML, described by its children */ -const unpackEntry = function (entry) { +const unpackEntry = function (entry, depth = 0) { if (entry.entries.length === 0) return h("li", h("a", {href: entry.link, innerHTML: entry.name})); + const arrow = depth === 0 ? "▾" : "▸" + return h("li", - h("a", {href: entry.link, innerHTML: `${entry.name} ▾`}), - h("ul", entry.entries.map(it => unpackEntry(it))) + h("a", {href: entry.link, innerHTML: `${entry.name} ${arrow}`}), + h("ul", entry.entries.map(it => unpackEntry(it, depth + 1))) ); };