menu_id:j}}),a.section.add(e,d),h.val(""),b.a11y.speak(a.Menus.data.l10n.menuAdded),a.section(e).focus()}}),c.extend(a.controlConstructor,{nav_menu_location:a.Menus.MenuLocationControl,nav_menu_item:a.Menus.MenuItemControl,nav_menu:a.Menus.MenuControl,nav_menu_name:a.Menus.MenuNameControl,new_menu:a.Menus.NewMenuControl}),c.extend(a.panelConstructor,{nav_menus:a.Menus.MenusPanel}),c.extend(a.sectionConstructor,{nav_menu:a.Menus.MenuSection,new_menu:a.Menus.NewMenuSection}),a.bind("ready",function(){a.Menus.availableMenuItemsPanel=newa.Menus.AvailableMenuItemsPanelView({collection:a.Menus.availableMenuItems}),a.bind("saved",function(b){(b.nav_menu_updates||b.nav_menu_item_updates)&&a.Menus.applySavedData(b)}),a.previewer.bind("refresh",function(){a.previewer.refresh()})}),a.Menus.applySavedData=function(b){varc={};_(b.nav_menu_updates).each(function(b){vard,e,f,g,h,i,j;if("inserted"===b.status){if(!b.previous_term_id)thrownewError("Expected previous_term_id");if(!b.term_id)thrownewError("Expected term_id");if(d="nav_menu["+String(b.previous_term_id)+"]",!a.has(d))thrownewError("Expected setting to exist: "+d);if(f=a(d),!a.section.has(d))thrownewError("Expected control to exist: "+d);if(i=a.section(d),h=f.get(),!h)thrownewError("Did not expect setting to be empty (deleted).");h=_.clone(h),c[b.previous_term_id]=b.term_id,e="nav_menu["+String(b.term_id)+"]",g=a.create(e,e,h,{type:"nav_menu",transport:"postMessage",previewer:a.previewer}),i.expanded()&&i.collapse(),j=newa.Menus.MenuSection(e,{params:{id:e,panel:"nav_menus",title:h.name,customizeAction:a.Menus.data.l10n.customizingMenus,type:"nav_menu",priority:i.priority.get(),active:!0,menu_id:b.term_id}}),i.container.remove(),a.section.remove(d),a.section.add(e,j),f.callbacks.disable(),f.set(!1),f.preview(),g.preview(),a.each(function(c){vard=a.state("saved").get();/^nav_menu_locations\[/.test(c.id)&&c.get()===b.previous_term_id&&(c.set(b.term_id),c._dirty=!1,a.state("saved").set(d),c.preview())}),i.expanded.get()&&j.expand()}}),_(b.nav_menu_item_updates).each(function(b){vard,e,f,g,h,i,j;if("inserted"===b.status){if(!b.previous_post_id)thrownewError("Expected previous_post_id");if(!b.post_id)thrownewError("Expected post_id");if(d="nav_menu_item["+String(b.previous_post_id)+"]",!a.has(d))thrownewError("Expected setting to exist: "+d);if(f=a(d),!a.control.has(d))thrownewError("Expected control to exist: "+d);if(i=a.control(d),h=f.get(),!h)thrownewError("Did not expect setting to be empty (deleted).");h=_.clone(h),c[h.nav_menu_term_id]&&(h.nav_menu_term_id=c[h.nav_menu_term_id]),e="nav_menu_item["+String(b.post_id)+"]",g=a.create(e,e,h,{type:"nav_menu_item",transport:"postMessage",previewer:a.previewer}),j=newa.controlConstructor.nav_menu_item(e,{params:{type:"nav_menu_item",content:'<li id="customize-control-nav_menu_item-'+String(b.post_id)+'" class="customize-control customize-control-nav_menu_item"></li>',menu_id:b.post_id,section:"nav_menu["+String(h.nav_menu_term_id)+"]",priority:i.priority.get(),active:!0,settings:{"default":e},menu_item_id:b.post_id},previewer:a.previewer}),i.container.remove(),a.control.remove(d),a.control.add(e,j),f.callbacks.disable(),f.set(!1),f.preview(),g.preview(),j.container.toggleClass("menu-item-edit-inactive",i.container.hasClass("menu-item-edit-inactive"))}})},a.Menus.focusMenuItemControl=function(b){varc=a.Menus.getMenuItemControl(b);c&&c.focus()},a.Menus.getMenuControl=function(b){returna.control("nav_menu["+b+"]")},a.Menus.getTypeLabel=function(b,c){vard,e=a.Menus.data;returnd="post_type"===b?e.itemTypes.postTypes[c]?e.itemTypes.postTypes[c].label:e.l10n.postTypeLabel:"taxonomy"===b?e.itemTypes.taxonomies[c]?e.itemTypes.taxonomies[c].label:e.l10n.taxonomyTermLabel:e.l10n.custom_label},a.Menus.getMenuItemControl=function(b){returna.control(d(b))}}(wp.customize,wp,jQuery);