-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.js
More file actions
59 lines (52 loc) · 1.51 KB
/
Copy pathmenu.js
File metadata and controls
59 lines (52 loc) · 1.51 KB
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
(function () {
const menus = document.querySelectorAll('.apply-menu');
const header = document.querySelector('.site-header');
const toggle = document.querySelector('.menu-toggle');
function closeAll(except) {
menus.forEach(function (menu) {
if (menu !== except) menu.removeAttribute('open');
});
}
function setNav(open) {
if (!header || !toggle) return;
header.classList.toggle('is-open', open);
toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
}
if (toggle) {
toggle.addEventListener('click', function () {
setNav(!header.classList.contains('is-open'));
});
}
document.addEventListener('click', function (event) {
const menu = event.target.closest('.apply-menu');
if (event.target.closest('.nav a')) {
closeAll();
setNav(false);
return;
}
if (!menu) closeAll();
});
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape') {
closeAll();
setNav(false);
}
});
window.addEventListener('resize', function () {
if (window.innerWidth > 680) setNav(false);
});
document.querySelectorAll('.page-back').forEach(function (link) {
link.addEventListener('click', function (event) {
let fromSite = false;
try {
fromSite = new URL(document.referrer).origin === location.origin;
} catch (err) {
fromSite = false;
}
if (fromSite && history.length > 1) {
event.preventDefault();
history.back();
}
});
});
})();