Customize: When a menu item is removed from the menu, uncheck its source item on the available items panel.

Props donmhico, garrett-eclipse, audrasjb.
Fixes #46830.
Built from https://develop.svn.wordpress.org/trunk@47356


git-svn-id: http://core.svn.wordpress.org/trunk@47143 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-02-25 11:14:08 +00:00
parent 556c6d80d8
commit 1a090b3385
3 changed files with 44 additions and 5 deletions

View File

@ -1795,7 +1795,11 @@
$removeBtn.on( 'click', function() {
// Find an adjacent element to add focus to when this menu item goes away.
var addingItems = true, $adjacentFocusTarget, $next, $prev;
var addingItems = true, $adjacentFocusTarget, $next, $prev,
instanceCounter = 0, // Instance count of the menu item deleted.
deleteItemOriginalItemId = control.params.original_item_id,
addedItems = control.getMenuControl().$sectionContent.find( '.menu-item' ),
availableMenuItem;
if ( ! $( 'body' ).hasClass( 'adding-menu-items' ) ) {
addingItems = false;
@ -1812,6 +1816,39 @@
$adjacentFocusTarget = control.container.nextAll( '.customize-control-nav_menu' ).find( '.add-new-menu-item' ).first();
}
/*
* If the menu item deleted is the only of its instance left,
* remove the check icon of this menu item in the right panel.
*/
_.each( addedItems, function( addedItem ) {
var menuItemId, menuItemControl, matches;
// This is because menu item that's deleted is just hidden.
if ( ! $( addedItem ).is( ':visible' ) ) {
return;
}
matches = addedItem.getAttribute( 'id' ).match( /^customize-control-nav_menu_item-(-?\d+)$/, '' );
if ( ! matches ) {
return;
}
menuItemId = parseInt( matches[1], 10 );
menuItemControl = api.control( 'nav_menu_item[' + String( menuItemId ) + ']' );
// Check for duplicate menu items.
if ( menuItemControl && deleteItemOriginalItemId == menuItemControl.params.original_item_id ) {
instanceCounter++;
}
} );
if ( instanceCounter <= 1 ) {
// Revert the check icon to add icon.
availableMenuItem = $( '#menu-item-tpl-' + control.params.original_item_id );
availableMenuItem.removeClass( 'selected' );
availableMenuItem.find( '.menu-item-handle' ).removeClass( 'item-added' );
}
control.container.slideUp( function() {
control.setting.set( false );
wp.a11y.speak( api.Menus.data.l10n.itemDeleted );
@ -2961,7 +2998,8 @@
* @return {wp.customize.Menus.controlConstructor.nav_menu_item} The newly-created nav_menu_item control instance.
*/
addItemToMenu: function( item ) {
var menuControl = this, customizeId, settingArgs, setting, menuItemControl, placeholderId, position = 0, priority = 10;
var menuControl = this, customizeId, settingArgs, setting, menuItemControl, placeholderId, position = 0, priority = 10,
originalItemId = item.id || '';
_.each( menuControl.getMenuItemControls(), function( control ) {
if ( false === control.setting() ) {
@ -3005,7 +3043,8 @@
settings: {
'default': customizeId
},
menu_item_id: placeholderId
menu_item_id: placeholderId,
original_item_id: originalItemId
} );
api.control.add( menuItemControl );

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.4-beta2-47355';
$wp_version = '5.4-beta2-47356';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.