Skip to content

Commit 0c86174

Browse files
fix: make sidebar bullet markers clickable
1 parent e386a42 commit 0c86174

4 files changed

Lines changed: 114 additions & 4 deletions

File tree

_includes/components/nav.html

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{%- comment -%}
2+
Include as: {%- include components/nav.html pages=pages -%}
3+
Depends on: include.pages.
4+
Results in: HTML for the navigation panel.
5+
Includes:
6+
sorted_pages.html
7+
Overwrites:
8+
nav_pages, first_level_pages, second_level_pages, third_level_pages,
9+
node, children_list, child, grand_children_list, grand_child.
10+
{%- endcomment -%}
11+
12+
{%- assign nav_pages = include.pages
13+
| where_exp: "item", "item.title != nil"
14+
| where_exp: "item", "item.nav_exclude != true" -%}
15+
16+
{%- include sorted_pages.html pages = nav_pages -%}
17+
18+
{%- comment -%}
19+
It might be more efficient to sort the pages at each level separately.
20+
{%- endcomment -%}
21+
22+
{%- assign first_level_pages = sorted_pages
23+
| where_exp: "item", "item.parent == nil" -%}
24+
{%- assign second_level_pages = sorted_pages
25+
| where_exp: "item", "item.parent != nil"
26+
| where_exp: "item", "item.grand_parent == nil" -%}
27+
{%- assign third_level_pages = sorted_pages
28+
| where_exp: "item", "item.grand_parent != nil" -%}
29+
30+
<ul class="nav-list">
31+
{%- for node in first_level_pages -%}
32+
<li class="nav-list-item">
33+
{%- if node.has_children -%}
34+
<button class="nav-list-expander btn-reset" aria-label="toggle items in {{ node.title }} category" aria-pressed="false">
35+
<svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg>
36+
</button>
37+
{%- endif -%}
38+
<a href="{{ node.url | relative_url }}" class="nav-list-link"><span class="nav-bullet">&#9679;</span>{{ node.title }}</a>
39+
{%- if node.has_children -%}
40+
{%- assign children_list = second_level_pages
41+
| where: "parent", node.title -%}
42+
{%- if node.child_nav_order == 'desc' or node.child_nav_order == 'reversed' -%}
43+
{%- assign children_list = children_list | reverse -%}
44+
{%- endif -%}
45+
<ul class="nav-list">
46+
{%- for child in children_list -%}
47+
<li class="nav-list-item">
48+
{%- if child.has_children -%}
49+
<button class="nav-list-expander btn-reset" aria-label="toggle items in {{ child.title }} category" aria-pressed="false">
50+
<svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg>
51+
</button>
52+
{%- endif -%}
53+
<a href="{{ child.url | relative_url }}" class="nav-list-link"><span class="nav-bullet">&#9679;</span>{{ child.title }}</a>
54+
{%- if child.has_children -%}
55+
{%- assign grand_children_list = third_level_pages
56+
| where: "parent", child.title
57+
| where: "grand_parent", node.title -%}
58+
{%- if child.child_nav_order == 'desc' or child.child_nav_order == 'reversed' -%}
59+
{%- assign grand_children_list = grand_children_list | reverse -%}
60+
{%- endif -%}
61+
<ul class="nav-list">
62+
{%- for grand_child in grand_children_list -%}
63+
<li class="nav-list-item">
64+
<a href="{{ grand_child.url | relative_url }}" class="nav-list-link"><span class="nav-bullet">&#9679;</span>{{ grand_child.title }}</a>
65+
</li>
66+
{%- endfor -%}
67+
</ul>
68+
{%- endif -%}
69+
</li>
70+
{%- endfor -%}
71+
</ul>
72+
{%- endif -%}
73+
</li>
74+
{%- endfor -%}
75+
</ul>

_includes/head_custom.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<script src="/assets/js/jquery-3.4.1.min.js"></script>
44
<script src="/assets/js/module.js"></script>
55
<script src="/assets/js/quiz.js"></script>
6-
<script src="/assets/js/global_scripts.js"></script>
6+
<script src="/assets/js/global_scripts.js"></script>
7+
<script defer src="/assets/js/nav-bullets-clickable.js"></script>

_sass/custom/custom.scss

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ $text-color: #111111;
195195
// CV flavored side nav
196196
//
197197
.nav-list {
198-
list-style: circle url("/assets/images/nav-marker-inactive.svg") inside;
198+
list-style: none;
199199

200200
.nav-list-item {
201201
// scss-lint:disable SelectorDepth
@@ -204,7 +204,7 @@ $text-color: #111111;
204204
}
205205

206206
&.active {
207-
list-style: disc url("/assets/images/nav-marker-active.svg") inside;
207+
list-style: none;
208208
}
209209
}
210210

@@ -214,7 +214,15 @@ $text-color: #111111;
214214
}
215215

216216
.nav-list-item.active {
217-
list-style: disc url("/assets/images/nav-marker-active.svg") inside;
217+
list-style: none;
218+
}
219+
220+
.nav-bullet {
221+
color: $body-text-color;
222+
cursor: pointer;
223+
font-size: 1rem;
224+
margin-right: 0.3rem;
225+
vertical-align: middle;
218226
}
219227
}
220228

@@ -315,3 +323,12 @@ button,
315323
top: 0;
316324
z-index: 500;
317325
}
326+
327+
// Fix: make sidebar bullet markers clickable
328+
.nav-list-item {
329+
cursor: pointer;
330+
}
331+
// Fix: sidebar expander arrow should be cursor pointer
332+
.nav-list-expander {
333+
cursor: pointer;
334+
}

assets/js/nav-bullets-clickable.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Fix: make sidebar bullet markers clickable
2+
document.addEventListener("DOMContentLoaded", function () {
3+
document.querySelectorAll(".nav-list-item").forEach(function (item) {
4+
item.addEventListener("click", function (e) {
5+
var link = item.querySelector(".nav-list-link");
6+
var expander = item.querySelector(".nav-list-expander");
7+
if (
8+
link &&
9+
e.target !== link &&
10+
!link.contains(e.target) &&
11+
!(expander && (e.target === expander || expander.contains(e.target)))
12+
) {
13+
link.click();
14+
}
15+
});
16+
});
17+
});

0 commit comments

Comments
 (0)