| | 153 | /** |
| | 154 | * Close menu and scroll to anchor when an anchor link is clicked. |
| | 155 | * Adapted from TwentyTwenty. |
| | 156 | */ |
| | 157 | document.addEventListener( 'click', function( event ) { |
| | 158 | // If target onclick is <a> with # within the href attribute |
| | 159 | if ( event.target.hash && event.target.hash.includes( '#' ) ) { |
| | 160 | wrapper.classList.remove( id + '-navigation-open', 'lock-scrolling' ); |
| | 161 | twentytwentyoneToggleAriaExpanded( mobileButton ); |
| | 162 | // Wait 550 and scroll to the anchor. |
| | 163 | setTimeout(function () { |
| | 164 | var anchor = document.getElementById(event.target.hash.slice(1)); |
| | 165 | anchor.scrollIntoView(); |
| | 166 | }, 550); |
| | 167 | } |
| | 168 | } ); |
| | 169 | |