| | 1810 | /* |
| | 1811 | * If the menu item deleted is the only of it's instance left, |
| | 1812 | * remove the check icon of this menu item in the right panel. |
| | 1813 | * |
| | 1814 | * @see https://core.trac.wordpress.org/ticket/46830 |
| | 1815 | */ |
| | 1816 | // Instance count of the menu item deleted. |
| | 1817 | var instanceCounter = 0; |
| | 1818 | var deleteItemOriginalItemId = control.params.original_item_id; |
| | 1819 | var addedItems = control.getMenuControl().$sectionContent.find( '.menu-item' ); |
| | 1820 | |
| | 1821 | _.each( addedItems, function( addedItem ) { |
| | 1822 | // This is because menu item that's deleted is just hidden. |
| | 1823 | if ( ! $( addedItem ).is( ':visible' ) ) { |
| | 1824 | return; |
| | 1825 | } |
| | 1826 | |
| | 1827 | var menuItemId, menuItemControl, matches; |
| | 1828 | |
| | 1829 | matches = addedItem.getAttribute('id').match( /^customize-control-nav_menu_item-(-?\d+)$/, '' ); |
| | 1830 | if ( ! matches ) { |
| | 1831 | return; |
| | 1832 | } |
| | 1833 | |
| | 1834 | menuItemId = parseInt( matches[1], 10 ); |
| | 1835 | menuItemControl = api.control( 'nav_menu_item[' + String( menuItemId ) + ']' ); |
| | 1836 | |
| | 1837 | // Check for duplicate menu items. |
| | 1838 | if ( menuItemControl && deleteItemOriginalItemId == menuItemControl.params.original_item_id ) { |
| | 1839 | instanceCounter++; |
| | 1840 | } |
| | 1841 | } ); |
| | 1842 | |
| | 1843 | if ( 1 >= instanceCounter ) { |
| | 1844 | // Revert the check icon to add icon. |
| | 1845 | var availableMenuItem = $( '#menu-item-tpl-' + control.params.original_item_id ); |
| | 1846 | availableMenuItem.removeClass( 'selected' ); |
| | 1847 | availableMenuItem.find( '.menu-item-handle' ).removeClass( 'item-added' ); |
| | 1848 | } |
| | 1849 | |