-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnav.html
266 lines (251 loc) · 8.86 KB
/
nav.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
{% assign nav = site.data.navigation.languages[lang] | default:
site.data.navigation.languages.en %} {% assign url_parts = page.url | split: '/'
%} {% assign parentUrl = page.parentUrl %} {% unless parentUrl %} {% assign
parentUrl = url_parts | slice: 0, 2 | join: "/" | append: "/" %} {% endunless %}
<aside
id="Nav" class="Nav container-fluid h-100 position-fixed d-md-block g-0"
style="z-index: var(--z-index-aside)"
aria-label="website menu"
>
<div class="row g-0 h-100">
<div class="col-sm-12 col-md-3 col-lg-3 col-xl-2 col-xxl-2 d-flex flex-column h-100 g-0">
<ul class="nav flex-column flex-grow-1 mb-3">
<li
class="nav-item squared position-relative"
>
<a href="/" class="position-absolute start-0 mt-2 ms-2 top-0" >
<button type="button" class="btn btn-simple" aria-label="go to home page">
<span class="icon-container">
{% include icons/home-simple-door.html %}</span
>
</button>
</a>
<button
type="button"
aria-label="toggle dark mode"
class="position-absolute end-0 top-0 mt-2 me-2 btn btn-simple"
id="Nav__darkModeToggler"
>
<span class="icon-container">
{% include icons/dark-mode.html %}</span
>
</button>
<div
class="position-absolute top-0 start-0 end-0 bottom-0 d-flex align-items-center justify-content-center"
>
{% comment %} logo {% endcomment %}
<a class="nav-link" href="{{site.baseurl}}/">
<div>{% include logos/Impresso-logo.svg %}</div>
</a>
</div>
</li>
<!-- <li>{{ parentUrl }}</li> -->
{% for item in nav.links %}
<li
class="nav-item ms-5 position-relative {% if item.links %} with-links {% endif %}{% if item.url == parentUrl %} force-open open active {% endif %}{% if item.url == page.url %} active {% endif %}"
>
<a class="nav-link small-caps" href="{{ item.url }}" tabindex="0"
><span>{{ item.title }}</span></a
>
{% if item.links %}
<button
class="btn btn-transparent Nav__dropdownToggler position-absolute"
aria-label="toggle sub-menu"
>
{% include icons/plus.html %}
</button>
<ul>
{% for subitem in item.links %}
<li
class="nav-item {% if subitem.url == page.url %} active {% endif %} {% if item.url == parentUrl %} open {% endif %}"
>
<a class="nav-link" href="{{ subitem.url }}" tabindex="0"
><span>{{ subitem.title }}</span></a
>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
<div class="side-menu-footer flex-shrink-1">
<ul class="d-flex w-100 justify-content-between">
<li class="nav-item ms-2">
<a
class="nav-link"
href="mailto:[email protected]"
title="email"
target="_blank"
>
<button type="button" class="btn btn-simple">
<span class="icon-container">
{% include icons/email.svg %}</span
>
</button>
</a>
</li>
<li class="nav-item">
<a
class="nav-link"
href="{{site.contacts.twitter.url}}"
title="our twitter account"
target="_blank"
>
<button type="button" class="btn btn-simple">
<span class="icon-container x"> {% include icons/x.svg %}</span>
</button>
</a>
</li>
<li class="nav-item me-2">
<a
class="nav-link"
href="{{site.contacts.github.url}}"
title="our github account"
target="_blank"
>
<button type="button" class="btn btn-simple">
<span class="icon-container">
{% include icons/github.svg %}</span
>
</button>
</a>
</li>
</ul>
<a
id="chimpSignup"
href="{{site.contacts.mailinglist.url}}"
target="_blank" class="btn btn-simple small-caps mb-4 me-2 ms-2 d-block">
Join our mailing list
</a>
</div>
</div>
</aside>
<script>
const navDarkModeToggler = document.querySelector("#Nav__darkModeToggler");
const htmlBodyElement = document.querySelector("body");
// read current dark mode from localStorage
const darkMode = localStorage.getItem("darkMode")
// Check if the user prefers dark mode
const isPreferredColorSchemeDark = window.matchMedia?.('(prefers-color-scheme: dark)')?.matches;
// add initial class based on localStorage
if (darkMode) {
navDarkModeToggler.classList.add("active");
htmlBodyElement.classList.add(darkMode);
} else if (isPreferredColorSchemeDark) {
htmlBodyElement.classList.add("dark");
} else {
htmlBodyElement.classList.add("light");
}
console.info("[nav] darkMode:", darkMode, 'isPreferredColorSchemeDark:', isPreferredColorSchemeDark);
// onclick, toggle dark mode
navDarkModeToggler.addEventListener("click", () => {
const isDark = htmlBodyElement.classList.contains("dark")
const isLight = htmlBodyElement.classList.contains("light")
if (isDark) {
htmlBodyElement.classList.remove("dark");
htmlBodyElement.classList.add("light");
} else if (isLight) {
htmlBodyElement.classList.remove("light");
htmlBodyElement.classList.add("dark");
}
const currentDarkMode = isDark ? "light" : "dark";
// store current dark mode in localStorage only if differs from preferred color scheme
if ((currentDarkMode ==="light" && isPreferredColorSchemeDark) || (currentDarkMode ==="dark" && !isPreferredColorSchemeDark)) {
console.info("[nav] @click store in localStorage \n - darkMode:", currentDarkMode,'\n - isPreferredColorSchemeDark:', isPreferredColorSchemeDark)
localStorage.setItem("darkMode", currentDarkMode);
// is active
navDarkModeToggler.classList.add("active");
} else {
console.info("[nav] @click remove from localStorage \n - darkMode:", currentDarkMode,'\n - isPreferredColorSchemeDark:', isPreferredColorSchemeDark)
localStorage.removeItem("darkMode");
// is not active
navDarkModeToggler.classList.remove("active");
}
});
// on click on the nav, open the <ul>
const navDropdownTogglers = document.querySelectorAll(
".Nav__dropdownToggler"
);
let openedNavItem = null;
function closeNavItem(item, ul) {
item.classList.remove("open");
ul.style.height = 0;
}
function openNavItem(item, ul) {
item.classList.add("open");
const hiddenHeight = ul.scrollHeight;
ul.style.height = hiddenHeight + "px";
}
navDropdownTogglers.forEach((toggler) => {
if (toggler.parentElement.classList.contains("open")) {
openedNavItem = toggler.parentElement;
}
toggler.addEventListener("click", (e) => {
const navItem = e.currentTarget.parentElement;
const ul = e.currentTarget.nextElementSibling;
const isOpen = navItem.classList.contains("open");
console.debug("[navDropdownTogglers] isOpen:", isOpen);
if (isOpen) {
closeNavItem(navItem, ul);
} else {
if (openedNavItem && openedNavItem != navItem) {
closeNavItem(openedNavItem, openedNavItem.querySelector("ul"));
}
openedNavItem = navItem;
openNavItem(navItem, ul);
}
});
});
</script>
<style>
.Nav li.nav-item.squared {
padding-top: 250px;
transition: all 0.3s ease-in-out;
}
#MenuToggler .icon-container{
flex-direction: column;
}
#MenuToggler .menu-bar{
display: block;
width: 16px;
margin: 1px auto;
height: 2px;
background-color: var(--bs-dark);
}
#MenuToggler:hover .menu-bar,
#MenuToggler:focus .menu-bar{
background-color: var(--bs-dark-fixed);
}
@media (max-width: 768px) {
.Nav.mobile {
position: fixed !important;
display: block !important;
left: 0;
top: 0;
right: 0;
bottom: 0;
width: 100% !important;
height: 100% !important;
background-color: var(--bs-light);
transform: translateX(0%);
}
#Nav__darkModeToggler {
right: calc(50% - 26px) !important;
}
.Nav.mobile li.nav-item.squared {
padding-top: 210px;
}
.Nav {
background-color: var(--bs-light);
transform: translateX(-100%);
transition: transform 0.3s ease-in-out;
}
}
</style>
<script>
function toggleMenuClass() {
var myParagraph = document.getElementById('Nav');
myParagraph.classList.toggle('mobile');
}
</script>