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

1 line
13 KiB
JavaScript
Raw Normal View History

var wpNavMenu;(function(b){var a=wpNavMenu={options:{menuItemDepthPerLevel:30,globalMaxDepth:11},menuList:undefined,targetList:undefined,autoCompleteData:{},init:function(){a.menuList=b("#menu-to-edit");a.targetList=a.menuList;this.jQueryExtensions();this.attachMenuEditListeners();this.setupInputWithDefaultTitle();this.attachAddMenuItemListeners();this.attachQuickSearchListeners();this.attachTabsPanelListeners();this.attachHomeLinkListener();if(a.menuList.length){this.initSortables()}this.initToggles();this.initTabManager();this.checkForEmptyMenu()},jQueryExtensions:function(){b.fn.extend({menuItemDepth:function(){return a.pxToDepth(this.eq(0).css("margin-left").slice(0,-2))},updateDepthClass:function(d,c){return this.each(function(){var e=b(this);c=c||e.menuItemDepth();b(this).removeClass("menu-item-depth-"+c).addClass("menu-item-depth-"+d)})},shiftDepthClass:function(c){return this.each(function(){var d=b(this),e=d.menuItemDepth();b(this).removeClass("menu-item-depth-"+e).addClass("menu-item-depth-"+(e+c))})},childMenuItems:function(){var c=b();this.each(function(){var d=b(this),f=d.menuItemDepth(),e=d.next();while(e.length&&e.menuItemDepth()>f){c=c.add(e);e=e.next()}});return c},updateParentMenuItemDBId:function(){return this.each(function(){var e=b(this),c=e.find(".menu-item-data-parent-id"),f=e.menuItemDepth(),d=e.prev();if(f==0){c.val(0)}else{while(d.menuItemDepth()!=f-1){d=d.prev()}c.val(d.find(".menu-item-data-db-id").val())}})},hideAdvancedMenuItemFields:function(){return this.each(function(){var c=b(this);b(".hide-column-tog").not(":checked").each(function(){c.find(".field-"+b(this).val()).addClass("hidden-field")})})},addSelectedToMenu:function(c){return this.each(function(){var e=b(this),d={},g=e.find(".tabs-panel-active .categorychecklist li input:checked"),f=new RegExp("menu-item\\[([^\\]]*)");c=c||a.addMenuItemToBottom;if(!g.length){return false}e.find("img.waiting").show();b(g).each(function(){var h=f.exec(b(this).attr("name")),i="undefined"==typeof h[1]?0:parseInt(h[1],10);d[i]=a.getListDataFromID(i)});a.addItemToMenu(d,c,function(){g.removeAttr("checked");e.find("img.waiting").hide()})})}})},initToggles:function(){postboxes.add_postbox_toggles("nav-menus");columns.useCheckboxesForHidden();columns.checked=function(c){b(".field-"+c).removeClass("hidden-field")};columns.unchecked=function(c){b(".field-"+c).addClass("hidden-field")};a.menuList.hideAdvancedMenuItemFields()},initSortables:function(){var i=0,h,g,c,f=a.menuList.offset().left,j,e;a.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(r,q){var l,p,o,m,n;e=q.item.children(".menu-item-transport");h=(j)?0:q.item.menuItemDepth();d(q,h);o=(q.item.next()[0]==q.placeholder[0])?q.item.next():q.item;m=o.childMenuItems();e.append(m);k(q);l=e.outerHeight();l+=(l>0)?(q.placeholder.css("margin-top").slice(0,-2)*1):0;l+=q.helper.outerHeight();l-=2;q.placeholder.height(l);n=h;m.each(function(){var s=b(this).menuItemDepth();n=(s>n)?s:n});p=q.helper.find(".menu-item-handle").outerWidth();p+=a.depthToPx(n-h);p-=2;q.placeholder.width(p)},stop:function(o,n){var m,l=i-h;m=e.children().insertAfter(n.item);if(l!=0){n.item.updateDepthClass(i);m.shiftDepthClass(l)}n.item.updateParentMenuItemDBId();a.recalculateMenuItemPositions()},change:function(m,l){if(!l.placeholder.parent().hasClass("menu")){l.placeholder.appendTo(a.menuList)}k(l)},sort:function(m,l){var n=a.pxToDepth(l.helper.offset().left-f);if(n<g){n=g}else{if(n>c){n=c}}if(n!=i){d(l,n)}}});function k(n){var m=n.placeholder.prev(),l=n.placeholder.next(),o;if(m[0]==n.item[0]){m=m.prev()}if(l[0]==n.item[0]){l=l.next()}g=(l.length)?l.menuItemDepth():0;if(m.length){c=((o=m.menuItemDepth()+1)>a.options.globalMaxDepth)?a.options.globalMaxDepth:o}else{c=0}}function d(l,m){l.placeholder.updateDepthClass(m,i);i=m}},attachMenuEditListeners:function(){var c=this;b("#update-nav-menu").bind("click",function(d){if(d.target&&d.target.className){if(-1!=d.target.className.indexOf("item-edit")){return c.eventOnClickEditLink(d.target)}else{if(-1!=d.target.className.indexOf("menu-delete")){r