Make WordPress Core

Ticket #36279: 36279.1.diff

File 36279.1.diff, 12.6 KB (added by bpayton, 8 years ago)
  • src/wp-admin/css/customize-nav-menus.css

    From b51199281d732340ac4b140a3894c53d6d13735d Mon Sep 17 00:00:00 2001
    From: Brandon Payton <brandon@happycode.net>
    Date: Sun, 15 Oct 2017 17:38:03 -0700
    Subject: [PATCH 1/6] Add New Menu button to All Locations
    
    ---
     src/wp-admin/css/customize-nav-menus.css           |  5 +--
     src/wp-admin/js/customize-nav-menus.js             | 41 ++++++++++++++++++++++
     ...lass-wp-customize-nav-menu-location-control.php |  1 +
     3 files changed, 45 insertions(+), 2 deletions(-)
    
    diff --git a/src/wp-admin/css/customize-nav-menus.css b/src/wp-admin/css/customize-nav-menus.css
    index f88c21d353..50f907aeb9 100644
    a b  
    3232        color: #555;
    3333}
    3434
    35 /* The `edit-menu` button uses also the `button-link` class. */
    36 .customize-control-nav_menu_location .edit-menu {
     35/* The `edit-menu` and `create-menu` buttons also use the `button-link` class. */
     36.customize-control-nav_menu_location .edit-menu,
     37.customize-control-nav_menu_location .create-menu {
    3738        margin-left: 6px;
    3839        vertical-align: middle;
    3940        line-height: 28px;
  • src/wp-admin/js/customize-nav-menus.js

    diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js
    index 6736b56bc3..c86dc773df 100644
    a b  
    13831383
    13841384                        // Focus on the new menu section.
    13851385                        api.section( customizeId ).focus(); // @todo should we focus on the new menu's control and open the add-items panel? Thinking user flow...
     1386                },
     1387
     1388                /**
     1389                 * Select a default location.
     1390                 *
     1391                 * This method selects a single location by default so we can support
     1392                 * creating a menu for a specific menu location.
     1393                 *
     1394                 * @param {string} locationId - The ID of the location to select.
     1395                 *  Specifying `null` or `undefined` will clear all selections.
     1396                 */
     1397                selectDefaultLocation: function ( locationId ) {
     1398                        var locationControl = api.control( this.id + '[locations]' ),
     1399                                locationSelections = {};
     1400
     1401                        if ( locationId !== undefined && locationId !== null ) {
     1402                                locationSelections[ locationId ] = true;
     1403                        }
     1404
     1405                        locationControl.setSelections( locationSelections );
    13861406                }
    13871407        });
    13881408
     
    14281448                                }
    14291449                        });
    14301450
     1451                        // Create menu button.
     1452                        control.container.find( '.create-menu' ).on( 'click', function () {
     1453                                var addMenuSection = api.section( 'add_menu' );
     1454                                addMenuSection.selectDefaultLocation( this.dataset.locationId );
     1455                                addMenuSection.focus();
     1456                        } );
     1457
    14311458                        // Add/remove menus from the available options when they are added and removed.
    14321459                        api.bind( 'add', function( setting ) {
    14331460                                var option, menuId, matches = setting.id.match( navMenuIdRegex );
     
    23492376                                } );
    23502377                                updateSelectedMenuLabel( navMenuLocationSetting.get() );
    23512378                        });
     2379                },
     2380
     2381                /**
     2382                 * Set the selected locations.
     2383                 *
     2384                 * This method sets the selected locations and allows us to do things like
     2385                 * set the default location for a new menu.
     2386                 *
     2387                 * @param {Object.<string,boolean>} selections - A map of location selections.
     2388                 */
     2389                setSelections: function ( selections ) {
     2390                        this.container.find( '.menu-location' ).each( function( i, checkboxNode ) {
     2391                                checkboxNode.checked = !! selections[ checkboxNode.dataset.locationId ];
     2392                        } );
    23522393                }
    23532394        });
    23542395
  • src/wp-includes/customize/class-wp-customize-nav-menu-location-control.php

    diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-location-control.php b/src/wp-includes/customize/class-wp-customize-nav-menu-location-control.php
    index dff79f17ad..fc22c62366 100644
    a b class WP_Customize_Nav_Menu_Location_Control extends WP_Customize_Control { 
    7474                        </select>
    7575                </label>
    7676                <button type="button" class="button-link edit-menu<?php if ( ! $this->value() ) { echo ' hidden'; } ?>" aria-label="<?php esc_attr_e( 'Edit selected menu' ); ?>"><?php _e( 'Edit Menu' ); ?></button>
     77                <button type="button" class="button-link create-menu" data-location-id="<?php echo esc_attr( $this->location_id ); ?>" aria-label="<?php esc_attr_e( 'Create a menu for this location' ); ?>"><?php _e( '+ Create New Nenu' ); ?></button>
    7778                <?php
    7879        }
    7980}
  • src/wp-admin/js/customize-nav-menus.js

    -- 
    2.14.1
    
    
    From 31815e56ab13756fbc716c040f03de5695026b42 Mon Sep 17 00:00:00 2001
    From: Brandon Payton <brandon@happycode.net>
    Date: Mon, 16 Oct 2017 00:14:06 -0700
    Subject: [PATCH 2/6] Update in response to code review
    
    ---
     src/wp-admin/js/customize-nav-menus.js | 15 +++++++++++----
     1 file changed, 11 insertions(+), 4 deletions(-)
    
    diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js
    index c86dc773df..0ddc7d1bd2 100644
    a b  
    13911391                 * This method selects a single location by default so we can support
    13921392                 * creating a menu for a specific menu location.
    13931393                 *
    1394                  * @param {string} locationId - The ID of the location to select.
    1395                  *  Specifying `null` or `undefined` will clear all selections.
     1394                 * @since 4.9.0
     1395                 *
     1396                 * @param {string|null} locationId - The ID of the location to select.
     1397                 *  Specifying `null` will clear all selections.
     1398                 * @returns {void}
    13961399                 */
    13971400                selectDefaultLocation: function ( locationId ) {
    13981401                        var locationControl = api.control( this.id + '[locations]' ),
    13991402                                locationSelections = {};
    14001403
    1401                         if ( locationId !== undefined && locationId !== null ) {
     1404                        if ( locationId !== null ) {
    14021405                                locationSelections[ locationId ] = true;
    14031406                        }
    14041407
     
    23842387                 * This method sets the selected locations and allows us to do things like
    23852388                 * set the default location for a new menu.
    23862389                 *
     2390                 * @since 4.9.0
     2391                 *
    23872392                 * @param {Object.<string,boolean>} selections - A map of location selections.
     2393                 * @returns {void}
    23882394                 */
    23892395                setSelections: function ( selections ) {
    23902396                        this.container.find( '.menu-location' ).each( function( i, checkboxNode ) {
    2391                                 checkboxNode.checked = !! selections[ checkboxNode.dataset.locationId ];
     2397                                var locationId = checkboxNode.dataset.locationId;
     2398                                checkboxNode.checked = locationId in selections ? selections[ locationId ] : false;
    23922399                        } );
    23932400                }
    23942401        });
  • src/wp-admin/js/customize-nav-menus.js

    -- 
    2.14.1
    
    
    From b668f33ca81e0b8227e1250f31ded1cb4bd6532b Mon Sep 17 00:00:00 2001
    From: Brandon Payton <brandon@happycode.net>
    Date: Tue, 17 Oct 2017 11:14:56 +0200
    Subject: [PATCH 3/6] Update create button visibility
    
    ---
     src/wp-admin/js/customize-nav-menus.js              | 21 +++++++++------------
     ...class-wp-customize-nav-menu-location-control.php |  2 +-
     2 files changed, 10 insertions(+), 13 deletions(-)
    
    diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js
    index 0ddc7d1bd2..18ae6b0e3a 100644
    a b  
    14381438                                }
    14391439                        };
    14401440
    1441                         // Edit menu button.
     1441                        // Create and Edit menu buttons.
     1442                        control.container.find( '.create-menu' ).on( 'click', function () {
     1443                                var addMenuSection = api.section( 'add_menu' );
     1444                                addMenuSection.selectDefaultLocation( this.dataset.locationId );
     1445                                addMenuSection.focus();
     1446                        } );
    14421447                        control.container.find( '.edit-menu' ).on( 'click', function() {
    14431448                                var menuId = control.setting();
    14441449                                api.section( 'nav_menu[' + menuId + ']' ).focus();
    14451450                        });
    14461451                        control.setting.bind( 'change', function() {
    1447                                 if ( 0 === control.setting() ) {
    1448                                         control.container.find( '.edit-menu' ).addClass( 'hidden' );
    1449                                 } else {
    1450                                         control.container.find( '.edit-menu' ).removeClass( 'hidden' );
    1451                                 }
     1452                                var menuIsSelected = 0 !== control.setting();
     1453                                control.container.find( '.create-menu' ).toggleClass( 'hidden', menuIsSelected );
     1454                                control.container.find( '.edit-menu' ).toggleClass( 'hidden', ! menuIsSelected );
    14521455                        });
    14531456
    1454                         // Create menu button.
    1455                         control.container.find( '.create-menu' ).on( 'click', function () {
    1456                                 var addMenuSection = api.section( 'add_menu' );
    1457                                 addMenuSection.selectDefaultLocation( this.dataset.locationId );
    1458                                 addMenuSection.focus();
    1459                         } );
    14601457
    14611458                        // Add/remove menus from the available options when they are added and removed.
    14621459                        api.bind( 'add', function( setting ) {
  • src/wp-includes/customize/class-wp-customize-nav-menu-location-control.php

    diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-location-control.php b/src/wp-includes/customize/class-wp-customize-nav-menu-location-control.php
    index fc22c62366..a90833e62b 100644
    a b class WP_Customize_Nav_Menu_Location_Control extends WP_Customize_Control { 
    7373                                ?>
    7474                        </select>
    7575                </label>
     76                <button type="button" class="button-link create-menu<?php if ( $this->value() ) { echo ' hidden'; } ?>" data-location-id="<?php echo esc_attr( $this->location_id ); ?>" aria-label="<?php esc_attr_e( 'Create a menu for this location' ); ?>"><?php _e( '+ Create New Nenu' ); ?></button>
    7677                <button type="button" class="button-link edit-menu<?php if ( ! $this->value() ) { echo ' hidden'; } ?>" aria-label="<?php esc_attr_e( 'Edit selected menu' ); ?>"><?php _e( 'Edit Menu' ); ?></button>
    77                 <button type="button" class="button-link create-menu" data-location-id="<?php echo esc_attr( $this->location_id ); ?>" aria-label="<?php esc_attr_e( 'Create a menu for this location' ); ?>"><?php _e( '+ Create New Nenu' ); ?></button>
    7878                <?php
    7979        }
    8080}
  • tests/qunit/wp-admin/js/customize-nav-menus.js

    -- 
    2.14.1
    
    
    From f5970f9552ac69d71431b8ae2f7c076d8061d3f6 Mon Sep 17 00:00:00 2001
    From: Brandon Payton <brandon@happycode.net>
    Date: Tue, 17 Oct 2017 11:23:45 +0200
    Subject: [PATCH 4/6] Add todo for MenuLocationsControl tests
    
    ---
     tests/qunit/wp-admin/js/customize-nav-menus.js | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/tests/qunit/wp-admin/js/customize-nav-menus.js b/tests/qunit/wp-admin/js/customize-nav-menus.js
    index f77111c171..9b60272875 100644
    a b jQuery( window ).load( function (){ 
    110110
    111111        // @todo Add tests for api.Menus.NewMenuSection
    112112        // @todo Add tests for api.Menus.MenuLocationControl
     113        // @todo Add tests for api.Menus.MenuLocationsControl
    113114        // @todo Add tests for api.Menus.MenuAutoAddControl
    114115        // @todo Add tests for api.Menus.MenuControl
    115116        // @todo Add tests for api.Menus.NewMenuControl
  • src/wp-admin/js/customize-nav-menus.js

    -- 
    2.14.1
    
    
    From bac1fe0322db4eddb5aad5a77222bd4acbe2433c Mon Sep 17 00:00:00 2001
    From: Brandon Payton <brandon@happycode.net>
    Date: Wed, 18 Oct 2017 15:03:42 +0200
    Subject: [PATCH 5/6] Fix inconsistent function paren spacing
    
    ---
     src/wp-admin/js/customize-nav-menus.js | 6 +++---
     1 file changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js
    index 18ae6b0e3a..3f30985cb1 100644
    a b  
    13971397                 *  Specifying `null` will clear all selections.
    13981398                 * @returns {void}
    13991399                 */
    1400                 selectDefaultLocation: function ( locationId ) {
     1400                selectDefaultLocation: function( locationId ) {
    14011401                        var locationControl = api.control( this.id + '[locations]' ),
    14021402                                locationSelections = {};
    14031403
     
    14391439                        };
    14401440
    14411441                        // Create and Edit menu buttons.
    1442                         control.container.find( '.create-menu' ).on( 'click', function () {
     1442                        control.container.find( '.create-menu' ).on( 'click', function() {
    14431443                                var addMenuSection = api.section( 'add_menu' );
    14441444                                addMenuSection.selectDefaultLocation( this.dataset.locationId );
    14451445                                addMenuSection.focus();
     
    23892389                 * @param {Object.<string,boolean>} selections - A map of location selections.
    23902390                 * @returns {void}
    23912391                 */
    2392                 setSelections: function ( selections ) {
     2392                setSelections: function( selections ) {
    23932393                        this.container.find( '.menu-location' ).each( function( i, checkboxNode ) {
    23942394                                var locationId = checkboxNode.dataset.locationId;
    23952395                                checkboxNode.checked = locationId in selections ? selections[ locationId ] : false;
  • src/wp-admin/js/customize-nav-menus.js

    -- 
    2.14.1
    
    
    From b0bd42f476eb57ff53a073162f7e7ccad2dddb2a Mon Sep 17 00:00:00 2001
    From: Brandon Payton <brandon@happycode.net>
    Date: Wed, 18 Oct 2017 15:30:47 +0200
    Subject: [PATCH 6/6] Remove unnecessarily added blank line
    
    ---
     src/wp-admin/js/customize-nav-menus.js | 1 -
     1 file changed, 1 deletion(-)
    
    diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js
    index 3f30985cb1..25786244ce 100644
    a b  
    14541454                                control.container.find( '.edit-menu' ).toggleClass( 'hidden', ! menuIsSelected );
    14551455                        });
    14561456
    1457 
    14581457                        // Add/remove menus from the available options when they are added and removed.
    14591458                        api.bind( 'add', function( setting ) {
    14601459                                var option, menuId, matches = setting.id.match( navMenuIdRegex );