Skip to content

Commit b2809cd

Browse files
committed
support navbar menus
1 parent 5794d83 commit b2809cd

File tree

3 files changed

+103
-19
lines changed

3 files changed

+103
-19
lines changed

_includes/nav.html

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,53 @@
1313
<div class="collapse navbar-collapse" id="main-navbar">
1414
<ul class="nav navbar-nav navbar-right">
1515
{% for link in site.navbar-links %}
16-
{% capture before %}{{ link[1] | split: "://" | first }}{% endcapture %}
17-
{% capture after %}{{ link[1] | split: "://" | last }}{% endcapture %}
18-
<li>
19-
{% assign internal = true %}
20-
{% if before != after %}
21-
{% if before == "http" or before == "https" %}
22-
{% assign internal = false %}
23-
{% endif %}
24-
{% endif %}
25-
26-
{% if internal %}
27-
{% capture linkurl %}{{ site.baseurl }}/{{ link[1] }}{% endcapture %}
16+
{% if link[1].first %}
17+
<li class="navlinks-container">
18+
<a class="navlinks-parent" href="javascript:void(0)">{{ link[0] }}</a>
19+
<div class="navlinks-children">
20+
{% for childlink in link[1] %}
21+
{% for linkparts in childlink %}
22+
{% capture before %}{{ linkparts[1] | split: "://" | first }}{% endcapture %}
23+
{% capture after %}{{ linkparts[1] | split: "://" | last }}{% endcapture %}
24+
{% assign internal = true %}
25+
{% if before != after %}
26+
{% if before == "http" or before == "https" %}
27+
{% assign internal = false %}
28+
{% endif %}
29+
{% endif %}
30+
31+
{% if internal %}
32+
{% capture linkurl %}{{ site.baseurl }}/{{ linkparts[1] }}{% endcapture %}
33+
{% else %}
34+
{% capture linkurl %}{{ linkparts[1] }}{% endcapture %}
35+
{% endif %}
36+
37+
<a href="{{ linkurl }}">{{ linkparts[0] }}</a>
38+
{% endfor %}
39+
{% endfor %}
40+
</div>
41+
</li>
2842
{% else %}
29-
{% capture linkurl %}{{ link[1] }}{% endcapture %}
30-
{% endif %}
43+
<li>
44+
{% capture before %}{{ link[1] | split: "://" | first }}{% endcapture %}
45+
{% capture after %}{{ link[1] | split: "://" | last }}{% endcapture %}
46+
{% assign internal = true %}
47+
{% if before != after %}
48+
{% if before == "http" or before == "https" %}
49+
{% assign internal = false %}
50+
{% endif %}
51+
{% endif %}
3152

32-
<a href="{{ linkurl }}">{{ link[0] }}</a>
33-
</li>
34-
{% endfor %}
53+
{% if internal %}
54+
{% capture linkurl %}{{ site.baseurl }}/{{ link[1] }}{% endcapture %}
55+
{% else %}
56+
{% capture linkurl %}{{ link[1] }}{% endcapture %}
57+
{% endif %}
58+
59+
<a href="{{ linkurl }}">{{ link[0] }}</a>
60+
</li>
61+
{% endif %}
62+
{% endfor %}
3563
</ul>
3664
</div>
3765

css/main.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,50 @@ img::-moz-selection {
177177
}
178178
}
179179

180+
/* Multi-level navigation links */
181+
.navbar-custom .nav .navlinks-container {
182+
position: relative;
183+
}
184+
.navbar-custom .nav .navlinks-parent:after {
185+
content: " \25BC";
186+
}
187+
.navbar-custom .nav .navlinks-children {
188+
width: 100%;
189+
display: none;
190+
}
191+
.navbar-custom .nav .navlinks-container .navlinks-children a {
192+
display: block;
193+
padding: 10px;
194+
padding-left: 30px;
195+
background: #f5f5f5;
196+
text-decoration: none !important;
197+
border-width: 0 1px 1px 1px;
198+
}
199+
@media only screen and (max-width: 767px) {
200+
.navbar-custom .nav .navlinks-container.show-children {
201+
background: #eee;
202+
}
203+
.navbar-custom .nav .navlinks-container.show-children .navlinks-children {
204+
display: block;
205+
}
206+
}
207+
@media only screen and (min-width: 768px) {
208+
.navbar-custom .nav .navlinks-container:hover {
209+
background: #eee;
210+
}
211+
.navbar-custom .nav .navlinks-container:hover .navlinks-children {
212+
display: block;
213+
}
214+
.navbar-custom .nav .navlinks-children {
215+
position: absolute;
216+
}
217+
.navbar-custom .nav .navlinks-container .navlinks-children a {
218+
padding-left: 10px;
219+
border: 1px solid #eaeaea;
220+
border-width: 0 1px 1px;
221+
}
222+
}
223+
180224
/* --- Footer --- */
181225

182226
footer {

js/main.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ $(window).scroll(function() {
1010
// On mobile, hide the avatar when expanding the navbar menu
1111
$('#main-navbar').on('show.bs.collapse', function () {
1212
$(".navbar").addClass("top-nav-expanded");
13-
})
13+
});
1414
$('#main-navbar').on('hidden.bs.collapse', function () {
1515
$(".navbar").removeClass("top-nav-expanded");
16-
})
16+
});
17+
18+
// On mobile, when clicking on a multi-level navbar menu, show the child links
19+
$('#main-navbar').on("click", ".navlinks-parent", function(e) {
20+
var target = e.target;
21+
$.each($(".navlinks-parent"), function(key, value) {
22+
if (value == target) {
23+
$(value).parent().toggleClass("show-children");
24+
} else {
25+
$(value).parent().removeClass("show-children");
26+
}
27+
});
28+
});

0 commit comments

Comments
 (0)