@@ -11,19 +11,23 @@ class Menu {
1111 this . resizeBreakpoint = window . matchMedia ( '(min-width: 1024px)' )
1212 }
1313 init ( ) {
14- // Events to handle toggle menu
15- this . menuOpen . addEventListener ( 'click' , this . openMenu . bind ( this ) , false )
16- this . menuClose . addEventListener ( 'click' , this . closeMenu . bind ( this ) , false )
17- // Detect if clicked outside menu
18- document . addEventListener ( 'click' , event => {
19- const menu = this . menu . contains ( event . target )
20- const buttonContainer = this . buttonContainer . contains ( event . target )
21- if ( ! menu && ! buttonContainer ) {
22- this . closeMenu ( )
23- }
24- } )
25- // Event breakpoint
26- this . resizeBreakpoint . addListener ( this . menuResizing . bind ( this ) )
14+ if ( this . menu ) {
15+ // Events to handle toggle menu
16+ this . menuOpen . addEventListener ( 'click' , this . openMenu . bind ( this ) , false )
17+ this . menuClose . addEventListener ( 'click' , this . closeMenu . bind ( this ) , false )
18+ // Detect if clicked outside menu
19+ document . addEventListener ( 'click' , event => {
20+ const menu = this . menu . contains ( event . target )
21+ const buttonContainer = this . buttonContainer . contains ( event . target )
22+ if ( ! menu && ! buttonContainer ) {
23+ this . closeMenu ( )
24+ }
25+ } )
26+ // Event breakpoint
27+ this . resizeBreakpoint . addListener ( this . menuResizing . bind ( this ) )
28+ } else {
29+ console . log ( 'No menu' )
30+ }
2731 }
2832 /**
2933 * Open menu
0 commit comments