Make WordPress Core

Ticket #32576: 32576.menu-customizer-core-misc.diff

File 32576.menu-customizer-core-misc.diff, 3.2 KB (added by westonruter, 10 years ago)

Additional Core changes needed for Menu Customizer from https://github.com/xwp/wordpress-develop/pull/91/files

  • src/wp-content/themes/twentyfifteen/js/functions.js

    diff --git src/wp-content/themes/twentyfifteen/js/functions.js src/wp-content/themes/twentyfifteen/js/functions.js
    index eeeecd2..64a6968 100644
     
    99        var $body, $window, $sidebar, adminbarOffset, top = false,
    1010            bottom = false, windowWidth, windowHeight, lastWindowPos = 0,
    1111            topOffset = 0, bodyHeight, sidebarHeight, resizeTimer,
    12                 secondary, button;
    13 
    14         // Add dropdown toggle that display child menu items.
    15         $( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
    16 
    17         // Toggle buttons and submenu items with active children menu items.
    18         $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' );
    19         $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
    20 
    21         $( '.dropdown-toggle' ).click( function( e ) {
    22                 var _this = $( this );
    23                 e.preventDefault();
    24                 _this.toggleClass( 'toggle-on' );
    25                 _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
    26                 _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
    27                 _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
    28         } );
     12            secondary, button;
     13
     14
     15        function initMainNavigation() {
     16                // 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>' );
     18
     19                // 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' );
     22
     23                $( '.dropdown-toggle' ).click( function( e ) {
     24                        var _this = $( this );
     25                        e.preventDefault();
     26                        _this.toggleClass( 'toggle-on' );
     27                        _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
     28                        _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
     29                        _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
     30                } );
     31        }
     32        initMainNavigation();
     33        $( document ).on( 'customize-preview-menu-refreshed', initMainNavigation );
    2934
    3035        secondary = $( '#secondary' );
    3136        button = $( '.site-branding' ).find( '.secondary-toggle' );
  • src/wp-includes/nav-menu-template.php

    diff --git src/wp-includes/nav-menu-template.php src/wp-includes/nav-menu-template.php
    index a0499fb..4194c50 100644
    function wp_nav_menu( $args = array() ) { 
    230230        'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    231231        'depth' => 0, 'walker' => '', 'theme_location' => '' );
    232232
     233        // Prevent a fallback_cb in Customizer Preview to assist with has_nav_menu() and partial refresh.
     234        if ( is_customize_preview() ) {
     235                $defaults['fallback_cb'] = '';
     236        }
     237
    233238        $args = wp_parse_args( $args, $defaults );
    234239        /**
    235240         * Filter the arguments used to display a navigation menu.