Wordpress/wp-admin/js/nav-menu.js

1 line
18 KiB
JavaScript
Raw Normal View History

var wpNavMenu;(function($){var api=wpNavMenu={options:{menuItemDepthPerLevel:30,globalMaxDepth:11},menuList:undefined,targetList:undefined,menusChanged:false,isRTL:!!("undefined"!=typeof isRtl&&isRtl),init:function(){api.menuList=$("#menu-to-edit");api.targetList=api.menuList;this.jQueryExtensions();this.attachMenuEditListeners();this.setupInputWithDefaultTitle();this.attachQuickSearchListeners();this.attachThemeLocationsListeners();this.attachTabsPanelListeners();this.attachUnsavedChangesListener();if(api.menuList.length){this.initSortables()}this.initToggles();this.initTabManager()},jQueryExtensions:function(){$.fn.extend({menuItemDepth:function(){var margin=api.isRTL?this.eq(0).css("margin-right"):this.eq(0).css("margin-left");return api.pxToDepth(margin&&-1!=margin.indexOf("px")?margin.slice(0,-2):0)},updateDepthClass:function(current,prev){return this.each(function(){var t=$(this);prev=prev||t.menuItemDepth();$(this).removeClass("menu-item-depth-"+prev).addClass("menu-item-depth-"+current)})},shiftDepthClass:function(change){return this.each(function(){var t=$(this),depth=t.menuItemDepth();$(this).removeClass("menu-item-depth-"+depth).addClass("menu-item-depth-"+(depth+change))})},childMenuItems:function(){var result=$();this.each(function(){var t=$(this),depth=t.menuItemDepth(),next=t.next();while(next.length&&next.menuItemDepth()>depth){result=result.add(next);next=next.next()}});return result},updateParentMenuItemDBId:function(){return this.each(function(){var item=$(this),input=item.find(".menu-item-data-parent-id"),depth=item.menuItemDepth(),parent=item.prev();if(depth==0){input.val(0)}else{while(!parent[0]||!parent[0].className||-1==parent[0].className.indexOf("menu-item")||(parent.menuItemDepth()!=depth-1)){parent=parent.prev()}input.val(parent.find(".menu-item-data-db-id").val())}})},hideAdvancedMenuItemFields:function(){return this.each(function(){var that=$(this);$(".hide-column-tog").not(":checked").each(function(){that.find(".field-"+$(this).val()).addClass("hidden-field")})})},addSelectedToMenu:function(processMethod){if(0==$("#menu-to-edit").length){return false}return this.each(function(){var t=$(this),menuItems={},checkboxes=t.find(".tabs-panel-active .categorychecklist li input:checked"),re=new RegExp("menu-item\\[([^\\]]*)");processMethod=processMethod||api.addMenuItemToBottom;if(!checkboxes.length){return false}t.find("img.waiting").show();$(checkboxes).each(function(){var t=$(this),listItemDBIDMatch=re.exec(t.attr("name")),listItemDBID="undefined"==typeof listItemDBIDMatch[1]?0:parseInt(listItemDBIDMatch[1],10);if(this.className&&-1!=this.className.indexOf("add-to-top")){processMethod=api.addMenuItemToTop}menuItems[listItemDBID]=t.closest("li").getItemData("add-menu-item",listItemDBID)});api.addItemToMenu(menuItems,processMethod,function(){checkboxes.removeAttr("checked");t.find("img.waiting").hide()})})},getItemData:function(itemType,id){itemType=itemType||"menu-item";var itemData={},i,fields=["menu-item-db-id","menu-item-object-id","menu-item-object","menu-item-parent-id","menu-item-position","menu-item-type","menu-item-title","menu-item-url","menu-item-description","menu-item-attr-title","menu-item-target","menu-item-classes","menu-item-xfn"];if(!id&&itemType=="menu-item"){id=this.find(".menu-item-data-db-id").val()}if(!id){return itemData}this.find("input").each(function(){var field;i=fields.length;while(i--){if(itemType=="menu-item"){field=fields[i]+"["+id+"]"}else{if(itemType=="add-menu-item"){field="menu-item["+id+"]["+fields[i]+"]"}}if(this.name&&field==this.name){itemData[fields[i]]=this.value}}});return itemData},setItemData:function(itemData,itemType,id){itemType=itemType||"menu-item";if(!id&&itemType=="menu-item"){id=$(".menu-item-data-db-id",this).val()}if(!id){return this}this.find("input").each(function(){var t=$(this),field;$.each(itemData,function(attr,val){if(itemType=="menu-item"){field=attr+"["+id+"]"}else{if(itemType=="add-menu-item"){field="menu-item["+id+"]["+attr+"]"}}if(field==t.attr("name")){t.val(val)}})});return this}})},initToggles:function(){postboxes.add_postbox_to