Changeset 47356
- Timestamp:
- 02/25/2020 11:12:18 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/wp/customize/nav-menus.js
r47122 r47356 1796 1796 $removeBtn.on( 'click', function() { 1797 1797 // Find an adjacent element to add focus to when this menu item goes away. 1798 var addingItems = true, $adjacentFocusTarget, $next, $prev; 1798 var addingItems = true, $adjacentFocusTarget, $next, $prev, 1799 instanceCounter = 0, // Instance count of the menu item deleted. 1800 deleteItemOriginalItemId = control.params.original_item_id, 1801 addedItems = control.getMenuControl().$sectionContent.find( '.menu-item' ), 1802 availableMenuItem; 1799 1803 1800 1804 if ( ! $( 'body' ).hasClass( 'adding-menu-items' ) ) { … … 1811 1815 } else { 1812 1816 $adjacentFocusTarget = control.container.nextAll( '.customize-control-nav_menu' ).find( '.add-new-menu-item' ).first(); 1817 } 1818 1819 /* 1820 * If the menu item deleted is the only of its instance left, 1821 * remove the check icon of this menu item in the right panel. 1822 */ 1823 _.each( addedItems, function( addedItem ) { 1824 var menuItemId, menuItemControl, matches; 1825 1826 // This is because menu item that's deleted is just hidden. 1827 if ( ! $( addedItem ).is( ':visible' ) ) { 1828 return; 1829 } 1830 1831 matches = addedItem.getAttribute( 'id' ).match( /^customize-control-nav_menu_item-(-?\d+)$/, '' ); 1832 if ( ! matches ) { 1833 return; 1834 } 1835 1836 menuItemId = parseInt( matches[1], 10 ); 1837 menuItemControl = api.control( 'nav_menu_item[' + String( menuItemId ) + ']' ); 1838 1839 // Check for duplicate menu items. 1840 if ( menuItemControl && deleteItemOriginalItemId == menuItemControl.params.original_item_id ) { 1841 instanceCounter++; 1842 } 1843 } ); 1844 1845 if ( instanceCounter <= 1 ) { 1846 // Revert the check icon to add icon. 1847 availableMenuItem = $( '#menu-item-tpl-' + control.params.original_item_id ); 1848 availableMenuItem.removeClass( 'selected' ); 1849 availableMenuItem.find( '.menu-item-handle' ).removeClass( 'item-added' ); 1813 1850 } 1814 1851 … … 2962 2999 */ 2963 3000 addItemToMenu: function( item ) { 2964 var menuControl = this, customizeId, settingArgs, setting, menuItemControl, placeholderId, position = 0, priority = 10; 3001 var menuControl = this, customizeId, settingArgs, setting, menuItemControl, placeholderId, position = 0, priority = 10, 3002 originalItemId = item.id || ''; 2965 3003 2966 3004 _.each( menuControl.getMenuItemControls(), function( control ) { … … 3006 3044 'default': customizeId 3007 3045 }, 3008 menu_item_id: placeholderId 3046 menu_item_id: placeholderId, 3047 original_item_id: originalItemId 3009 3048 } ); 3010 3049
Note: See TracChangeset
for help on using the changeset viewer.