Skip to content

Commit 9573c52

Browse files
authored
Merge pull request #11 from niheno/patch-1
Add Javascript support for navbar burger
2 parents 2d31da8 + ed845c9 commit 9573c52

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/bulma-stubs/app.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,28 @@ const app = new Vue({
2323

2424

2525
require('./bulma-extensions');
26+
27+
document.addEventListener('DOMContentLoaded', function () {
28+
// Get all "navbar-burger" elements
29+
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
30+
31+
// Check if there are any navbar burgers
32+
if ($navbarBurgers.length > 0) {
33+
34+
// Add a click event on each of them
35+
$navbarBurgers.forEach(function ($el) {
36+
$el.addEventListener('click', function () {
37+
38+
// Get the target from the "data-target" attribute
39+
let target = $el.dataset.target;
40+
let $target = document.getElementById(target);
41+
42+
// Toggle the class on both the "navbar-burger" and the "navbar-menu"
43+
$el.classList.toggle('is-active');
44+
$target.classList.toggle('is-active');
45+
46+
});
47+
});
48+
}
49+
50+
});

0 commit comments

Comments
 (0)