Make WordPress Core

Changeset 36371


Ignore:
Timestamp:
01/21/2016 06:07:45 AM (7 years ago)
Author:
westonruter
Message:

Customizer: Fix click.preview event handler for jump links and shift+clicks in preview.

  • Prevent following jump links (starting with #), but instead scroll that element into view.
  • Prevent following links clicked in the Customizer if shift key is pressed when clicking; this fixes an issue when trying to shift-click on a widget or nav menu item (#32681) to just focus on the control in the Customizer.

Fixes #26005.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/customize-preview.js

    r35391 r36371  
    3434    api.Preview = api.Messenger.extend({
    3535        /**
    36          * @param {string} url The URL of preview frame
     36         * @param {object} params  - Parameters to configure the messenger.
     37         * @param {object} options - Extend any instance parameter or method with this object.
    3738         */
    3839        initialize: function( params, options ) {
     
    4344            this.body = $( document.body );
    4445            this.body.on( 'click.preview', 'a', function( event ) {
     46                var link, isInternalJumpLink;
     47                link = $( this );
     48                isInternalJumpLink = ( '#' === link.attr( 'href' ).substr( 0, 1 ) );
    4549                event.preventDefault();
     50
     51                if ( isInternalJumpLink && '#' !== link.attr( 'href' ) ) {
     52                    $( link.attr( 'href' ) ).each( function() {
     53                        this.scrollIntoView();
     54                    } );
     55                }
     56
     57                /*
     58                 * Note the shift key is checked so shift+click on widgets or
     59                 * nav menu items can just result on focusing on the corresponding
     60                 * control instead of also navigating to the URL linked to.
     61                 */
     62                if ( event.shiftKey || isInternalJumpLink ) {
     63                    return;
     64                }
    4665                self.send( 'scroll', 0 );
    47                 self.send( 'url', $(this).prop('href') );
     66                self.send( 'url', link.prop( 'href' ) );
    4867            });
    4968
Note: See TracChangeset for help on using the changeset viewer.