Make WordPress Core

Ticket #32683: 32683.1.diff

File 32683.1.diff, 2.3 KB (added by celloexpressions, 10 years ago)

Restructure JS, show/hide the edit button when a menu is selected.

  • src/wp-admin/js/customize-widgets.js

     
    21392139                return foundControl;
    21402140        };
    21412141
     2142        /*
     2143         * Init linking between menu widgets and customizer menus.
     2144         */
     2145        $( document ).on( 'widget-added', function( event, widgetContainer ) {
     2146                if ( 0 < widgetContainer.find( '.nav-menu-widget-form-controls' ).length ) {
     2147                        var menuField = widgetContainer.find( '.selected-menu' ),
     2148                            button = widgetContainer.find( '.edit-menu' );
     2149                        menuField.on( 'change', function() {
     2150                                if ( 0 < menuField.val() ) {
     2151                                        button.show();
     2152                                } else {
     2153                                        button.hide();
     2154                                }
     2155                        });
     2156                        button.on( 'click', function() {
     2157                                var section = 'nav_menu[' + menuField.val() + ']';
     2158                                wp.customize.section( section ).focus();
     2159                        } );
     2160                }
     2161        } );
     2162
    21422163        /**
    21432164         * @param {String} widgetId
    21442165         * @returns {Object}
  • src/wp-includes/widgets/class-wp-nav-menu-widget.php

     
    137137                        </p>
    138138                        <p>
    139139                                <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label>
    140                                 <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>">
     140                                <select class="selected-menu" id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>">
    141141                                        <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    142142                                        <?php foreach ( $menus as $menu ) : ?>
    143143                                                <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>>
     
    145145                                                </option>
    146146                                        <?php endforeach; ?>
    147147                                </select>
     148                                <?php if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) : ?>
     149                                        <button type="button" class="button edit-menu" style="margin-top: 12px; <?php if ( ! $nav_menu ) { echo 'display: none;'; } ?>"><?php _e( 'Edit Menu' ) ?></button>
     150                                <?php endif; ?>
    148151                        </p>
    149152                </div>
    150153                <?php