2 lines
45 KiB
JavaScript
2 lines
45 KiB
JavaScript
/*! This file is auto-generated */
|
|
!function(v,h,g){"use strict";function u(e){return e=e||"",e=h.sanitize.stripTagsAndEncodeText(e),(e=g.trim(e))||v.Menus.data.l10n.unnamed}wpNavMenu.originalInit=wpNavMenu.init,wpNavMenu.options.menuItemDepthPerLevel=20,wpNavMenu.options.sortableItems="> .customize-control-nav_menu_item",wpNavMenu.options.targetTolerance=10,wpNavMenu.init=function(){this.jQueryExtensions()},v.Menus=v.Menus||{},v.Menus.data={itemTypes:[],l10n:{},settingTransport:"refresh",phpIntMax:0,defaultSettingValues:{nav_menu:{},nav_menu_item:{}},locationSlugMappedToName:{}},"undefined"!=typeof _wpCustomizeNavMenusSettings&&g.extend(v.Menus.data,_wpCustomizeNavMenusSettings),v.Menus.generatePlaceholderAutoIncrementId=function(){return-Math.ceil(v.Menus.data.phpIntMax*Math.random())},v.Menus.AvailableItemModel=Backbone.Model.extend(g.extend({id:null},v.Menus.data.defaultSettingValues.nav_menu_item)),v.Menus.AvailableItemCollection=Backbone.Collection.extend({model:v.Menus.AvailableItemModel,sort_key:"order",comparator:function(e){return-e.get(this.sort_key)},sortByField:function(e){this.sort_key=e,this.sort()}}),v.Menus.availableMenuItems=new v.Menus.AvailableItemCollection(v.Menus.data.availableMenuItems),v.Menus.insertAutoDraftPost=function(n){var e,i=g.Deferred();return(e=h.ajax.post("customize-nav-menus-insert-auto-draft",{"customize-menus-nonce":v.settings.nonce["customize-menus"],wp_customize:"on",customize_changeset_uuid:v.settings.changeset.uuid,params:n})).done(function(t){t.post_id&&(v("nav_menus_created_posts").set(v("nav_menus_created_posts").get().concat([t.post_id])),"page"===n.post_type&&(v.section.has("static_front_page")&&v.section("static_front_page").activate(),v.control.each(function(e){"dropdown-pages"===e.params.type&&e.container.find('select[name^="_customize-dropdown-pages-"]').append(new Option(n.post_title,t.post_id))})),i.resolve(t))}),e.fail(function(e){var t=e||"";void 0!==e.message&&(t=e.message),console.error(t),i.rejectWith(t)}),i.promise()},v.Menus.AvailableMenuItemsPanelView=h.Backbone.View.extend({el:"#available-menu-items",events:{"input #menu-items-search":"debounceSearch","focus .menu-item-tpl":"focus","click .menu-item-tpl":"_submit","click #custom-menu-item-submit":"_submitLink","keypress #custom-menu-item-name":"_submitLink","click .new-content-item .add-content":"_submitNew","keypress .create-item-input":"_submitNew",keydown:"keyboardAccessible"},selected:null,currentMenuControl:null,debounceSearch:null,$search:null,$clearResults:null,searchTerm:"",rendered:!1,pages:{},sectionContent:"",loading:!1,addingNew:!1,initialize:function(){var a=this;v.panel.has("nav_menus")&&(this.$search=g("#menu-items-search"),this.$clearResults=this.$el.find(".clear-results"),this.sectionContent=this.$el.find(".available-menu-items-list"),this.debounceSearch=_.debounce(a.search,500),_.bindAll(this,"close"),g("#customize-controls, .customize-section-back").on("click keydown",function(e){var t=g(e.target).is(".item-delete, .item-delete *"),n=g(e.target).is(".add-new-menu-item, .add-new-menu-item *");!g("body").hasClass("adding-menu-items")||t||n||a.close()}),this.$clearResults.on("click",function(){a.$search.val("").focus().trigger("keyup")}),this.$el.on("input","#custom-menu-item-name.invalid, #custom-menu-item-url.invalid",function(){g(this).removeClass("invalid")}),v.panel("nav_menus").container.bind("expanded",function(){a.rendered||(a.initList(),a.rendered=!0)}),this.sectionContent.scroll(function(){var e=a.$el.find(".accordion-section.open .available-menu-items-list").prop("scrollHeight"),t=a.$el.find(".accordion-section.open").height();if(!a.loading&&g(this).scrollTop()>.75*e-t){var n=g(this).data("type"),i=g(this).data("object");"search"===n?a.searchTerm&&a.doSearch(a.pages.search):a.loadItems([{type:n,object:i}])}}),v.previewer.bind("url",this.close),a.delegateEvents())},search:function(e){var t=g("#available-menu-items-search"),n=g("#available-menu-items .accordion-section").not(t);e&&this.searchTerm!==e.target.value&&(""===e.target.value||t.hasClass("open")?""===e.target.value&&(t.removeClass("open"),n.show(),this.$clearResults.removeClass("is-visible")):(n.fadeOut(100),t.find(".accordion-section-content").slideDown("fast"),t.addClass("open"),this.$clearResults.addClass("is-visible")),this.searchTerm=e.target.value,this.pages.search=1,this.doSearch(1))},doSearch:function(n){var e,i=this,a=g("#available-menu-items-search"),o=a.find(".accordion-section-content"),s=h.template("available-menu-item");if(i.currentRequest&&i.currentRequest.abort(),!(n<0)){if(1<n)a.addClass("loading-more"),o.attr("aria-busy","true"),h.a11y.speak(v.Menus.data.l10n.itemsLoadingMore);else if(""===i.searchTerm)return o.html(""),void h.a11y.speak("");a.addClass("loading"),i.loading=!0,e=v.previewer.query({excludeCustomizedSaved:!0}),_.extend(e,{"customize-menus-nonce":v.settings.nonce["customize-menus"],wp_customize:"on",search:i.searchTerm,page:n}),i.currentRequest=h.ajax.post("search-available-menu-items-customizer",e),i.currentRequest.done(function(e){var t;1===n&&o.empty(),a.removeClass("loading loading-more"),o.attr("aria-busy","false"),a.addClass("open"),i.loading=!1,t=new v.Menus.AvailableItemCollection(e.items),i.collection.add(t.models),t.each(function(e){o.append(s(e.attributes))}),t.length<20?i.pages.search=-1:i.pages.search=i.pages.search+1,t&&1<n?h.a11y.speak(v.Menus.data.l10n.itemsFoundMore.replace("%d",t.length)):t&&1===n&&h.a11y.speak(v.Menus.data.l10n.itemsFound.replace("%d",t.length))}),i.currentRequest.fail(function(e){e.message&&(o.empty().append(g('<li class="nothing-found"></li>').text(e.message)),h.a11y.speak(e.message)),i.pages.search=-1}),i.currentRequest.always(function(){a.removeClass("loading loading-more"),o.attr("aria-busy","false"),i.loading=!1,i.currentRequest=null})}},initList:function(){var t=this;_.each(v.Menus.data.itemTypes,function(e){t.pages[e.type+":"+e.object]=0}),t.loadItems(v.Menus.data.itemTypes)},loadItems:function(e,t){var n,i,a,o,s=this,r=[],d={};o=h.template("available-menu-item"),n=_.isString(e)&&_.isString(t)?[{type:e,object:t}]:e,_.each(n,function(e){var t,n=e.type+":"+e.object;-1!==s.pages[n]&&((t=g("#available-menu-items-"+e.type+"-"+e.object)).find(".accordion-section-title").addClass("loading"),d[n]=t,r.push({object:e.object,type:e.type,page:s.pages[n]}))}),0!==r.length&&(s.loading=!0,i=v.previewer.query({excludeCustomizedSaved:!0}),_.extend(i,{"customize-menus-nonce":v.settings.nonce["customize-menus"],wp_customize:"on",item_types:r}),(a=h.ajax.post("load-available-menu-items-customizer",i)).done(function(e){var n;_.each(e.items,function(e,t){if(0===e.length)return 0===s.pages[t]&&d[t].find(".accordion-section-title").addClass("cannot-expand").removeClass("loading").find(".accordion-section-title > button").prop("tabIndex",-1),void(s.pages[t]=-1);"post_type:page"!==t||d[t].hasClass("open")||d[t].find(".accordion-section-title > button").click(),e=new v.Menus.AvailableItemCollection(e),s.collection.add(e.models),n=d[t].find(".available-menu-items-list"),e.each(function(e){n.append(o(e.attributes))}),s.pages[t]+=1})}),a.fail(function(e){"undefined"!=typeof console&&console.error&&console.error(e)}),a.always(function(){_.each(d,function(e){e.find(".accordion-section-title").removeClass("loading")}),s.loading=!1}))},itemSectionHeight:function(){var e,t,n,i;n=window.innerHeight,e=this.$el.find(".accordion-section:not( #available-menu-items-search ) .accordion-section-content"),t=this.$el.find('.accordion-section:not( #available-menu-items-search ) .available-menu-items-list:not(":only-child")'),120<(i=n-(46*(1+e.length)+14))&&i<290&&(e.css("max-height",i),t.css("max-height",i-60))},select:function(e){this.selected=g(e),this.selected.siblings(".menu-item-tpl").removeClass("selected"),this.selected.addClass("selected")},focus:function(e){this.select(g(e.currentTarget))},_submit:function(e){"keypress"===e.type&&13!==e.which&&32!==e.which||this.submit(g(e.currentTarget))},submit:function(e){var t,n;(e=e||this.selected)&&this.currentMenuControl&&(this.select(e),t=g(this.selected).data("menu-item-id"),(n=this.collection.findWhere({id:t}))&&(this.currentMenuControl.addItemToMenu(n.attributes),g(e).find(".menu-item-handle").addClass("item-added")))},_submitLink:function(e){"keypress"===e.type&&13!==e.which||this.submitLink()},submitLink:function(){var e,t,n=g("#custom-menu-item-name"),i=g("#custom-menu-item-url"),a=i.val().trim();this.currentMenuControl&&(t=/^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/,""!==n.val()?t.test(a)?(e={title:n.val(),url:a,type:"custom",type_label:v.Menus.data.l10n.custom_label,object:"custom"},this.currentMenuControl.addItemToMenu(e),i.val("").attr("placeholder","https://"),n.val("")):i.addClass("invalid"):n.addClass("invalid"))},_submitNew:function(e){var t;"keypress"===e.type&&13!==e.which||this.addingNew||(t=g(e.target).closest(".accordion-section"),this.submitNew(t))},submitNew:function(a){var o=this,s=a.find(".create-item-input"),e=s.val(),t=a.find(".available-menu-items-list"),r=t.data("type"),d=t.data("object"),u=t.data("type_label");if(this.currentMenuControl&&"post_type"===r){if(""===g.trim(s.val()))return s.addClass("invalid"),void s.focus();s.removeClass("invalid"),a.find(".accordion-section-title").addClass("loading"),o.addingNew=!0,s.attr("disabled","disabled"),v.Menus.insertAutoDraftPost({post_title:e,post_type:d}).done(function(e){var t,n,i;t=new v.Menus.AvailableItemModel({id:"post-"+e.post_id,title:s.val(),type:r,type_label:u,object:d,object_id:e.post_id,url:e.url}),o.currentMenuControl.addItemToMenu(t.attributes),v.Menus.availableMenuItemsPanel.collection.add(t),n=a.find(".available-menu-items-list"),(i=g(h.template("available-menu-item")(t.attributes))).find(".menu-item-handle:first").addClass("item-added"),n.prepend(i),n.scrollTop(),s.val("").removeAttr("disabled"),o.addingNew=!1,a.find(".accordion-section-title").removeClass("loading")})}},open:function(e){var t,n=this;this.currentMenuControl=e,this.itemSectionHeight(),v.section.has("publish_settings")&&v.section("publish_settings").collapse(),g("body").addClass("adding-menu-items"),t=function(){n.close(),g(this).off("click",t)},g("#customize-preview").on("click",t),_(this.currentMenuControl.getMenuItemControls()).each(function(e){e.collapseForm()}),this.$el.find(".selected").removeClass("selected"),this.$search.focus()},close:function(e){(e=e||{}).returnFocus&&this.currentMenuControl&&this.currentMenuControl.container.find(".add-new-menu-item").focus(),this.currentMenuControl=null,this.selected=null,g("body").removeClass("adding-menu-items"),g("#available-menu-items .menu-item-handle.item-added").removeClass("item-added"),this.$search.val("").trigger("keyup")},keyboardAccessible:function(e){var t=13===e.which,n=27===e.which,i=9===e.which&&e.shiftKey,a=g(e.target).is(this.$search);t&&!this.$search.val()||(a&&i?(this.currentMenuControl.container.find(".add-new-menu-item").focus(),e.preventDefault()):n&&this.close({returnFocus:!0}))}}),v.Menus.MenusPanel=v.Panel.extend({attachEvents:function(){v.Panel.prototype.attachEvents.call(this);var t=this.container.find(".panel-meta"),n=t.find(".customize-help-toggle"),i=t.find(".customize-panel-description"),a=g("#screen-options-wrap"),o=t.find(".customize-screen-options-toggle");o.on("click keydown",function(e){if(!v.utils.isKeydownButNotEnterEvent(e))return e.preventDefault(),i.not(":hidden")&&(i.slideUp("fast"),n.attr("aria-expanded","false")),"true"===o.attr("aria-expanded")?(o.attr("aria-expanded","false"),t.removeClass("open"),t.removeClass("active-menu-screen-options"),a.slideUp("fast")):(o.attr("aria-expanded","true"),t.addClass("open"),t.addClass("active-menu-screen-options"),a.slideDown("fast")),!1}),n.on("click keydown",function(e){v.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),"true"===o.attr("aria-expanded")&&(o.attr("aria-expanded","false"),n.attr("aria-expanded","true"),t.addClass("open"),t.removeClass("active-menu-screen-options"),a.slideUp("fast"),i.slideDown("fast")))})},ready:function(){var e=this;e.container.find(".hide-column-tog").click(function(){e.saveManageColumnsState()}),v.section("menu_locations",function(e){e.headContainer.prepend(h.template("nav-menu-locations-header")(v.Menus.data))})},saveManageColumnsState:_.debounce(function(){var e=this;e._updateHiddenColumnsRequest&&e._updateHiddenColumnsRequest.abort(),e._updateHiddenColumnsRequest=h.ajax.post("hidden-columns",{hidden:e.hidden(),screenoptionnonce:g("#screenoptionnonce").val(),page:"nav-menus"}),e._updateHiddenColumnsRequest.always(function(){e._updateHiddenColumnsRequest=null})},2e3),checked:function(){},unchecked:function(){},hidden:function(){return g(".hide-column-tog").not(":checked").map(function(){var e=this.id;return e.substring(0,e.length-5)}).get().join(",")}}),v.Menus.MenuSection=v.Section.extend({initialize:function(e,t){v.Section.prototype.initialize.call(this,e,t),this.deferred.initSortables=g.Deferred()},ready:function(){var e,t,i=this;if(void 0===i.params.menu_id)throw new Error("params.menu_id was not defined");i.active.validate=function(){return!!v.has(i.id)&&!!v(i.id).get()},i.populateControls(),i.navMenuLocationSettings={},i.assignedLocations=new v.Value([]),v.each(function(e,t){var n=t.match(/^nav_menu_locations\[(.+?)]/);n&&(i.navMenuLocationSettings[n[1]]=e).bind(function(){i.refreshAssignedLocations()})}),i.assignedLocations.bind(function(e){i.updateAssignedLocationsInSectionTitle(e)}),i.refreshAssignedLocations(),v.bind("pane-contents-reflowed",function(){i.contentContainer.parent().length&&(i.container.find(".menu-item .menu-item-reorder-nav button").attr({tabindex:"0","aria-hidden":"false"}),i.container.find(".menu-item.move-up-disabled .menus-move-up").attr({tabindex:"-1","aria-hidden":"true"}),i.container.find(".menu-item.move-down-disabled .menus-move-down").attr({tabindex:"-1","aria-hidden":"true"}),i.container.find(".menu-item.move-left-disabled .menus-move-left").attr({tabindex:"-1","aria-hidden":"true"}),i.container.find(".menu-item.move-right-disabled .menus-move-right").attr({tabindex:"-1","aria-hidden":"true"}))}),t=function(){var e="field-"+g(this).val()+"-active";i.contentContainer.toggleClass(e,g(this).prop("checked"))},(e=v.panel("nav_menus").contentContainer.find(".metabox-prefs:first").find(".hide-column-tog")).each(t),e.on("click",t)},populateControls:function(){var e,t,n,i,a,o,s,r,d,u=this;e=u.id+"[name]",(o=v.control(e))||(o=new v.controlConstructor.nav_menu_name(e,{type:"nav_menu_name",label:v.Menus.data.l10n.menuNameLabel,section:u.id,priority:0,settings:{default:u.id}}),v.control.add(o),o.active.set(!0)),(a=v.control(u.id))||(a=new v.controlConstructor.nav_menu(u.id,{type:"nav_menu",section:u.id,priority:998,settings:{default:u.id},menu_id:u.params.menu_id}),v.control.add(a),a.active.set(!0)),t=u.id+"[locations]",(s=v.control(t))||(s=new v.controlConstructor.nav_menu_locations(t,{section:u.id,priority:999,settings:{default:u.id},menu_id:u.params.menu_id}),v.control.add(s.id,s),a.active.set(!0)),n=u.id+"[auto_add]",(r=v.control(n))||(r=new v.controlConstructor.nav_menu_auto_add(n,{type:"nav_menu_auto_add",label:"",section:u.id,priority:1e3,settings:{default:u.id}}),v.control.add(r),r.active.set(!0)),i=u.id+"[delete]",(d=v.control(i))||(d=new v.Control(i,{section:u.id,priority:1001,templateId:"nav-menu-delete-button"}),v.control.add(d.id,d),d.active.set(!0),d.deferred.embedded.done(function(){d.container.find("button").on("click",function(){var e=u.params.menu_id;v.Menus.getMenuControl(e).setting.set(!1)})}))},refreshAssignedLocations:function(){var n=this.params.menu_id,i=[];_.each(this.navMenuLocationSettings,function(e,t){e()===n&&i.push(t)}),this.assignedLocations.set(i)},updateAssignedLocationsInSectionTitle:function(e){var i;(i=this.container.find(".accordion-section-title:first")).find(".menu-in-location").remove(),_.each(e,function(e){var t,n;t=g('<span class="menu-in-location"></span>'),n=v.Menus.data.locationSlugMappedToName[e],t.text(v.Menus.data.l10n.menuLocation.replace("%s",n)),i.append(t)}),this.container.toggleClass("assigned-to-menu-location",0!==e.length)},onChangeExpanded:function(e,t){var n,i=this;e&&(wpNavMenu.menuList=i.contentContainer,wpNavMenu.targetList=wpNavMenu.menuList,g("#menu-to-edit").removeAttr("id"),wpNavMenu.menuList.attr("id","menu-to-edit").addClass("menu"),_.each(v.section(i.id).controls(),function(e){"nav_menu_item"===e.params.type&&e.actuallyEmbed()}),t.completeCallback&&(n=t.completeCallback),t.completeCallback=function(){"resolved"!==i.deferred.initSortables.state()&&(wpNavMenu.initSortables(),i.deferred.initSortables.resolve(wpNavMenu.menuList),v.control("nav_menu["+String(i.params.menu_id)+"]").reflowMenuItems()),_.isFunction(n)&&n()}),v.Section.prototype.onChangeExpanded.call(i,e,t)},highlightNewItemButton:function(){v.utils.highlightButton(this.contentContainer.find(".add-new-menu-item"),{delay:2e3})}}),v.Menus.createNavMenu=function(e){var t,n;return n=v.Menus.generatePlaceholderAutoIncrementId(),t="nav_menu["+String(n)+"]",v.create(t,t,{},{type:"nav_menu",transport:v.Menus.data.settingTransport,previewer:v.previewer}).set(g.extend({},v.Menus.data.defaultSettingValues.nav_menu,{name:e||""})),v.section.add(new v.Menus.MenuSection(t,{panel:"nav_menus",title:u(e),customizeAction:v.Menus.data.l10n.customizingMenus,priority:10,menu_id:n}))},v.Menus.NewMenuSection=v.Section.extend({attachEvents:function(){var t=this,e=t.container,n=t.contentContainer,i=/^nav_menu\[/;function a(){e.find(".add-new-menu-notice").prop("hidden",0<function(){var t=0;return v.each(function(e){i.test(e.id)&&!1!==e.get()&&(t+=1)}),t}())}function o(e){i.test(e.id)&&(e.bind(a),a())}t.headContainer.find(".accordion-section-title").replaceWith(h.template("nav-menu-create-menu-section-title")),e.on("click",".customize-add-menu-button",function(){t.expand()}),n.on("keydown",".menu-name-field",function(e){13===e.which&&t.submit()}),n.on("click","#customize-new-menu-submit",function(e){t.submit(),e.stopPropagation(),e.preventDefault()}),v.each(o),v.bind("add",o),v.bind("removed",function(e){i.test(e.id)&&(e.unbind(a),a())}),a(),v.Section.prototype.attachEvents.apply(t,arguments)},ready:function(){this.populateControls()},populateControls:function(){var e,t,n,i,a,o,s=this;e=s.id+"[name]",(i=v.control(e))||(i=new v.controlConstructor.nav_menu_name(e,{label:v.Menus.data.l10n.menuNameLabel,description:v.Menus.data.l10n.newMenuNameDescription,section:s.id,priority:0}),v.control.add(i.id,i),i.active.set(!0)),t=s.id+"[locations]",(a=v.control(t))||(a=new v.controlConstructor.nav_menu_locations(t,{section:s.id,priority:1,menu_id:"",isCreating:!0}),v.control.add(t,a),a.active.set(!0)),n=s.id+"[submit]",(o=v.control(n))||(o=new v.Control(n,{section:s.id,priority:1,templateId:"nav-menu-submit-new-button"}),v.control.add(n,o),o.active.set(!0))},submit:function(){var t,e=this.contentContainer,n=e.find(".menu-name-field").first(),i=n.val();if(!i)return n.addClass("invalid"),void n.focus();t=v.Menus.createNavMenu(i),n.val(""),n.removeClass("invalid"),e.find(".assigned-menu-location input[type=checkbox]").each(function(){var e=g(this);e.prop("checked")&&(v("nav_menu_locations["+e.data("location-id")+"]").set(t.params.menu_id),e.prop("checked",!1))}),h.a11y.speak(v.Menus.data.l10n.menuAdded),t.focus({completeCallback:function(){t.highlightNewItemButton()}})},selectDefaultLocation:function(e){var t=v.control(this.id+"[locations]"),n={};null!==e&&(n[e]=!0),t.setSelections(n)}}),v.Menus.MenuLocationControl=v.Control.extend({initialize:function(e,t){var n=e.match(/^nav_menu_locations\[(.+?)]/);this.themeLocation=n[1],v.Control.prototype.initialize.call(this,e,t)},ready:function(){var a=this,o=/^nav_menu\[(-?\d+)]/;a.setting.validate=function(e){return""===e?0:parseInt(e,10)},a.container.find(".create-menu").on("click",function(){var e=v.section("add_menu");e.selectDefaultLocation(this.dataset.locationId),e.focus()}),a.container.find(".edit-menu").on("click",function(){var e=a.setting();v.section("nav_menu["+e+"]").focus()}),a.setting.bind("change",function(){var e=0!==a.setting();a.container.find(".create-menu").toggleClass("hidden",e),a.container.find(".edit-menu").toggleClass("hidden",!e)}),v.bind("add",function(e){var t,n,i=e.id.match(o);i&&!1!==e()&&(n=i[1],t=new Option(u(e().name),n),a.container.find("select").append(t))}),v.bind("remove",function(e){var t,n=e.id.match(o);n&&(t=parseInt(n[1],10),a.setting()===t&&a.setting.set(""),a.container.find("option[value="+t+"]").remove())}),v.bind("change",function(e){var t,n=e.id.match(o);n&&(t=parseInt(n[1],10),!1===e()?(a.setting()===t&&a.setting.set(""),a.container.find("option[value="+t+"]").remove()):a.container.find("option[value="+t+"]").text(u(e().name)))})}}),v.Menus.MenuItemControl=v.Control.extend({initialize:function(e,t){var n=this;n.expanded=new v.Value(!1),n.expandedArgumentsQueue=[],n.expanded.bind(function(e){var t=n.expandedArgumentsQueue.shift();t=g.extend({},n.defaultExpandedArguments,t),n.onChangeExpanded(e,t)}),v.Control.prototype.initialize.call(n,e,t),n.active.validate=function(){var e=v.section(n.section());return!!e&&e.active()}},embed:function(){var e,t=this.section();t&&((e=v.section(t))&&e.expanded()||v.settings.autofocus.control===this.id)&&this.actuallyEmbed()},actuallyEmbed:function(){"resolved"!==this.deferred.embedded.state()&&(this.renderContent(),this.deferred.embedded.resolve())},ready:function(){if(void 0===this.params.menu_item_id)throw new Error("params.menu_item_id was not defined");this._setupControlToggle(),this._setupReorderUI(),this._setupUpdateUI(),this._setupRemoveUI(),this._setupLinksUI(),this._setupTitleUI()},_setupControlToggle:function(){var a=this;this.container.find(".menu-item-handle").on("click",function(e){e.preventDefault(),e.stopPropagation();var t=a.getMenuControl(),n=g(e.target).is(".item-delete, .item-delete *"),i=g(e.target).is(".add-new-menu-item, .add-new-menu-item *");!g("body").hasClass("adding-menu-items")||n||i||v.Menus.availableMenuItemsPanel.close(),t.isReordering||t.isSorting||a.toggleForm()})},_setupReorderUI:function(){var e,o=this;e=h.template("menu-item-reorder-nav"),o.container.find(".item-controls").after(e),o.container.find(".menu-item-reorder-nav").find(".menus-move-up, .menus-move-down, .menus-move-left, .menus-move-right").on("click",function(){var e=g(this);e.focus();var t=e.is(".menus-move-up"),n=e.is(".menus-move-down"),i=e.is(".menus-move-left"),a=e.is(".menus-move-right");t?o.moveUp():n?o.moveDown():i?o.moveLeft():a&&o.moveRight(),e.focus()})},_setupUpdateUI:function(){var e,s=this,t=s.setting();s.elements={},s.elements.url=new v.Element(s.container.find(".edit-menu-item-url")),s.elements.title=new v.Element(s.container.find(".edit-menu-item-title")),s.elements.attr_title=new v.Element(s.container.find(".edit-menu-item-attr-title")),s.elements.target=new v.Element(s.container.find(".edit-menu-item-target")),s.elements.classes=new v.Element(s.container.find(".edit-menu-item-classes")),s.elements.xfn=new v.Element(s.container.find(".edit-menu-item-xfn")),s.elements.description=new v.Element(s.container.find(".edit-menu-item-description")),_.each(s.elements,function(n,i){n.bind(function(e){n.element.is("input[type=checkbox]")&&(e=e?n.element.val():"");var t=s.setting();t&&t[i]!==e&&((t=_.clone(t))[i]=e,s.setting.set(t))}),t&&("classes"!==i&&"xfn"!==i||!_.isArray(t[i])?n.set(t[i]):n.set(t[i].join(" ")))}),s.setting.bind(function(n,i){var e,t=s.params.menu_item_id,a=[],o=[];!1===n?(e=v.control("nav_menu["+String(i.nav_menu_term_id)+"]"),s.container.remove(),_.each(e.getMenuItemControls(),function(e){i.menu_item_parent===e.setting().menu_item_parent&&e.setting().position>i.position?a.push(e):e.setting().menu_item_parent===t&&o.push(e)}),_.each(a,function(e){var t=_.clone(e.setting());t.position+=o.length,e.setting.set(t)}),_.each(o,function(e,t){var n=_.clone(e.setting());n.position=i.position+t,n.menu_item_parent=i.menu_item_parent,e.setting.set(n)}),e.debouncedReflowMenuItems()):(_.each(n,function(e,t){s.elements[t]&&s.elements[t].set(n[t])}),s.container.find(".menu-item-data-parent-id").val(n.menu_item_parent),n.position===i.position&&n.menu_item_parent===i.menu_item_parent||s.getMenuControl().debouncedReflowMenuItems())}),e=function(){s.elements.url.element.toggleClass("invalid",s.setting.notifications.has("invalid_url"))},s.setting.notifications.bind("add",e),s.setting.notifications.bind("removed",e)},_setupRemoveUI:function(){var d=this;d.container.find(".item-delete").on("click",function(){var e,t,n,i,a=!0,o=0,s=d.params.original_item_id,r=d.getMenuControl().$sectionContent.find(".menu-item");g("body").hasClass("adding-menu-items")||(a=!1),t=d.container.nextAll(".customize-control-nav_menu_item:visible").first(),n=d.container.prevAll(".customize-control-nav_menu_item:visible").first(),e=t.length?t.find(!1===a?".item-edit":".item-delete").first():n.length?n.find(!1===a?".item-edit":".item-delete").first():d.container.nextAll(".customize-control-nav_menu").find(".add-new-menu-item").first(),_.each(r,function(e){var t,n,i;g(e).is(":visible")&&(i=e.getAttribute("id").match(/^customize-control-nav_menu_item-(-?\d+)$/,""))&&(t=parseInt(i[1],10),(n=v.control("nav_menu_item["+String(t)+"]"))&&s==n.params.original_item_id&&o++)}),o<=1&&((i=g("#menu-item-tpl-"+d.params.original_item_id)).removeClass("selected"),i.find(".menu-item-handle").removeClass("item-added")),d.container.slideUp(function(){d.setting.set(!1),h.a11y.speak(v.Menus.data.l10n.itemDeleted),e.focus()}),d.setting.set(!1)})},_setupLinksUI:function(){this.container.find("a.original-link").on("click",function(e){e.preventDefault(),v.previewer.previewUrl(e.target.toString())})},_setupTitleUI:function(){var i;this.container.find(".edit-menu-item-title").on("blur",function(){g(this).val(g.trim(g(this).val()))}),i=this.container.find(".menu-item-title"),this.setting.bind(function(e){var t,n;e&&(n=(t=g.trim(e.title))||e.original_title||v.Menus.data.l10n.untitled,e._invalid&&(n=v.Menus.data.l10n.invalidTitleTpl.replace("%s",n)),t||e.original_title?i.text(n).removeClass("no-title"):i.text(n).addClass("no-title"))})},getDepth:function(){var e=this,t=e.setting(),n=0;if(!t)return 0;for(;t&&t.menu_item_parent&&(n+=1,e=v.control("nav_menu_item["+t.menu_item_parent+"]"));)t=e.setting();return n},renderContent:function(){var e,t=this,n=t.setting();t.params.title=n.title||"",t.params.depth=t.getDepth(),t.container.data("item-depth",t.params.depth),e=["menu-item","menu-item-depth-"+String(t.params.depth),"menu-item-"+n.object,"menu-item-edit-inactive"],n._invalid?(e.push("menu-item-invalid"),t.params.title=v.Menus.data.l10n.invalidTitleTpl.replace("%s",t.params.title)):"draft"===n.status&&(e.push("pending"),t.params.title=v.Menus.data.pendingTitleTpl.replace("%s",t.params.title)),t.params.el_classes=e.join(" "),t.params.item_type_label=n.type_label,t.params.item_type=n.type,t.params.url=n.url,t.params.target=n.target,t.params.attr_title=n.attr_title,t.params.classes=_.isArray(n.classes)?n.classes.join(" "):n.classes,t.params.xfn=n.xfn,t.params.description=n.description,t.params.parent=n.menu_item_parent,t.params.original_title=n.original_title||"",t.container.addClass(t.params.el_classes),v.Control.prototype.renderContent.call(t)},getMenuControl:function(){var e=this.setting();return e&&e.nav_menu_term_id?v.control("nav_menu["+e.nav_menu_term_id+"]"):null},expandControlSection:function(){var e=this.container.closest(".accordion-section");e.hasClass("open")||e.find(".accordion-section-title:first").trigger("click")},_toggleExpanded:v.Section.prototype._toggleExpanded,expand:v.Section.prototype.expand,expandForm:function(e){this.expand(e)},collapse:v.Section.prototype.collapse,collapseForm:function(e){this.collapse(e)},toggleForm:function(e,t){void 0===e&&(e=!this.expanded()),e?this.expand(t):this.collapse(t)},onChangeExpanded:function(e,t){var n,i,a,o=this;i=(n=this.container).find(".menu-item-settings:first"),void 0===e&&(e=!i.is(":visible")),i.is(":visible")!==e?e?(v.control.each(function(e){o.params.type===e.params.type&&o!==e&&e.collapseForm()}),a=function(){n.removeClass("menu-item-edit-inactive").addClass("menu-item-edit-active"),o.container.trigger("expanded"),t&&t.completeCallback&&t.completeCallback()},n.find(".item-edit").attr("aria-expanded","true"),i.slideDown("fast",a),o.container.trigger("expand")):(a=function(){n.addClass("menu-item-edit-inactive").removeClass("menu-item-edit-active"),o.container.trigger("collapsed"),t&&t.completeCallback&&t.completeCallback()},o.container.trigger("collapse"),n.find(".item-edit").attr("aria-expanded","false"),i.slideUp("fast",a)):t&&t.completeCallback&&t.completeCallback()},focus:function(e){var t,n=this,i=(e=e||{}).completeCallback;t=function(){n.expandControlSection(),e.completeCallback=function(){n.container.find(".menu-item-settings").find("input, select, textarea, button, object, a[href], [tabindex]").filter(":visible").first().focus(),i&&i()},n.expandForm(e)},v.section.has(n.section())?v.section(n.section()).expand({completeCallback:t}):t()},moveUp:function(){this._changePosition(-1),h.a11y.speak(v.Menus.data.l10n.movedUp)},moveDown:function(){this._changePosition(1),h.a11y.speak(v.Menus.data.l10n.movedDown)},moveLeft:function(){this._changeDepth(-1),h.a11y.speak(v.Menus.data.l10n.movedLeft)},moveRight:function(){this._changeDepth(1),h.a11y.speak(v.Menus.data.l10n.movedRight)},_changePosition:function(e){var t,n,i=this,a=_.clone(i.setting()),o=[];if(1!==e&&-1!==e)throw new Error("Offset changes by 1 are only supported.");if(i.setting()){if(_(i.getMenuControl().getMenuItemControls()).each(function(e){e.setting().menu_item_parent===a.menu_item_parent&&o.push(e.setting)}),o.sort(function(e,t){return e().position-t().position}),-1===(n=_.indexOf(o,i.setting)))throw new Error("Expected setting to be among siblings.");0===n&&e<0||n===o.length-1&&0<e||((t=o[n+e])&&t.set(g.extend(_.clone(t()),{position:a.position})),a.position+=e,i.setting.set(a))}},_changeDepth:function(e){if(1!==e&&-1!==e)throw new Error("Offset changes by 1 are only supported.");var t,n,i,a=this,o=_.clone(a.setting()),s=[];if(_(a.getMenuControl().getMenuItemControls()).each(function(e){e.setting().menu_item_parent===o.menu_item_parent&&s.push(e)}),s.sort(function(e,t){return e.setting().position-t.setting().position}),-1===(t=_.indexOf(s,a)))throw new Error("Expected control to be among siblings.");if(-1===e){if(!o.menu_item_parent)return;i=v.control("nav_menu_item["+o.menu_item_parent+"]"),_(s).chain().slice(t).each(function(e,t){e.setting.set(g.extend({},e.setting(),{menu_item_parent:a.params.menu_item_id,position:t}))}),_(a.getMenuControl().getMenuItemControls()).each(function(e){var t;e.setting().menu_item_parent===i.setting().menu_item_parent&&e.setting().position>i.setting().position&&(t=_.clone(e.setting()),e.setting.set(g.extend(t,{position:t.position+1})))}),o.position=i.setting().position+1,o.menu_item_parent=i.setting().menu_item_parent,a.setting.set(o)}else if(1===e){if(0===t)return;n=s[t-1],o.menu_item_parent=n.params.menu_item_id,o.position=0,_(a.getMenuControl().getMenuItemControls()).each(function(e){e.setting().menu_item_parent===o.menu_item_parent&&(o.position=Math.max(o.position,e.setting().position))}),o.position+=1,a.setting.set(o)}}}),v.Menus.MenuNameControl=v.Control.extend({ready:function(){var n=this;if(n.setting){var e=n.setting();n.nameElement=new v.Element(n.container.find(".menu-name-field")),n.nameElement.bind(function(e){var t=n.setting();t&&t.name!==e&&((t=_.clone(t)).name=e,n.setting.set(t))}),e&&n.nameElement.set(e.name),n.setting.bind(function(e){e&&n.nameElement.set(e.name)})}}}),v.Menus.MenuLocationsControl=v.Control.extend({ready:function(){var d=this;d.container.find(".assigned-menu-location").each(function(){function t(e){var t=v("nav_menu["+String(e)+"]");e&&t&&t()?n.find(".theme-location-set").show().find("span").text(u(t().name)):n.find(".theme-location-set").hide()}var n=g(this),e=n.find("input[type=checkbox]"),i=new v.Element(e),a=v("nav_menu_locations["+e.data("location-id")+"]"),o=""===d.params.menu_id,s=o?_.noop:function(e){i.set(e)},r=o?_.noop:function(e){a.set(e?d.params.menu_id:0)};s(a.get()===d.params.menu_id),e.on("change",function(){r(this.checked)}),a.bind(function(e){s(e===d.params.menu_id),t(e)}),t(a.get())})},setSelections:function(i){this.container.find(".menu-location").each(function(e,t){var n=t.dataset.locationId;t.checked=n in i&&i[n]})}}),v.Menus.MenuAutoAddControl=v.Control.extend({ready:function(){var n=this,e=n.setting();n.active.validate=function(){var e=v.section(n.section());return!!e&&e.active()},n.autoAddElement=new v.Element(n.container.find("input[type=checkbox].auto_add")),n.autoAddElement.bind(function(e){var t=n.setting();t&&t.name!==e&&((t=_.clone(t)).auto_add=e,n.setting.set(t))}),e&&n.autoAddElement.set(e.auto_add),n.setting.bind(function(e){e&&n.autoAddElement.set(e.auto_add)})}}),v.Menus.MenuControl=v.Control.extend({ready:function(){var t,e,n,i=this,a=v.section(i.section()),o=i.params.menu_id,s=i.setting();if(void 0===this.params.menu_id)throw new Error("params.menu_id was not defined");i.active.validate=function(){return!!a&&a.active()},i.$controlSection=a.headContainer,i.$sectionContent=i.container.closest(".accordion-section-content"),this._setupModel(),v.section(i.section(),function(e){e.deferred.initSortables.done(function(e){i._setupSortable(e)})}),this._setupAddition(),this._setupTitle(),s&&(t=u(s.name),v.control.each(function(e){e.extended(v.controlConstructor.widget_form)&&"nav_menu"===e.params.widget_id_base&&(e.container.find(".nav-menu-widget-form-controls:first").show(),e.container.find(".nav-menu-widget-no-menus-message:first").hide(),0===(n=e.container.find("select")).find("option[value="+String(o)+"]").length&&n.append(new Option(t,o)))}),(e=g("#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )")).find(".nav-menu-widget-form-controls:first").show(),e.find(".nav-menu-widget-no-menus-message:first").hide(),0===(n=e.find(".widget-inside select:first")).find("option[value="+String(o)+"]").length&&n.append(new Option(t,o))),_.defer(function(){i.updateInvitationVisibility()})},_setupModel:function(){var n=this,i=n.params.menu_id;n.setting.bind(function(e){var t;!1===e?n._handleDeletion():(t=u(e.name),v.control.each(function(e){e.extended(v.controlConstructor.widget_form)&&"nav_menu"===e.params.widget_id_base&&e.container.find("select").find("option[value="+String(i)+"]").text(t)}))})},_setupSortable:function(e){var t=this;if(!e.is(t.$sectionContent))throw new Error("Unexpected menuList.");e.on("sortstart",function(){t.isSorting=!0}),e.on("sortstop",function(){setTimeout(function(){var e=t.$sectionContent.sortable("toArray"),a=[],n=0,i=10;t.isSorting=!1,t.$sectionContent.scrollLeft(0),_.each(e,function(e){var t,n,i;(i=e.match(/^customize-control-nav_menu_item-(-?\d+)$/,""))&&(t=parseInt(i[1],10),(n=v.control("nav_menu_item["+String(t)+"]"))&&a.push(n))}),_.each(a,function(e){if(!1!==e.setting()){var t=_.clone(e.setting());n+=1,i+=1,t.position=n,e.priority(i),t.menu_item_parent=parseInt(e.container.find(".menu-item-data-parent-id").val(),10),t.menu_item_parent||(t.menu_item_parent=0),e.setting.set(t)}})})}),t.isReordering=!1,this.container.find(".reorder-toggle").on("click",function(){t.toggleReordering(!t.isReordering)})},_setupAddition:function(){var t=this;this.container.find(".add-new-menu-item").on("click",function(e){t.$sectionContent.hasClass("reordering")||(g("body").hasClass("adding-menu-items")?(g(this).attr("aria-expanded","false"),v.Menus.availableMenuItemsPanel.close(),e.stopPropagation()):(g(this).attr("aria-expanded","true"),v.Menus.availableMenuItemsPanel.open(t)))})},_handleDeletion:function(){var e,t,n,i=this.params.menu_id,a=0;e=v.section(this.section()),t=function(){e.container.remove(),v.section.remove(e.id)},e&&e.expanded()?e.collapse({completeCallback:function(){t(),h.a11y.speak(v.Menus.data.l10n.menuDeleted),v.panel("nav_menus").focus()}}):t(),v.each(function(e){/^nav_menu\[/.test(e.id)&&!1!==e()&&(a+=1)}),v.control.each(function(e){if(e.extended(v.controlConstructor.widget_form)&&"nav_menu"===e.params.widget_id_base){var t=e.container.find("select");t.val()===String(i)&&t.prop("selectedIndex",0).trigger("change"),e.container.find(".nav-menu-widget-form-controls:first").toggle(0!==a),e.container.find(".nav-menu-widget-no-menus-message:first").toggle(0===a),e.container.find("option[value="+String(i)+"]").remove()}}),(n=g("#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )")).find(".nav-menu-widget-form-controls:first").toggle(0!==a),n.find(".nav-menu-widget-no-menus-message:first").toggle(0===a),n.find("option[value="+String(i)+"]").remove()},_setupTitle:function(){var d=this;d.setting.bind(function(e){if(e){var t=v.section(d.section()),n=d.params.menu_id,i=t.headContainer.find(".accordion-section-title"),a=t.contentContainer.find(".customize-section-title h3"),o=t.headContainer.find(".menu-in-location"),s=a.find(".customize-action"),r=u(e.name);i.text(r),o.length&&o.appendTo(i),a.text(r),s.length&&s.prependTo(a),v.control.each(function(e){/^nav_menu_locations\[/.test(e.id)&&e.container.find("option[value="+n+"]").text(r)}),t.contentContainer.find(".customize-control-checkbox input").each(function(){g(this).prop("checked")&&g(".current-menu-location-name-"+g(this).data("location-id")).text(r)})}})},toggleReordering:function(e){var t=this.container.find(".add-new-menu-item"),n=this.container.find(".reorder-toggle"),i=this.$sectionContent.find(".item-title");(e=Boolean(e))!==this.$sectionContent.hasClass("reordering")&&(this.isReordering=e,this.$sectionContent.toggleClass("reordering",e),this.$sectionContent.sortable(this.isReordering?"disable":"enable"),this.isReordering?(t.attr({tabindex:"-1","aria-hidden":"true"}),n.attr("aria-label",v.Menus.data.l10n.reorderLabelOff),h.a11y.speak(v.Menus.data.l10n.reorderModeOn),i.attr("aria-hidden","false")):(t.removeAttr("tabindex aria-hidden"),n.attr("aria-label",v.Menus.data.l10n.reorderLabelOn),h.a11y.speak(v.Menus.data.l10n.reorderModeOff),i.attr("aria-hidden","true")),e&&_(this.getMenuItemControls()).each(function(e){e.collapseForm()}))},getMenuItemControls:function(){var t=[],n=this.params.menu_id;return v.control.each(function(e){"nav_menu_item"===e.params.type&&e.setting()&&n===e.setting().nav_menu_term_id&&t.push(e)}),t},reflowMenuItems:function(){var e,t=this.getMenuItemControls();(e=function(n){var t=[],i=n.currentParent;_.each(n.menuItemControls,function(e){i===e.setting().menu_item_parent&&t.push(e)}),t.sort(function(e,t){return e.setting().position-t.setting().position}),_.each(t,function(t){n.currentAbsolutePosition+=1,t.priority.set(n.currentAbsolutePosition),t.container.hasClass("menu-item-depth-"+String(n.currentDepth))||(_.each(t.container.prop("className").match(/menu-item-depth-\d+/g),function(e){t.container.removeClass(e)}),t.container.addClass("menu-item-depth-"+String(n.currentDepth))),t.container.data("item-depth",n.currentDepth),n.currentDepth+=1,n.currentParent=t.params.menu_item_id,e(n),n.currentDepth-=1,n.currentParent=i}),t.length&&(_(t).each(function(e){e.container.removeClass("move-up-disabled move-down-disabled move-left-disabled move-right-disabled"),0===n.currentDepth?e.container.addClass("move-left-disabled"):10===n.currentDepth&&e.container.addClass("move-right-disabled")}),t[0].container.addClass("move-up-disabled").addClass("move-right-disabled").toggleClass("move-down-disabled",1===t.length),t[t.length-1].container.addClass("move-down-disabled").toggleClass("move-up-disabled",1===t.length))})({menuItemControls:t,currentParent:0,currentDepth:0,currentAbsolutePosition:0}),this.updateInvitationVisibility(t),this.container.find(".reorder-toggle").toggle(1<t.length)},debouncedReflowMenuItems:_.debounce(function(){this.reflowMenuItems.apply(this,arguments)},0),addItemToMenu:function(e){var t,n,i,a,o,s=0,r=10,d=e.id||"";return _.each(this.getMenuItemControls(),function(e){!1!==e.setting()&&(r=Math.max(r,e.priority()),0===e.setting().menu_item_parent&&(s=Math.max(s,e.setting().position)))}),s+=1,r+=1,delete(e=g.extend({},v.Menus.data.defaultSettingValues.nav_menu_item,e,{nav_menu_term_id:this.params.menu_id,original_title:e.title,position:s})).id,o=v.Menus.generatePlaceholderAutoIncrementId(),t="nav_menu_item["+String(o)+"]",n={type:"nav_menu_item",transport:v.Menus.data.settingTransport,previewer:v.previewer},(i=v.create(t,t,{},n)).set(e),a=new v.controlConstructor.nav_menu_item(t,{type:"nav_menu_item",section:this.id,priority:r,settings:{default:t},menu_item_id:o,original_item_id:d}),v.control.add(a),i.preview(),this.debouncedReflowMenuItems(),h.a11y.speak(v.Menus.data.l10n.itemAdded),a},updateInvitationVisibility:function(e){var t=e||this.getMenuItemControls();this.container.find(".new-menu-item-invitation").toggle(0===t.length)}}),g.extend(v.controlConstructor,{nav_menu_location:v.Menus.MenuLocationControl,nav_menu_item:v.Menus.MenuItemControl,nav_menu:v.Menus.MenuControl,nav_menu_name:v.Menus.MenuNameControl,nav_menu_locations:v.Menus.MenuLocationsControl,nav_menu_auto_add:v.Menus.MenuAutoAddControl}),g.extend(v.panelConstructor,{nav_menus:v.Menus.MenusPanel}),g.extend(v.sectionConstructor,{nav_menu:v.Menus.MenuSection,new_menu:v.Menus.NewMenuSection}),v.bind("ready",function(){v.Menus.availableMenuItemsPanel=new v.Menus.AvailableMenuItemsPanelView({collection:v.Menus.availableMenuItems}),v.bind("saved",function(e){(e.nav_menu_updates||e.nav_menu_item_updates)&&v.Menus.applySavedData(e)}),v.state("changesetStatus").bind(function(e){"publish"===e&&(v("nav_menus_created_posts")._value=[])}),v.previewer.bind("focus-nav-menu-item-control",v.Menus.focusMenuItemControl)}),v.Menus.applySavedData=function(e){var f={},d={};_(e.nav_menu_updates).each(function(i){var e,t,n,a,o,s,r,d,u,c,l,m,p;if("inserted"===i.status){if(!i.previous_term_id)throw new Error("Expected previous_term_id");if(!i.term_id)throw new Error("Expected term_id");if(e="nav_menu["+String(i.previous_term_id)+"]",!v.has(e))throw new Error("Expected setting to exist: "+e);if(a=v(e),!v.section.has(e))throw new Error("Expected control to exist: "+e);if(d=v.section(e),!(r=a.get()))throw new Error("Did not expect setting to be empty (deleted).");r=g.extend(_.clone(r),i.saved_value),f[i.previous_term_id]=i.term_id,t="nav_menu["+String(i.term_id)+"]",o=v.create(t,t,r,{type:"nav_menu",transport:v.Menus.data.settingTransport,previewer:v.previewer}),(p=d.expanded())&&d.collapse(),u=new v.Menus.MenuSection(t,{panel:"nav_menus",title:r.name,customizeAction:v.Menus.data.l10n.customizingMenus,type:"nav_menu",priority:d.priority.get(),menu_id:i.term_id}),v.section.add(u),v.control.each(function(e){var t,n;e.extended(v.controlConstructor.widget_form)&&"nav_menu"===e.params.widget_id_base&&(n=(t=e.container.find("select")).find("option[value="+String(i.previous_term_id)+"]"),t.find("option[value="+String(i.term_id)+"]").prop("selected",n.prop("selected")),n.remove())}),a.callbacks.disable(),a.set(!1),a.preview(),o.preview(),a._dirty=!1,d.container.remove(),v.section.remove(e),m=0,v.each(function(e){/^nav_menu\[/.test(e.id)&&!1!==e()&&(m+=1)}),(l=g("#available-widgets-list .widget-tpl:has( input.id_base[ value=nav_menu ] )")).find(".nav-menu-widget-form-controls:first").toggle(0!==m),l.find(".nav-menu-widget-no-menus-message:first").toggle(0===m),l.find("option[value="+String(i.previous_term_id)+"]").remove(),h.customize.control.each(function(e){/^nav_menu_locations\[/.test(e.id)&&e.container.find("option[value="+String(i.previous_term_id)+"]").remove()}),v.each(function(e){var t=v.state("saved").get();/^nav_menu_locations\[/.test(e.id)&&e.get()===i.previous_term_id&&(e.set(i.term_id),e._dirty=!1,v.state("saved").set(t),e.preview())}),p&&u.expand()}else if("updated"===i.status){if(n="nav_menu["+String(i.term_id)+"]",!v.has(n))throw new Error("Expected setting to exist: "+n);s=v(n),_.isEqual(i.saved_value,s.get())||(c=v.state("saved").get(),s.set(i.saved_value),s._dirty=!1,v.state("saved").set(c))}}),_(e.nav_menu_item_updates).each(function(e){e.previous_post_id&&(d[e.previous_post_id]=e.post_id)}),_(e.nav_menu_item_updates).each(function(e){var t,n,i,a,o,s,r;if("inserted"===e.status){if(!e.previous_post_id)throw new Error("Expected previous_post_id");if(!e.post_id)throw new Error("Expected post_id");if(t="nav_menu_item["+String(e.previous_post_id)+"]",!v.has(t))throw new Error("Expected setting to exist: "+t);if(i=v(t),!v.control.has(t))throw new Error("Expected control to exist: "+t);if(s=v.control(t),!(o=i.get()))throw new Error("Did not expect setting to be empty (deleted).");if((o=_.clone(o)).menu_item_parent<0){if(!d[o.menu_item_parent])throw new Error("inserted ID for menu_item_parent not available");o.menu_item_parent=d[o.menu_item_parent]}f[o.nav_menu_term_id]&&(o.nav_menu_term_id=f[o.nav_menu_term_id]),n="nav_menu_item["+String(e.post_id)+"]",a=v.create(n,n,o,{type:"nav_menu_item",transport:v.Menus.data.settingTransport,previewer:v.previewer}),r=new v.controlConstructor.nav_menu_item(n,{type:"nav_menu_item",menu_id:e.post_id,section:"nav_menu["+String(o.nav_menu_term_id)+"]",priority:s.priority.get(),settings:{default:n},menu_item_id:e.post_id}),s.container.remove(),v.control.remove(t),v.control.add(r),i.callbacks.disable(),i.set(!1),i.preview(),a.preview(),i._dirty=!1,r.container.toggleClass("menu-item-edit-inactive",s.container.hasClass("menu-item-edit-inactive"))}}),_.each(e.widget_nav_menu_updates,function(e,t){var n=v(t);n&&(n._value=e,n.preview())})},v.Menus.focusMenuItemControl=function(e){var t=v.Menus.getMenuItemControl(e);t&&t.focus()},v.Menus.getMenuControl=function(e){return v.control("nav_menu["+e+"]")},v.Menus.getMenuItemControl=function(e){return v.control(function(e){return"nav_menu_item["+e+"]"}(e))}}(wp.customize,wp,jQuery); |