WordPress.org

Make WordPress Core

Changeset 33491


Ignore:
Timestamp:
07/29/2015 06:12:26 PM (5 years ago)
Author:
westonruter
Message:

Twenty Fifteen: Only re-initialize the main navigation in the Customizer when it is specifically updated.

  • Fix a bug where updating the social menu links would cause the main navigation to get its toggle-expanded buttons duplicated.
  • Persist any existing submenu expanded states on the updated menu.
  • Improve naming of customize-preview-menu-refreshed event param from wpNavArgs to wpNavMenuArgs (old name is retained and marked as deprecated).

Fixes #33177.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfifteen/js/functions.js

    r32807 r33491  
    1212        secondary, button;
    1313
    14 
    15     function initMainNavigation() {
     14    function initMainNavigation( container ) {
    1615        // Add dropdown toggle that display child menu items.
    17         $( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
     16        container.find( '.menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
    1817
    1918        // Toggle buttons and submenu items with active children menu items.
    20         $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' );
    21         $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
     19        container.find( '.current-menu-ancestor > button' ).addClass( 'toggle-on' );
     20        container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
    2221
    23         $( '.dropdown-toggle' ).click( function( e ) {
     22        container.find( '.dropdown-toggle' ).click( function( e ) {
    2423            var _this = $( this );
    2524            e.preventDefault();
     
    3029        } );
    3130    }
    32     initMainNavigation();
    33     $( document ).on( 'customize-preview-menu-refreshed', initMainNavigation );
     31    initMainNavigation( $( '.main-navigation' ) );
     32
     33    // Re-initialize the main navigation when it is updated, persisting any existing submenu expanded states.
     34    $( document ).on( 'customize-preview-menu-refreshed', function( e, params ) {
     35        if ( 'primary' === params.wpNavMenuArgs.theme_location ) {
     36            initMainNavigation( params.newContainer );
     37
     38            // Re-sync expanded states from oldContainer.
     39            params.oldContainer.find( '.dropdown-toggle.toggle-on' ).each(function() {
     40                var containerId = $( this ).parent().prop( 'id' );
     41                $( params.newContainer ).find( '#' + containerId + ' > .dropdown-toggle' ).triggerHandler( 'click' );
     42            });
     43        }
     44    });
    3445
    3546    secondary = $( '#secondary' );
  • trunk/src/wp-includes/js/customize-preview-nav-menus.js

    r33347 r33491  
    175175         */
    176176        refreshMenuInstance : function( instanceNumber ) {
    177             var data, menuId, customized, container, request, wpNavArgs, instance, containerInstanceClassName;
     177            var data, menuId, customized, container, request, wpNavMenuArgs, instance, containerInstanceClassName;
    178178
    179179            if ( ! settings.navMenuInstanceArgs[ instanceNumber ] ) {
     
    228228            data[ settings.renderNoncePostKey ] = settings.renderNonceValue;
    229229
    230             wpNavArgs = $.extend( {}, instance );
    231             data.wp_nav_menu_args_hash = wpNavArgs.args_hash;
    232             delete wpNavArgs.args_hash;
    233             data.wp_nav_menu_args = JSON.stringify( wpNavArgs );
     230            wpNavMenuArgs = $.extend( {}, instance );
     231            data.wp_nav_menu_args_hash = wpNavMenuArgs.args_hash;
     232            delete wpNavMenuArgs.args_hash;
     233            data.wp_nav_menu_args = JSON.stringify( wpNavMenuArgs );
    234234
    235235            container.addClass( 'customize-partial-refreshing' );
     
    253253                eventParam = {
    254254                    instanceNumber: instanceNumber,
    255                     wpNavArgs: wpNavArgs,
     255                    wpNavArgs: wpNavMenuArgs, // @deprecated
     256                    wpNavMenuArgs: wpNavMenuArgs,
    256257                    oldContainer: previousContainer,
    257258                    newContainer: container
Note: See TracChangeset for help on using the changeset viewer.