Skip to content

Commit cd5db8f

Browse files
committed
INFRA: add dropdown
1 parent 7ba0518 commit cd5db8f

File tree

3 files changed

+530
-70
lines changed

3 files changed

+530
-70
lines changed

_data/navigation.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
# main links
22
main:
33
- title: "Peer Review & Packages"
4-
url: /python-packages/
4+
url:
5+
sub-nav:
6+
- title: "About peer review"
7+
icon: "fas fa-fw fa-envelope-square"
8+
url: "/about-peer-review/"
9+
url: "/python-packages/"
10+
- title: "Peer review guide"
11+
url: "https://www.pyopensci.org/contributing-guide/"
12+
- title: "Python package guide"
13+
url: "https://www.pyopensci.org/python-package-guide/"
14+
- title: "Our packages"
15+
icon: "fas fa-fw fa-envelope-square"
516
- title: "Blog"
617
url: /blog/
7-
- title: "Resources"
8-
url: /resources/
9-
- title: "Our Community"
10-
url: /our-community/
18+
# - title: "Resources"
19+
# url: /resources/
20+
- title: "Community"
21+
sub-nav:
22+
- title: "Our Community"
23+
url: "/our-community/"
24+
- title: "Governance"
25+
icon: "fas fa-fw fa-envelope-square"
26+
url: "https://www.pyopensci.org/governance/"
1127
- title: "Contact"
1228
url: /get-involved-contact/

_includes/masthead.html

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{% capture logo_path %}{{ site.logo }}{% endcapture %}
2+
3+
<div class="masthead">
4+
<div class="masthead__inner-wrap">
5+
<div class="masthead__menu">
6+
<nav id="site-nav" class="nav__topbar" aria-label="Main Navigation">
7+
<!-- More accessible as a screen reader will group the title and image in the same link -->
8+
{% unless logo_path == empty %}
9+
<a class="site-logo" href="{{ '/' | relative_url }}">
10+
<img src="{{ logo_path | relative_url }}" alt="{{ site.masthead_title | default: site.title }}">
11+
<span class="site-title">pyOpenSci</span>
12+
</a>
13+
{% endunless %}
14+
15+
<ul class="nav__links">
16+
{%- for alink in site.data.navigation.main -%}
17+
{% if alink.sub-nav %}
18+
<!-- If there is sub nav to display -->
19+
<li class="dropdown">
20+
<button class="dropbtn">{{ alink.title }} <i class="fas fa-caret-down"></i>
21+
</button>
22+
<ul class="dropdown-content">
23+
{% for subnav in alink.sub-nav %}
24+
<li>
25+
<a href="{{ subnav.url }}" class="masthead__menu-item hover-underline">{{ subnav.title }}</a>
26+
</li>
27+
{% endfor %}
28+
</ul>
29+
</li>
30+
{% else %}
31+
<li>
32+
<a href="{{ alink.url | relative_url }}" class="hover-underline">{{ alink.title }}</a>
33+
</li>
34+
{% endif %}
35+
{% endfor %}
36+
</ul>
37+
<!-- Burger button - span class for screen readers-->
38+
<button class="hamburger__btn-toggle" type="button" count="1">
39+
<span class="visually-hidden">Toggle menu</span> <!--screen readers-->
40+
<div class="burger__icon"></div>
41+
</button>
42+
</nav>
43+
</div>
44+
</div>
45+
</div>
46+
</div>
47+
{% if site.search == true %}
48+
<button class="search__toggle" type="button">
49+
<span class="visually-hidden">{{ site.data.ui-text[site.locale].search_label | default: "Toggle search" }}</span>
50+
<i class="fas fa-search"></i>
51+
</button>
52+
{% endif %}
53+
<ul class="hidden-links hidden"></ul>
54+
</nav>
55+
</div>
56+
</div>
57+
</div>
58+
59+
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
60+
<script>
61+
$(document).ready(function () {
62+
$(".hamburger__btn-toggle").click(function (e) {
63+
$(this).toggleClass("close");
64+
e.preventDefault();
65+
$(".nav__links").toggleClass("vertical");
66+
});
67+
68+
$(".dropdown").click(function (e) {
69+
e.stopPropagation();
70+
e.preventDefault();
71+
// close when click outside
72+
$(this).find(".dropdown-content").toggleClass("open");
73+
$(this).siblings(".dropdown").find(".dropdown-content").removeClass("open");
74+
});
75+
76+
// Close dropdown when u click outside of the nav ul
77+
$(document).click(function (e) {
78+
if (!e.target.closest("ul") && $(".dropdown-content").hasClass("open")) {
79+
$(".dropdown-content").removeClass("open");
80+
}
81+
});
82+
});
83+
84+
</script>

0 commit comments

Comments
 (0)