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

2 lines
36 KiB
JavaScript
Raw Normal View History

!function(a,b,c){"use strict";function d(a){return"nav_menu_item["+a+"]"}function e(b){return b=b||"",b=c("<div>").text(b).html(),b=c.trim(b),b||a.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()},a.Menus=a.Menus||{},a.Menus.data={nonce:"",itemTypes:{taxonomies:{},postTypes:{}},l10n:{},menuItemTransport:"postMessage",phpIntMax:0,defaultSettingValues:{nav_menu:{},nav_menu_item:{}}},"undefined"!=typeof _wpCustomizeNavMenusSettings&&c.extend(a.Menus.data,_wpCustomizeNavMenusSettings),a.Menus.generatePlaceholderAutoIncrementId=function(){return-Math.ceil(a.Menus.data.phpIntMax*Math.random())},a.Menus.AvailableItemModel=Backbone.Model.extend(c.extend({id:null},a.Menus.data.defaultSettingValues.nav_menu_item)),a.Menus.AvailableItemCollection=Backbone.Collection.extend({model:a.Menus.AvailableItemModel,sort_key:"order",comparator:function(a){return-a.get(this.sort_key)},sortByField:function(a){this.sort_key=a,this.sort()}}),a.Menus.availableMenuItems=new a.Menus.AvailableItemCollection(a.Menus.data.availableMenuItems),a.Menus.AvailableMenuItemsPanelView=b.Backbone.View.extend({el:"#available-menu-items",events:{"input #menu-items-search":"debounceSearch","keyup #menu-items-search":"debounceSearch","click #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 b=this;this.$search=c("#menu-items-search"),this.sectionContent=this.$el.find(".accordion-section-content"),this.debounceSearch=_.debounce(b.search,500),_.bindAll(this,"close"),c("#customize-controls, .customize-section-back").on("click keydown",function(a){var d=c(a.target).is(".item-delete, .item-delete *"),e=c(a.target).is(".add-new-menu-item, .add-new-menu-item *");!c("body").hasClass("adding-menu-items")||d||e||b.close()}),this.$el.on("input","#custom-menu-item-name.invalid, #custom-menu-item-url.invalid",function(){c(this).removeClass("invalid")}),a.panel("nav_menus").container.bind("expanded",function(){b.rendered||(b.initList(),b.rendered=!0)}),this.sectionContent.scroll(function(){var a=b.$el.find(".accordion-section.open .accordion-section-content").prop("scrollHeight"),d=b.$el.find(".accordion-section.open").height();if(!b.loading&&c(this).scrollTop()>.75*a-d){var e=c(this).data("type"),f=c(this).data("obj_type");"search"===e?b.searchTerm&&b.doSearch(b.pages.search):b.loadItems(e,f)}}),a.previewer.bind("url",this.close)},search:function(a){a&&(this.searchTerm&&!c("#available-menu-items-search").hasClass("open")&&(c("#available-menu-items .accordion-section-content").slideUp("fast"),c("#available-menu-items-search .accordion-section-content").slideDown("fast"),c("#available-menu-items .accordion-section.open").removeClass("open"),c("#available-menu-items-search").addClass("open")),""===a.target.value&&c("#available-menu-items-search").removeClass("open"),this.searchTerm!==a.target.value&&(this.searchTerm=a.target.value,this.pages.search=1,this.doSearch(1)))},doSearch:function(d){var e,f=this,g=c("#available-menu-items-search"),h=g.find(".accordion-section-content"),i=b.template("available-menu-item");if(f.currentRequest&&f.currentRequest.abort(),!(0>d)){if(d>1)g.addClass("loading-more"),h.attr("aria-busy","true"),b.a11y.speak(a.Menus.data.l10n.itemsLoadingMore);else if(""===f.searchTerm)return h.html(""),void b.a11y.speak("");g.addClass("loading"),f.loading=!0,e={"customize-menus-nonce":a.Menus.data.nonce,wp_customize:"on",search:f.searchTerm,page:d},f.currentRequest=b.ajax.post("search-available-menu-items-customizer",e),f.currentRequest.done(function(c){var e;1===d&&h.empty(),g.removeClass("loading loading-more"),h.attr("aria-b
}),d.on("click",function(b){a.submit(),b.stopPropagation(),b.preventDefault()})},submit:function(){var d,f,g=this,h=g.container.closest(".accordion-section-new-menu"),i=h.find(".menu-name-field").first(),j=i.val(),k=a.Menus.generatePlaceholderAutoIncrementId();return j?(f="nav_menu["+String(k)+"]",a.create(f,f,{},{type:"nav_menu",transport:"postMessage",previewer:a.previewer}),a(f).set(c.extend({},a.Menus.data.defaultSettingValues.nav_menu,{name:j})),d=new a.Menus.MenuSection(f,{params:{id:f,panel:"nav_menus",title:e(j),customizeAction:a.Menus.data.l10n.customizingMenus,type:"nav_menu",priority:10,menu_id:k}}),a.section.add(f,d),i.val(""),i.removeClass("invalid"),b.a11y.speak(a.Menus.data.l10n.menuAdded),void a.section(f).focus()):(i.addClass("invalid"),void i.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,nav_menu_auto_add:a.Menus.MenuAutoAddControl,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=new a.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){var d={};_(b.nav_menu_updates).each(function(b){var e,f,g,h,i,j,k,l,m,n;if("inserted"===b.status){if(!b.previous_term_id)throw new Error("Expected previous_term_id");if(!b.term_id)throw new Error("Expected term_id");if(e="nav_menu["+String(b.previous_term_id)+"]",!a.has(e))throw new Error("Expected setting to exist: "+e);if(h=a(e),!a.section.has(e))throw new Error("Expected control to exist: "+e);if(l=a.section(e),k=h.get(),!k)throw new Error("Did not expect setting to be empty (deleted).");k=c.extend(_.clone(k),b.saved_value),d[b.previous_term_id]=b.term_id,f="nav_menu["+String(b.term_id)+"]",i=a.create(f,f,k,{type:"nav_menu",transport:"postMessage",previewer:a.previewer}),l.expanded()&&l.collapse(),m=new a.Menus.MenuSection(f,{params:{id:f,panel:"nav_menus",title:k.name,customizeAction:a.Menus.data.l10n.customizingMenus,type:"nav_menu",priority:l.priority.get(),active:!0,menu_id:b.term_id}}),l.container.remove(),a.section.remove(e),a.section.add(f,m),h.callbacks.disable(),h.set(!1),h.preview(),i.preview(),a.each(function(c){var d=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())}),l.expanded.get()&&m.expand()}else if("updated"===b.status){if(g="nav_menu["+String(b.term_id)+"]",!a.has(g))throw new Error("Expected setting to exist: "+g);j=a(g),_.isEqual(b.saved_value,j.get())||(n=a.state("saved").get(),j.set(b.saved_value),j._dirty=!1,a.state("saved").set(n))}}),_(b.nav_menu_item_updates).each(function(b){var c,e,f,g,h,i,j;if("inserted"===b.status){if(!b.previous_post_id)throw new Error("Expected previous_post_id");if(!b.post_id)throw new Error("Expected post_id");if(c="nav_menu_item["+String(b.previous_post_id)+"]",!a.has(c))throw new Error("Expected setting to exist: "+c);if(f=a(c),!a.control.has(c))throw new Error("Expected control to exist: "+c);if(i=a.control(c),h=f.get(),!h)throw new Error("Did not expect setting to be empty (deleted).");h=_.clone(h),d[h.nav_menu_term_id]&&(h.nav_menu_term_id=d[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=new a.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},previe