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

1 line
45 KiB
JavaScript
Raw Normal View History

!function(v,h,g){"use strict";function d(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.$clear