| 114 | | if ( mobileButton ) { |
| 115 | | mobileButton.onclick = function() { |
| 116 | | wrapper.classList.toggle( id + '-navigation-open' ); |
| 117 | | wrapper.classList.toggle( 'lock-scrolling' ); |
| 118 | | twentytwentyoneToggleAriaExpanded( mobileButton ); |
| 119 | | mobileButton.focus(); |
| | 114 | if (mobileButton) { |
| | 115 | let scrollPosition = 0; // To store the current scroll position |
| | 116 | |
| | 117 | mobileButton.onclick = function () { |
| | 118 | const isMenuOpen = wrapper.classList.contains(id + '-navigation-open'); |
| | 119 | |
| | 120 | if (!isMenuOpen) { |
| | 121 | // Save the scroll position when opening the menu |
| | 122 | scrollPosition = window.scrollY; |
| | 123 | } |
| | 124 | |
| | 125 | wrapper.classList.toggle(id + '-navigation-open'); |
| | 126 | wrapper.classList.toggle('lock-scrolling'); |
| | 127 | twentytwentyoneToggleAriaExpanded(mobileButton); |
| | 128 | |
| | 129 | if (isMenuOpen) { |
| | 130 | // Restore scroll position when closing the menu |
| | 131 | window.scrollTo(0, scrollPosition); |
| | 132 | } |