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
|
|
32 | 32 | color: #555; |
33 | 33 | } |
34 | 34 | |
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 { |
37 | 38 | margin-left: 6px; |
38 | 39 | vertical-align: middle; |
39 | 40 | line-height: 28px; |
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
|
|
1383 | 1383 | |
1384 | 1384 | // Focus on the new menu section. |
1385 | 1385 | 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 ); |
1386 | 1406 | } |
1387 | 1407 | }); |
1388 | 1408 | |
… |
… |
|
1428 | 1448 | } |
1429 | 1449 | }); |
1430 | 1450 | |
| 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 | |
1431 | 1458 | // Add/remove menus from the available options when they are added and removed. |
1432 | 1459 | api.bind( 'add', function( setting ) { |
1433 | 1460 | var option, menuId, matches = setting.id.match( navMenuIdRegex ); |
… |
… |
|
2349 | 2376 | } ); |
2350 | 2377 | updateSelectedMenuLabel( navMenuLocationSetting.get() ); |
2351 | 2378 | }); |
| 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 | } ); |
2352 | 2393 | } |
2353 | 2394 | }); |
2354 | 2395 | |
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 { |
74 | 74 | </select> |
75 | 75 | </label> |
76 | 76 | <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> |
77 | 78 | <?php |
78 | 79 | } |
79 | 80 | } |
--
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
|
|
1391 | 1391 | * This method selects a single location by default so we can support |
1392 | 1392 | * creating a menu for a specific menu location. |
1393 | 1393 | * |
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} |
1396 | 1399 | */ |
1397 | 1400 | selectDefaultLocation: function ( locationId ) { |
1398 | 1401 | var locationControl = api.control( this.id + '[locations]' ), |
1399 | 1402 | locationSelections = {}; |
1400 | 1403 | |
1401 | | if ( locationId !== undefined && locationId !== null ) { |
| 1404 | if ( locationId !== null ) { |
1402 | 1405 | locationSelections[ locationId ] = true; |
1403 | 1406 | } |
1404 | 1407 | |
… |
… |
|
2384 | 2387 | * This method sets the selected locations and allows us to do things like |
2385 | 2388 | * set the default location for a new menu. |
2386 | 2389 | * |
| 2390 | * @since 4.9.0 |
| 2391 | * |
2387 | 2392 | * @param {Object.<string,boolean>} selections - A map of location selections. |
| 2393 | * @returns {void} |
2388 | 2394 | */ |
2389 | 2395 | setSelections: function ( selections ) { |
2390 | 2396 | 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; |
2392 | 2399 | } ); |
2393 | 2400 | } |
2394 | 2401 | }); |
--
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
|
|
1438 | 1438 | } |
1439 | 1439 | }; |
1440 | 1440 | |
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 | } ); |
1442 | 1447 | control.container.find( '.edit-menu' ).on( 'click', function() { |
1443 | 1448 | var menuId = control.setting(); |
1444 | 1449 | api.section( 'nav_menu[' + menuId + ']' ).focus(); |
1445 | 1450 | }); |
1446 | 1451 | 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 ); |
1452 | 1455 | }); |
1453 | 1456 | |
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 | | } ); |
1460 | 1457 | |
1461 | 1458 | // Add/remove menus from the available options when they are added and removed. |
1462 | 1459 | api.bind( 'add', function( setting ) { |
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 { |
73 | 73 | ?> |
74 | 74 | </select> |
75 | 75 | </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> |
76 | 77 | <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> |
78 | 78 | <?php |
79 | 79 | } |
80 | 80 | } |
--
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 (){ |
110 | 110 | |
111 | 111 | // @todo Add tests for api.Menus.NewMenuSection |
112 | 112 | // @todo Add tests for api.Menus.MenuLocationControl |
| 113 | // @todo Add tests for api.Menus.MenuLocationsControl |
113 | 114 | // @todo Add tests for api.Menus.MenuAutoAddControl |
114 | 115 | // @todo Add tests for api.Menus.MenuControl |
115 | 116 | // @todo Add tests for api.Menus.NewMenuControl |
--
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
|
|
1397 | 1397 | * Specifying `null` will clear all selections. |
1398 | 1398 | * @returns {void} |
1399 | 1399 | */ |
1400 | | selectDefaultLocation: function ( locationId ) { |
| 1400 | selectDefaultLocation: function( locationId ) { |
1401 | 1401 | var locationControl = api.control( this.id + '[locations]' ), |
1402 | 1402 | locationSelections = {}; |
1403 | 1403 | |
… |
… |
|
1439 | 1439 | }; |
1440 | 1440 | |
1441 | 1441 | // Create and Edit menu buttons. |
1442 | | control.container.find( '.create-menu' ).on( 'click', function () { |
| 1442 | control.container.find( '.create-menu' ).on( 'click', function() { |
1443 | 1443 | var addMenuSection = api.section( 'add_menu' ); |
1444 | 1444 | addMenuSection.selectDefaultLocation( this.dataset.locationId ); |
1445 | 1445 | addMenuSection.focus(); |
… |
… |
|
2389 | 2389 | * @param {Object.<string,boolean>} selections - A map of location selections. |
2390 | 2390 | * @returns {void} |
2391 | 2391 | */ |
2392 | | setSelections: function ( selections ) { |
| 2392 | setSelections: function( selections ) { |
2393 | 2393 | this.container.find( '.menu-location' ).each( function( i, checkboxNode ) { |
2394 | 2394 | var locationId = checkboxNode.dataset.locationId; |
2395 | 2395 | checkboxNode.checked = locationId in selections ? selections[ locationId ] : false; |
--
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
|
|
1454 | 1454 | control.container.find( '.edit-menu' ).toggleClass( 'hidden', ! menuIsSelected ); |
1455 | 1455 | }); |
1456 | 1456 | |
1457 | | |
1458 | 1457 | // Add/remove menus from the available options when they are added and removed. |
1459 | 1458 | api.bind( 'add', function( setting ) { |
1460 | 1459 | var option, menuId, matches = setting.id.match( navMenuIdRegex ); |