@@ -23,6 +23,12 @@ document.addEventListener('DOMContentLoaded', function () {
23
23
document . body . classList . toggle ( 'md:hx-overflow-auto' ) ;
24
24
}
25
25
26
+ function hideOverlay ( ) {
27
+ // Hide the overlay
28
+ overlay . classList . remove ( ...overlayClasses ) ;
29
+ overlay . classList . add ( 'hx-bg-transparent' ) ;
30
+ }
31
+
26
32
menu . addEventListener ( 'click' , ( e ) => {
27
33
e . preventDefault ( ) ;
28
34
toggleMenu ( ) ;
@@ -33,8 +39,7 @@ document.addEventListener('DOMContentLoaded', function () {
33
39
overlay . classList . remove ( 'hx-bg-transparent' ) ;
34
40
} else {
35
41
// Hide the overlay
36
- overlay . classList . remove ( ...overlayClasses ) ;
37
- overlay . classList . add ( 'hx-bg-transparent' ) ;
42
+ hideOverlay ( ) ;
38
43
}
39
44
} ) ;
40
45
@@ -43,7 +48,23 @@ document.addEventListener('DOMContentLoaded', function () {
43
48
toggleMenu ( ) ;
44
49
45
50
// Hide the overlay
46
- overlay . classList . remove ( ...overlayClasses ) ;
47
- overlay . classList . add ( 'hx-bg-transparent' ) ;
51
+ hideOverlay ( ) ;
52
+ } ) ;
53
+
54
+ // Select all anchor tags in the sidebar container
55
+ const sidebarLinks = sidebarContainer . querySelectorAll ( 'a' ) ;
56
+
57
+ // Add click event listener to each anchor tag
58
+ sidebarLinks . forEach ( link => {
59
+ link . addEventListener ( 'click' , ( e ) => {
60
+ // Check if the href attribute contains a hash symbol (links to a heading)
61
+ if ( link . getAttribute ( 'href' ) && link . getAttribute ( 'href' ) . startsWith ( '#' ) ) {
62
+ // Only dismiss overlay on mobile view
63
+ if ( window . innerWidth < 768 ) {
64
+ toggleMenu ( ) ;
65
+ hideOverlay ( ) ;
66
+ }
67
+ }
68
+ } ) ;
48
69
} ) ;
49
70
} ) ;
0 commit comments