WordPress/wp-admin/js/customize-nav-menus.min.js

1 line
39 KiB
JavaScript
Raw Permalink Normal View History

!function(d,c,l){"use strict";function m(e){return e=e||"",e=l("<div>").text(e).html(),(e=l.trim(e))||d.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()},d.Menus=d.Menus||{},d.Menus.data={itemTypes:[],l10n:{},settingTransport:"refresh",phpIntMax:0,defaultSettingValues:{nav_menu:{},nav_menu_item:{}},locationSlugMappedToName:{}},"undefined"!=typeof _wpCustomizeNavMenusSettings&&l.extend(d.Menus.data,_wpCustomizeNavMenusSettings),d.Menus.generatePlaceholderAutoIncrementId=function(){return-Math.ceil(d.Menus.data.phpIntMax*Math.random())},d.Menus.AvailableItemModel=Backbone.Model.extend(l.extend({id:null},d.Menus.data.defaultSettingValues.nav_menu_item)),d.Menus.AvailableItemCollection=Backbone.Collection.extend({model:d.Menus.AvailableItemModel,sort_key:"order",comparator:function(e){return-e.get(this.sort_key)},sortByField:function(e){this.sort_key=e,this.sort()}}),d.Menus.availableMenuItems=new d.Menus.AvailableItemCollection(d.Menus.data.availableMenuItems),d.Menus.AvailableMenuItemsPanelView=c.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",keydown:"keyboardAccessible"},selected:null,currentMenuControl:null,debounceSearch:null,$search:null,searchTerm:"",rendered:!1,pages:{},sectionContent:"",loading:!1,initialize:function(){var n=this;d.panel.has("nav_menus")&&(this.$search=l("#menu-items-search"),this.sectionContent=this.$el.find(".accordion-section-content"),this.debounceSearch=_.debounce(n.search,500),_.bindAll(this,"close"),l("#customize-controls, .customize-section-back").on("click keydown",function(e){var t=l(e.target).is(".item-delete, .item-delete *"),e=l(e.target).is(".add-new-menu-item, .add-new-menu-item *");!l("body").hasClass("adding-menu-items")||t||e||n.close()}),l(".clear-results").on("click",function(){n.$search.val("").focus().trigger("keyup")}),this.$el.on("input","#custom-menu-item-name.invalid, #custom-menu-item-url.invalid",function(){l(this).removeClass("invalid")}),d.panel("nav_menus").container.bind("expanded",function(){n.rendered||(n.initList(),n.rendered=!0)}),this.sectionContent.scroll(function(){var e=n.$el.find(".accordion-section.open .accordion-section-content").prop("scrollHeight"),t=n.$el.find(".accordion-section.open").height();!n.loading&&l(this).scrollTop()>.75*e-t&&(e=l(this).data("type"),t=l(this).data("object"),"search"===e?n.searchTerm&&n.doSearch(n.pages.search):n.loadItems(e,t))}),d.previewer.bind("url",this.close),n.delegateEvents())},search:function(e){var t=l("#available-menu-items-search"),n=l("#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(),t.find(".clear-results").removeClass("is-visible")):(n.fadeOut(100),t.find(".accordion-section-content").slideDown("fast"),t.addClass("open"),t.find(".clear-results").addClass("is-visible")),this.searchTerm=e.target.value,this.pages.search=1,this.doSearch(1))},doSearch:function(t){var e,n=this,i=l("#available-menu-items-search"),a=i.find(".accordion-section-content"),o=c.template("available-menu-item");if(n.currentRequest&&n.currentRequest.abort(),!(t<0)){if(1<t)i.addClass("loading-more"),a.attr("aria-busy","true"),c.a11y.speak(d.Menus.data.l10n.itemsLoadingMore);else if(""===n.searchTerm)return a.html(""),void c.a11y.speak("");i.addClass("loading"),n.loading=!0,e={"customize-menus-nonce":d.settings.nonce["customize-menus"],wp_customize:"on",search:n.searchTerm,page:t},n.currentRequest=c.ajax.post("search-available-menu-items-customizer",e),n.currentRequest.done(function(e){1===t&&a.empty(),i.removeClass("loading loading-more"),a.attr("aria-busy