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

1 line
11 KiB
JavaScript
Raw Normal View History

var WPNavMenuHandler=function(d){var h={},f=30,c=11,j=function(l,p,m,o){if(l&&l[0]){var n=d.parseJSON(l[0]);if(n.post_title){if(n.ID&&n.post_type){h[n.post_title]={ID:n.ID,object_type:n.post_type}}return n.post_title}}},k=function(l,p,m,o){if(l&&l[0]){var n=d.parseJSON(l[0]);if(n.post_title){return n.post_title}}},b=function(r,q){if(!r){return false}q=q||document;var m=["menu-item-db-id","menu-item-object-id","menu-item-object","menu-item-parent-id","menu-item-position","menu-item-type","menu-item-append","menu-item-title","menu-item-url","menu-item-description","menu-item-attr-title","menu-item-target","menu-item-classes","menu-item-xfn"],l={},n=q.getElementsByTagName("input"),p=n.length,o,s=document.getElementById("nav-menu-meta-object-id").value;while(p--){o=m.length;while(o--){if(n[p]&&n[p].name&&"menu-item["+r+"]["+m[o]+"]"==n[p].name){l[m[o]]=n[p].value}}}return l},a=function(){g.find(".menu-item-data-position").val(function(l){return l+1})},e=function(l){return l*f},i=function(l){return Math.floor(l/f)},g;d.fn.extend({menuItemDepth:function(){return i(this.eq(0).css("margin-left").slice(0,-2))},updateDepthClass:function(m,l){return this.each(function(){var n=d(this);l=l||n.menuItemDepth();d(this).removeClass("menu-item-depth-"+l).addClass("menu-item-depth-"+m)})},shiftDepthClass:function(l){return this.each(function(){var m=d(this),n=m.menuItemDepth();d(this).removeClass("menu-item-depth-"+n).addClass("menu-item-depth-"+(n+l))})},childMenuItems:function(){var l=d();this.each(function(){var m=d(this),o=m.menuItemDepth(),n=m.next();while(n.length&&n.menuItemDepth()>o){l=l.add(n);n=n.next()}});return l},updateParentMenuItemDBId:function(){return this.each(function(){var n=d(this),l=n.find(".menu-item-data-parent-id"),o=n.menuItemDepth(),m=n.prev();if(o==0){l.val(0)}else{while(m.menuItemDepth()!=o-1){m=m.prev()}l.val(m.find(".menu-item-data-object-id").val())}})},hideAdvancedMenuItemFields:function(){return this.each(function(){var l=d(this);d(".hide-column-tog").not(":checked").each(function(){l.find(".field-"+d(this).val()).addClass("hidden-field")})})},});return{init:function(){g=d("#menu-to-edit");this.attachMenuEditListeners();this.attachMenuMetaListeners(document.getElementById("nav-menu-meta"));this.attachTabsPanelListeners();if(g.length){this.initSortables()}this.initToggles();this.initTabManager()},initToggles:function(){postboxes.add_postbox_toggles("nav-menus");columns.useCheckboxesForHidden();columns.checked=function(l){d(".field-"+l).removeClass("hidden-field")};columns.unchecked=function(l){d(".field-"+l).addClass("hidden-field")};g.hideAdvancedMenuItemFields()},initSortables:function(){var o=0,m,p,r,n=g.offset().left;g.sortable({handle:" > dl",placeholder:"sortable-placeholder",start:function(w,x){var v,z,s,y,t,A,u=x.item.children(".menu-item-transport");m=x.item.menuItemDepth();l(x,m);y=(x.item.next()[0]==x.placeholder[0])?x.item.next():x.item;t=y.childMenuItems();u.append(t);q(x);z=u.outerHeight();z+=(z>0)?(x.placeholder.css("margin-top").slice(0,-2)*1):0;z+=x.item.outerHeight();z-=2;x.placeholder.height(z);A=m;t.each(function(){var B=d(this).menuItemDepth();A=(B>A)?B:A});s=x.item.find("dl dt").outerWidth();s+=e(A-m);s-=2;x.placeholder.width(s)},stop:function(v,u){var t,s=o-m;t=u.item.children(".menu-item-transport").children().insertAfter(u.item);if(s!=0){u.item.updateDepthClass(o);t.shiftDepthClass(s)}u.item.updateParentMenuItemDBId();a()},change:function(t,s){if(!s.placeholder.parent().hasClass("menu")){s.placeholder.appendTo(g)}q(s)},sort:function(t,s){var u=i(s.item.offset().left-n);if(u<p){u=p}else{if(u>r){u=r}}if(u!=o){l(s,u)}}});function q(u){var t=u.placeholder.prev(),s=u.placeholder.next(),v;if(t[0]==u.item[0]){t=t.prev()}if(s[0]==u.item[0]){s=s.next()}p=(s.length)?s.menuItemDepth():0;if(t.length){r=((v=t.menuItemDepth()+1)>c)?c:v}else{r=0}}function l(s,t){s.placeholder.updateDepthClass(t,o);o=t}},attachMenuEditListeners:function(){var l=this;d("#update-nav-menu").bind("click",function(m){if(m.target&&m.target.className){if(-1!=m.target.className.indexOf("item-edit")){return l.eventOnClickE