Skip to content

Commit 849e4d6

Browse files
committed
Restore burger
1 parent 544cf76 commit 849e4d6

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
document.addEventListener('DOMContentLoaded', () => {
22

3-
// Top bar burger
4-
(function() {
5-
var burger = document.querySelector('.navbar-burger');
6-
var menu = document.querySelector('.navbar-menu');
7-
8-
burger.addEventListener('click', function() {
9-
burger.classList.toggle('is-active');
10-
menu.classList.toggle('is-active');
3+
// Get all "navbar-burger" elements
4+
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
5+
6+
// Check if there are any navbar burgers
7+
if ($navbarBurgers.length > 0) {
8+
9+
// Add a click event on each of them
10+
$navbarBurgers.forEach( el => {
11+
el.addEventListener('click', () => {
12+
13+
// Get the target from the "data-target" attribute
14+
const target = el.dataset.target;
15+
const $target = document.getElementById(target);
16+
17+
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
18+
el.classList.toggle('is-active');
19+
$target.classList.toggle('is-active');
20+
21+
});
1122
});
12-
})();
13-
14-
});
23+
}
24+
25+
});

0 commit comments

Comments
 (0)