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 j=0,i,g,c,h,f=a.menuList.offset().left,k,e;a.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(s,r){var m,q,p,n,o;e=r.item.children(".menu-item-transport");i=(k)?0:r.item.menuItemDepth();d(r,i);p=(r.item.next()[0]==r.placeholder[0])?r.item.next():r.item;n=p.childMenuItems();e.append(n);l(r);m=e.outerHeight();m+=(m>0)?(r.placeholder.css("margin-top").slice(0,-2)*1):0;m+=r.helper.outerHeight();m-=2;r.placeholder.height(m);o=i;n.each(function(){var t=b(this).menuItemDepth();o=(t>o)?t:o});q=r.helper.find(".menu-item-handle").outerWidth();q+=a.depthToPx(o-i);q-=2;r.placeholder.width(q)},stop:function(p,o){var n,m=j-i;n=e.children().insertAfter(o.item);if(m!=0){o.item.updateDepthClass(j);n.shiftDepthClass(m)}o.item.updateParentMenuItemDBId();a.recalculateMenuItemPositions()},change:function(n,m){if(!m.placeholder.parent().hasClass("menu")){m.placeholder.appendTo(a.menuList)}l(m)},sort:function(n,m){var p=m.helper.offset(),o=a.pxToDepth(p.left-f);if(o>c||p.top<h){o=c}else{if(o<g){o=g}}if(o!=j){d(m,o)}}});function l(o){var n=o.placeholder.prev(),m=o.placeholder.next(),p;if(n[0]==o.item[0]){n=n.prev()}if(m[0]==o.item[0]){m=m.next()}h=(n.length)?n.offset().top+n.height():0;g=(m.length)?m.menuItemDepth():0;if(n.length){c=((p=n.menuItemDepth()+1)>a.options.globalMaxDepth)?a.options.globalMaxDepth:p}else{c=0}}function d(m,n){m.placeholder.updateDepthClass(n,j);j=n}},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)}