!function(v,h,g){"use strict";function d(e){return e=e||"",e=g("
").text(e).html(),(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","keyup #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').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=[],u={};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"),u[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]&&u[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||u[t].hasClass("open")||u[t].find(".accordion-section-title > button").click(),e=new v.Menus.AvailableItemCollection(e),s.collection.add(e.models),n=u[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(u,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),e&&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");this.currentMenuControl&&(t=/^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/,""!==n.val()?t.test(i.val())?(e={title:n.val(),url:i.val(),type:"custom",type_label:v.Menus.data.l10n.custom_label,object:"custom"},this.currentMenuControl.addItemToMenu(e),i.val("http://"),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"),u=t.data("object"),d=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:u}).done(function(e){var t,n,i;t=new v.Menus.AvailableItemModel({id:"post-"+e.post_id,title:s.val(),type:r,type_label:d,object:u,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,u,d=this;e=d.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:d.id,priority:0,settings:{default:d.id}}),v.control.add(o),o.active.set(!0)),(a=v.control(d.id))||(a=new v.controlConstructor.nav_menu(d.id,{type:"nav_menu",section:d.id,priority:998,settings:{default:d.id},menu_id:d.params.menu_id}),v.control.add(a),a.active.set(!0)),t=d.id+"[locations]",(s=v.control(t))||(s=new v.controlConstructor.nav_menu_locations(t,{section:d.id,priority:999,settings:{default:d.id},menu_id:d.params.menu_id}),v.control.add(s.id,s),a.active.set(!0)),n=d.id+"[auto_add]",(r=v.control(n))||(r=new v.controlConstructor.nav_menu_auto_add(n,{type:"nav_menu_auto_add",label:"",section:d.id,priority:1e3,settings:{default:d.id}}),v.control.add(r),r.active.set(!0)),i=d.id+"[delete]",(u=v.control(i))||(u=new v.Control(i,{section:d.id,priority:1001,templateId:"nav-menu-delete-button"}),v.control.add(u.id,u),u.active.set(!0),u.deferred.embedded.done(function(){u.container.find("button").on("click",function(){var e=d.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(''),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:d(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(){var t;e.find(".add-new-menu-notice").prop("hidden",(t=0,v.each(function(e){i.test(e.id)&&!1!==e.get()&&(t+=1)}),0i.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 a=this;a.container.find(".item-delete").on("click",function(){var e,t,n,i=!0;g("body").hasClass("adding-menu-items")||(i=!1),t=a.container.nextAll(".customize-control-nav_menu_item:visible").first(),n=a.container.prevAll(".customize-control-nav_menu_item:visible").first(),e=t.length?t.find(!1===i?".item-edit":".item-delete").first():n.length?n.find(!1===i?".item-edit":".item-delete").first():a.container.nextAll(".customize-control-nav_menu").find(".add-new-menu-item").first(),a.container.slideUp(function(){a.setting.set(!1),h.a11y.speak(v.Menus.data.l10n.itemDeleted),e.focus()}),a.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.attr_title=n.attr_title,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&&0i.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 u=this;u.container.find(".assigned-menu-location").each(function(){var n=g(this),e=n.find("input[type=checkbox]"),t=new v.Element(e),i=v("nav_menu_locations["+e.data("location-id")+"]"),a=""===u.params.menu_id,o=a?_.noop:function(e){t.set(e)},s=a?_.noop:function(e){i.set(e?u.params.menu_id:0)},r=function(e){var t=v("nav_menu["+String(e)+"]");e&&t&&t()?n.find(".theme-location-set").show().find("span").text(d(t().name)):n.find(".theme-location-set").hide()};o(i.get()===u.params.menu_id),e.on("change",function(){s(this.checked)}),i.bind(function(e){o(e===u.params.menu_id),r(e)}),r(i.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=d(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=d(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 u=this;u.setting.bind(function(e){if(e){var t=v.section(u.section()),n=u.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=d(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