Skip to content

Commit 1f2b084

Browse files
author
Fred Heusschen
committed
bugfix
1 parent baac45d commit 1f2b084

11 files changed

+106
-64
lines changed

bin/mburger.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* mburger webcomponent v1.3.2
2+
* mburger webcomponent v1.3.3
33
* mmenujs.com/mburger
44
*
55
* Copyright (c) Fred Heusschen
@@ -31,25 +31,38 @@ customElements.define('m-burger', class extends HTMLElement {
3131
}
3232
attributeChangedCallback(name, oldValue, newValue) {
3333
if (name == 'menu') {
34-
// Set the new menu node and API.
34+
// Initiate the new menu.
3535
this.initMenu(newValue);
3636
}
3737
}
3838
connectedCallback() {
3939
// Open the menu when clicking the hamburger.
4040
this.addEventListener('click', evnt => {
41+
// If there is no API for a menu available (the menu isn't yet initiated),
42+
// try to initiate the menu.
43+
if (!this.menuApi) {
44+
this.initMenu();
45+
}
46+
// If there is an API for a menu available,
47+
// open the menu.
4148
if (this.menuApi && this.menuApi.open) {
4249
this.menuApi.open();
4350
}
4451
});
4552
}
4653
/**
4754
* Set the menu node and API.
48-
* @param {string} id The ID-attribute for the menu node.
55+
* @param {string} [id] The ID-attribute for the menu node.
4956
*/
5057
initMenu(id) {
51-
this.menuNode = id ? document.getElementById(id) : null;
58+
this.menuNode = null;
5259
this.menuApi = null;
60+
if (!id) {
61+
id = this.getAttribute('menu');
62+
}
63+
if (id) {
64+
this.menuNode = document.getElementById(id);
65+
}
5366
if (this.menuNode) {
5467
this.menuApi =
5568
this.menuNode['mmApi'] || this.menuNode['mmenu'] || null;

bin/webcomponent.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mburger-css",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"authors": "Fred Heusschen <[email protected]>",
55
"license": "CC-BY-4.0",
66
"description": "A small collection of CSS animated hamburgers. All set up to work out of the box with the mmenu.js plugin.",

dist/mburger.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)