| 1510 | |
| 1511 | currentMenuControl = control.getMenuControl(); |
| 1512 | |
| 1513 | if ( currentMenuControl ) { |
| 1514 | navMenuItemCount = currentMenuControl.getMenuItemControls().length; |
| 1515 | |
| 1516 | /** |
| 1517 | * Since the item is not remove yet, we check if the |
| 1518 | * current value is 1, meaning there is only one item in |
| 1519 | * the menu that will be removed. |
| 1520 | */ |
| 1521 | if ( 1 === navMenuItemCount ) { |
| 1522 | currentMenuControl.removeFromWidgets(); |
| 1523 | } |
| 1524 | } |
2178 | | |
2179 | | // Add menu to Custom Menu widgets. |
2180 | | if ( menu ) { |
2181 | | name = displayNavMenuName( menu.name ); |
2182 | | |
2183 | | // Add the menu to the existing controls. |
2184 | | api.control.each( function( widgetControl ) { |
2185 | | if ( ! widgetControl.extended( api.controlConstructor.widget_form ) || 'nav_menu' !== widgetControl.params.widget_id_base ) { |
2186 | | return; |
2187 | | } |
2188 | | widgetControl.container.find( '.nav-menu-widget-form-controls:first' ).show(); |
2189 | | widgetControl.container.find( '.nav-menu-widget-no-menus-message:first' ).hide(); |
2190 | | |
2191 | | select = widgetControl.container.find( 'select' ); |
2192 | | if ( 0 === select.find( 'option[value=' + String( menuId ) + ']' ).length ) { |
2193 | | select.append( new Option( name, menuId ) ); |
2194 | | } |
2195 | | } ); |
2196 | | |
2197 | | // Add the menu to the widget template. |
2198 | | widgetTemplate = $( '#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )' ); |
2199 | | widgetTemplate.find( '.nav-menu-widget-form-controls:first' ).show(); |
2200 | | widgetTemplate.find( '.nav-menu-widget-no-menus-message:first' ).hide(); |
2201 | | select = widgetTemplate.find( '.widget-inside select:first' ); |
2202 | | if ( 0 === select.find( 'option[value=' + String( menuId ) + ']' ).length ) { |
2203 | | select.append( new Option( name, menuId ) ); |
2204 | | } |
2205 | | } |
2362 | | api.each(function( setting ) { |
2363 | | if ( /^nav_menu\[/.test( setting.id ) && false !== setting() ) { |
2364 | | navMenuCount += 1; |
2365 | | } |
2366 | | }); |
2367 | | |
2368 | | // Remove the menu from any Custom Menu widgets. |
2369 | | api.control.each(function( widgetControl ) { |
2370 | | if ( ! widgetControl.extended( api.controlConstructor.widget_form ) || 'nav_menu' !== widgetControl.params.widget_id_base ) { |
2371 | | return; |
2372 | | } |
2373 | | var select = widgetControl.container.find( 'select' ); |
2374 | | if ( select.val() === String( menuId ) ) { |
2375 | | select.prop( 'selectedIndex', 0 ).trigger( 'change' ); |
2376 | | } |
2377 | | |
2378 | | widgetControl.container.find( '.nav-menu-widget-form-controls:first' ).toggle( 0 !== navMenuCount ); |
2379 | | widgetControl.container.find( '.nav-menu-widget-no-menus-message:first' ).toggle( 0 === navMenuCount ); |
2380 | | widgetControl.container.find( 'option[value=' + String( menuId ) + ']' ).remove(); |
2381 | | }); |
2382 | | |
2383 | | // Remove the menu to the nav menu widget template. |
2384 | | widgetTemplate = $( '#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )' ); |
2385 | | widgetTemplate.find( '.nav-menu-widget-form-controls:first' ).toggle( 0 !== navMenuCount ); |
2386 | | widgetTemplate.find( '.nav-menu-widget-no-menus-message:first' ).toggle( 0 === navMenuCount ); |
2387 | | widgetTemplate.find( 'option[value=' + String( menuId ) + ']' ).remove(); |
| 2343 | control.removeFromWidgets(); |
2624 | | var menuControl = this, customizeId, settingArgs, setting, menuItemControl, placeholderId, position = 0, priority = 10; |
| 2580 | var menuControl = this, customizeId, settingArgs, setting, menuItemControl, placeholderId, position = 0, priority = 10, |
| 2581 | menu, |
| 2582 | name, |
| 2583 | menuId, |
| 2584 | select, |
| 2585 | widgetTemplate; |
| 2643 | /** |
| 2644 | * Add menu to Custom Menu widgets since it has at least one |
| 2645 | * menu item. |
| 2646 | */ |
| 2647 | menu = menuControl.setting(); |
| 2648 | |
| 2649 | if ( menu ) { |
| 2650 | name = displayNavMenuName( menu.name ); |
| 2651 | menuId = menuControl.params.menu_id; |
| 2652 | |
| 2653 | /** |
| 2654 | * Add the menu to the existing controls. |
| 2655 | */ |
| 2656 | api.control.each( function( widgetControl ) { |
| 2657 | if ( widgetControl.extended( api.controlConstructor.widget_form ) || |
| 2658 | 'nav_menu' === widgetControl.params.widget_id_base ) { |
| 2659 | widgetControl.container.find( '.nav-menu-widget-form-controls:first' ).show(); |
| 2660 | widgetControl.container.find( '.nav-menu-widget-no-menus-message:first' ).hide(); |
| 2661 | |
| 2662 | select = widgetControl.container.find( 'select' ); |
| 2663 | |
| 2664 | if ( 0 === select.find( 'option[value=' + String( menuId ) + ']' ).length ) { |
| 2665 | select.append( new Option( name, menuId ) ); |
| 2666 | } |
| 2667 | } |
| 2668 | } ); |
| 2669 | |
| 2670 | /** |
| 2671 | * Add the menu to the widget template. |
| 2672 | */ |
| 2673 | widgetTemplate = $( '#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )' ); |
| 2674 | |
| 2675 | widgetTemplate.find( '.nav-menu-widget-form-controls:first' ).show(); |
| 2676 | widgetTemplate.find( '.nav-menu-widget-no-menus-message:first' ).hide(); |
| 2677 | |
| 2678 | select = widgetTemplate.find( '.widget-inside select:first' ); |
| 2679 | |
| 2680 | if ( 0 === select.find( 'option[value=' + String( menuId ) + ']' ).length ) { |
| 2681 | select.append( new Option( name, menuId ) ); |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2686 | }, |
| 2687 | |
| 2688 | /** |
| 2689 | * Removes menu from widgets. |
| 2690 | */ |
| 2691 | removeFromWidgets: function() { |
| 2692 | var navMenuCount = 0, |
| 2693 | select, |
| 2694 | menuId = this.params.menu_id, |
| 2695 | widgetTemplate; |
| 2696 | |
| 2697 | api.each( function( setting ) { |
| 2698 | if ( /^nav_menu\[/.test( setting.id ) && |
| 2699 | false !== setting() ) { |
| 2700 | navMenuCount += 1; |
| 2701 | } |
| 2702 | } ); |
| 2703 | |
| 2704 | /** |
| 2705 | * Remove the menu from any Custom Menu widgets. |
| 2706 | */ |
| 2707 | api.control.each( function( widgetControl ) { |
| 2708 | if ( widgetControl.extended( api.controlConstructor.widget_form ) && |
| 2709 | 'nav_menu' === widgetControl.params.widget_id_base ) { |
| 2710 | select = widgetControl.container.find( 'select' ); |
| 2711 | |
| 2712 | if ( select.val() === String( menuId ) ) { |
| 2713 | select.prop( 'selectedIndex', 0 ).trigger( 'change' ); |
| 2714 | } |
| 2715 | |
| 2716 | widgetControl.container.find( '.nav-menu-widget-form-controls:first' ).toggle( 0 !== navMenuCount ); |
| 2717 | widgetControl.container.find( '.nav-menu-widget-no-menus-message:first' ).toggle( 0 === navMenuCount ); |
| 2718 | widgetControl.container.find( 'option[value=' + String( menuId ) + ']' ).remove(); |
| 2719 | } |
| 2720 | } ); |
| 2721 | |
| 2722 | /** |
| 2723 | * Remove the menu to the nav menu widget template. |
| 2724 | */ |
| 2725 | widgetTemplate = $( '#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )' ); |
| 2726 | |
| 2727 | widgetTemplate.find( '.nav-menu-widget-form-controls:first' ).toggle( 0 !== navMenuCount ); |
| 2728 | widgetTemplate.find( '.nav-menu-widget-no-menus-message:first' ).toggle( 0 === navMenuCount ); |
| 2729 | widgetTemplate.find( 'option[value=' + String( menuId ) + ']' ).remove(); |