2010-04-28 22:44:08 +02:00
|
|
|
var WPNavMenuHandler=function(){var i=jQuery,a=false,k=null,h,d,n,j,m={},o=function(q,u,r,t){if(q&&q[0]){var s=i.parseJSON(q[0]);if(s.post_title){if(s.ID&&s.post_type){m[s.post_title]={ID:s.ID,object_type:s.post_type}}return s.post_title}}},p=function(q,u,r,t){if(q&&q[0]){var s=i.parseJSON(q[0]);if(s.post_title){return s.post_title}}},b=function(w,v){if(!w){return false}v=v||document;var r=["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"],q={},s=v.getElementsByTagName("input"),u=s.length,t,x=document.getElementById("nav-menu-meta-object-id").value;while(u--){t=r.length;while(t--){if(s[u]&&s[u].name&&"menu-item["+w+"]["+r[t]+"]"==s[u].name){q[r[t]]=s[u].value}}}return q},c=function(){var u=this.getElementsByTagName("input"),r=u.length,q,t,s;while(r--){if(-1!=u[r].name.indexOf("menu-item-parent-id["+parseInt(this.id.replace("menu-item-",""),10)+"]")){if(!this.parentNode.className||-1==this.parentNode.className.indexOf("sub-menu")){u[r].value=0}else{if("LI"==this.parentNode.parentNode.nodeName&&-1!=this.parentNode.parentNode.id.indexOf("menu-item-")){t=this.parentNode.parentNode;s=t.getElementsByTagName("input");q=s.length;while(q--){if(s[q].name&&-1!=s[q].name.indexOf("menu-item-object-id["+parseInt(t.id.replace("menu-item-",""),10)+"]")){u[r].value=parseInt(s[q].value,10);break}}}}break}}},e=function(r,t){var s=document.getElementById("nav-menu-meta"),q;while(r.parentNode&&(!r.className||-1==r.className.indexOf(t))&&r.parentNode!=s){r=r.parentNode}return r},f=function(q){var r=this;i(q).droppable({accept:".menu li",tolerance:"pointer",drop:function(t,s){r.eventOnDrop(s.draggable[0],this,s,t)},over:function(t,s){r.eventOnDragOver(s.draggable[0],this,s,t)},out:function(t,s){r.eventOnDragOut(s.draggable[0],this,s,t)}})},l,g=function(t){if(!t){return}var r=document.getElementById(t.id+"-dummy-list-item"),q=t.getElementsByTagName("li"),s=q.length;if(!r){r=document.createElement("li");r.id=t.id+"-dummy-list-item";t.appendChild(r);this.setupListItemDragAndDrop(r)}while(s--){this.setupListItemDragAndDrop(q[s])}};return{init:function(){l=document.getElementById("menu-to-edit");this.attachMenuEditListeners();this.attachMenuMetaListeners(document.getElementById("nav-menu-meta"));this.attachTabsPanelListeners();g.call(this,l);postboxes.add_postbox_toggles("nav-menus")},attachMenuEditListeners:function(){var q=this;i("#update-nav-menu").bind("click",function(r){if(r.target&&r.target.className){if(-1!=r.target.className.indexOf("item-edit")){return q.eventOnClickEditLink(r.target)}else{if(-1!=r.target.className.indexOf("menu-delete")){return q.eventOnClickMenuDelete(r.target)}else{if(-1!=r.target.className.indexOf("item-delete")){return q.eventOnClickMenuItemDelete(r.target)}}}}})},attachMenuMetaListeners:function(q){if(!q){return}var r=this;h=document.getElementById("custom-menu-item-name");d=document.getElementById("custom-menu-item-url");if(h){n="undefined"!=typeof h.defaultValue?h.defaultValue:h.getAttribute("value");j="undefined"!=typeof d.defaultValue?d.defaultValue:d.getAttribute("value");i(h).bind("focus",function(s){this.value=n==this.value?"":this.value});i(h).bind("blur",function(s){this.value=""==this.value?n:this.value})}i("input.quick-search").each(function(s,t){r.setupQuickSearchEventListeners(t)});i(q).bind("submit",function(s){return r.eventSubmitMetaForm.call(r,this,s)})},attachTabsPanelListeners:function(){i("#menu-settings-column").bind("click",function(v){if(v.target&&v.target.className&&-1!=v.target.className.indexOf("menu-tab-link")){var w,r=/#(.*)$/.exec(v.target.href),u,x=e(v.target,"inside"),q=x?x.getElementsByTagName("input"):[],s=q.length;while(s--){q[s].checked=false}i(".tabs-panel",x).each(function(){if(this.className){this.className=this.className.replace("tabs-panel-active","tabs-panel-inactive")}});i(".tabs",x).each(function(){this.className=this.className.replace("tabs","")});v.t
|