1
1
/*
2
- * mburger webcomponent v1.3.1
2
+ * mburger webcomponent v1.3.2
3
3
* mmenujs.com/mburger
4
4
*
5
5
* Copyright (c) Fred Heusschen
@@ -15,24 +15,47 @@ mBurger.innerHTML = `
15
15
<b></b>
16
16
<b></b>
17
17
<slot></slot>` ;
18
- customElements . define ( 'm-burger' , class extends HTMLElement {
19
- constructor ( ) {
20
- super ( ) ;
21
- /** The menu node. */
22
- this . menuNode = null ;
23
- /** API for the menu. */
24
- this . menuApi = null ;
25
- // Attach shadow DOM
26
- var content = mBurger . content . cloneNode ( true ) ;
27
- this . attachShadow ( { mode : 'open' } ) . appendChild ( content ) ;
28
- }
29
- static get observedAttributes ( ) {
30
- return [ 'menu' ] ;
31
- }
32
- attributeChangedCallback ( name , oldValue , newValue ) {
33
- if ( name == 'menu' ) {
34
- // Set the new menu node and API.
35
- this . setMenu ( newValue ) ;
18
+ customElements . define (
19
+ 'm-burger' ,
20
+ class extends HTMLElement {
21
+ constructor ( ) {
22
+ super ( ) ;
23
+ /** The menu node. */
24
+ this . menuNode = null ;
25
+ /** API for the menu. */
26
+ this . menuApi = null ;
27
+ // Attach shadow DOM
28
+ var content = mBurger . content . cloneNode ( true ) ;
29
+ this . attachShadow ( { mode : 'open' } ) . appendChild ( content ) ;
30
+ }
31
+ static get observedAttributes ( ) {
32
+ return [ 'menu' ] ;
33
+ }
34
+ attributeChangedCallback ( name , oldValue , newValue ) {
35
+ if ( name == 'menu' ) {
36
+ // Set the new menu node and API.
37
+ this . initMenu ( newValue ) ;
38
+ }
39
+ }
40
+ connectedCallback ( ) {
41
+ // Open the menu when clicking the hamburger.
42
+ this . addEventListener ( 'click' , evnt => {
43
+ if ( this . menuApi && this . menuApi . open ) {
44
+ this . menuApi . open ( ) ;
45
+ }
46
+ } ) ;
47
+ }
48
+ /**
49
+ * Set the menu node and API.
50
+ * @param {string } id The ID-attribute for the menu node.
51
+ */
52
+ initMenu ( id ) {
53
+ this . menuNode = id ? document . getElementById ( id ) : null ;
54
+ this . menuApi = null ;
55
+ if ( this . menuNode ) {
56
+ this . menuApi =
57
+ this . menuNode [ 'mmApi' ] || this . menuNode [ 'mmenu' ] || null ;
58
+ }
36
59
// Change the hamburger state when opening and closing the menu.
37
60
if ( this . menuApi ) {
38
61
this . menuApi . bind ( 'open:after' , ( ) => {
@@ -44,24 +67,4 @@ customElements.define('m-burger', class extends HTMLElement {
44
67
}
45
68
}
46
69
}
47
- connectedCallback ( ) {
48
- // Open the menu when clicking the hamburger.
49
- this . addEventListener ( 'click' , evnt => {
50
- if ( this . menuApi && this . menuApi . open ) {
51
- this . menuApi . open ( ) ;
52
- }
53
- } ) ;
54
- }
55
- /**
56
- * Set the menu node and API.
57
- * @param {string } id The ID-attribute for the menu node.
58
- */
59
- setMenu ( id ) {
60
- this . menuNode = id ? document . getElementById ( id ) : null ;
61
- this . menuApi = null ;
62
- if ( this . menuNode ) {
63
- this . menuApi =
64
- this . menuNode [ 'mmApi' ] || this . menuNode [ 'mmenu' ] || null ;
65
- }
66
- }
67
- } ) ;
70
+ ) ;
0 commit comments