Make WordPress Core

Changeset 47829


Ignore:
Timestamp:
05/19/2020 10:48:49 PM (5 years ago)
Author:
whyisjake
Message:

Bundled Themes: Twenty Twenty anchor links don't work in mobile menu.
Modifies the mobile modal menu javascript, so that anchor links will close the modal and scroll to the anchor within the page.

This brings the changes from [47784] to the 5.4 branch.

Props Giorgio25b, suzylah, yuhin, samful, bdcstr.
Fixes #48916.

Location:
branches/5.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

  • branches/5.4/src/wp-content/themes/twentytwenty/assets/js/index.js

    r47122 r47829  
    137137            var target = event.target;
    138138            var modal = document.querySelector( '.cover-modal.active' );
     139
     140            // if target onclick is <a> with # within the href attribute
     141            if ( event.target.tagName.toLowerCase() === 'a' && event.target.hash.includes( '#' ) && modal !== null ) {
     142                // untoggle the modal
     143                this.untoggleModal( modal );
     144                // wait 550 and scroll to the anchor
     145                setTimeout( function() {
     146                    var anchor = document.getElementById( event.target.hash.slice( 1 ) );
     147                    anchor.scrollIntoView();
     148                }, 550 );
     149            }
    139150
    140151            if ( target === modal ) {
Note: See TracChangeset for help on using the changeset viewer.