WordPress.org

Make WordPress Core

Changeset 14283


Ignore:
Timestamp:
04/28/10 18:30:32 (5 years ago)
Author:
nacin
Message:

More nav menu fixes. props filosofo. see #13148. fixes #13155, fixes #13157, fixes #13138, see #13134.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/nav-menu.php

    r14271 r14283  
    306306    $post_types = get_post_types( array( 'public' => true ), 'object' ); 
    307307 
    308     if ( !$post_types ) 
     308    if ( ! $post_types ) 
    309309        return; 
    310310 
    311311    foreach ( $post_types as $post_type ) { 
    312         $id = $post_type->name; 
    313         add_meta_box( "add-{$id}", $post_type->label, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type ); 
     312        $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); 
     313        if ( $post_type ) { 
     314            $id = $post_type->name; 
     315            add_meta_box( "add-{$id}", $post_type->label, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type ); 
     316        } 
    314317    } 
    315318} 
     
    327330 
    328331    foreach ( $taxonomies as $tax ) { 
    329         $id = $tax->name; 
    330         add_meta_box( "add-{$id}", $tax->label, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); 
     332        $tax = apply_filters( 'nav_menu_meta_box_object', $tax ); 
     333        if ( $tax ) { 
     334            $id = $tax->name; 
     335            add_meta_box( "add-{$id}", $tax->label, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); 
     336        } 
    331337    } 
    332338} 
     
    338344 */ 
    339345function wp_nav_menu_item_link_meta_box() { 
    340     static $_placeholder; 
    341     $_placeholder = 0 > $_placeholder ? $_placeholder - 1 : -1; 
     346    global $_nav_menu_placeholder; 
     347    $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; 
    342348 
    343349    // @note: hacky query, see #12660 
     
    365371        <ul id="customlink-tabs" class="customlink-tabs add-menu-item-tabs"> 
    366372            <li <?php echo ( 'create' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg('customlink-tab', 'create', remove_query_arg($removed_args)); ?>#tabs-panel-create-custom"><?php _e('Create New'); ?></a></li> 
    367             <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg('customlink-tab', 'all', remove_query_arg($removed_args)); ?>#tabs-panel-all-custom"><?php _e('View All'); ?></a></li> 
    368373        </ul> 
    369374 
     
    371376            echo ( 'create' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 
    372377        ?>" id="tabs-panel-create-custom"> 
    373             <input type="hidden" value="custom" name="menu-item[<?php echo $_placeholder; ?>][menu-item-type]" /> 
     378            <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" /> 
    374379            <p id="menu-item-url-wrap"> 
    375380                <label class="howto" for="custom-menu-item-url"> 
    376381                    <span><?php _e('URL'); ?></span> 
    377                     <input id="custom-menu-item-url" name="menu-item[<?php echo $_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" /> 
     382                    <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" /> 
    378383                </label> 
    379384            </p> 
     
    382387                <label class="howto" for="custom-menu-item-name"> 
    383388                    <span><?php _e('Text'); ?></span> 
    384                     <input id="custom-menu-item-name" name="menu-item[<?php echo $_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox" value="<?php echo esc_attr( __('Menu Item') ); ?>" /> 
     389                    <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox" value="<?php echo esc_attr( __('Menu Item') ); ?>" /> 
    385390                </label> 
    386391            </p> 
    387         </div><!-- /.tabs-panel --> 
    388  
    389         <div class="tabs-panel <?php  
    390             echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 
    391         ?>" id="tabs-panel-all-custom"> 
    392             <ul id="customlinkchecklist" class="list:customlink customlinkchecklist form-no-clear"> 
    393                 <?php 
    394                 $args['walker'] = new Walker_Nav_Menu_Checklist; 
    395                 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $links), 0, (object) $args ); 
    396                 ?> 
    397             </ul> 
    398392        </div><!-- /.tabs-panel --> 
    399393 
     
    433427        'suppress_filters' => true,  
    434428    ); 
     429 
     430    if ( isset( $post_type['args']->_default_query ) ) 
     431        $args = array_merge($args, (array) $post_type['args']->_default_query ); 
    435432 
    436433    // @todo transient caching of these results with proper invalidation on updating of a post of this type 
     
    811808 
    812809/** 
     810 * Adds custom arguments to some of the meta box object types. 
     811 * 
     812 * @since 3.0.0 
     813 *  
     814 * @access private 
     815 * 
     816 * @param object $object The post type or taxonomy meta-object. 
     817 * @return object The post type of taxonomy object. 
     818 */ 
     819function _wp_nav_menu_meta_box_object( $object = null ) { 
     820    if ( isset( $object->name ) ) { 
     821        // don't show media meta box 
     822        if ( 'attachment' == $object->name ) 
     823            return false; 
     824     
     825        // pages should show most recent 
     826        if ( 'page' == $object->name ) { 
     827            $object->_default_query = array( 
     828                'orderby' => 'post_date', 
     829                'order' => 'DESC', 
     830                'post_status' => 'publish', 
     831            ); 
     832 
     833        // posts should show only published items 
     834        } elseif ( 'post' == $object->name ) { 
     835            $object->_default_query = array( 
     836                'post_status' => 'publish', 
     837            ); 
     838 
     839        // cats should be in reverse chronological order 
     840        } elseif ( 'category' == $object->name ) { 
     841            $object->_default_query = array( 
     842                'orderby' => 'id', 
     843                'order' => 'DESC', 
     844            ); 
     845        } 
     846    } 
     847     
     848    return $object; 
     849} 
     850 
     851/** 
    813852 * Returns the menu item formatted to edit. 
    814853 * 
     
    819858 */ 
    820859function wp_get_nav_menu_to_edit( $menu_item_id = 0 ) { 
    821     static $_placeholder; 
    822      
    823860    $menu = wp_get_nav_menu_object( $menu_item_id ); 
    824861     
  • trunk/wp-admin/js/nav-menu.dev.js

    r14267 r14283  
    160160            return; 
    161161 
    162         var menuListItems = list.getElementsByTagName('li'), 
     162        var dummyListItem = document.getElementById(list.id + '-dummy-list-item'), 
     163        menuListItems = list.getElementsByTagName('li'), 
    163164        i = menuListItems.length; 
     165 
     166        if ( ! dummyListItem ) { 
     167            dummyListItem = document.createElement('li'); 
     168            dummyListItem.id = list.id + '-dummy-list-item'; 
     169            list.appendChild(dummyListItem); 
     170            this.setupListItemDragAndDrop(dummyListItem); 
     171        } 
    164172         
    165173        while ( i-- ) 
     
    235243            $('#menu-settings-column').bind('click', function(e) { 
    236244                if ( e.target && e.target.className && -1 != e.target.className.indexOf('menu-tab-link') ) { 
    237                     var i = e.target.parentNode, 
    238                     activePanel, 
     245                    var activePanel, 
    239246                    panelIdMatch = /#(.*)$/.exec(e.target.href), 
    240                     tabPanels; 
    241                     while ( ! i.className || -1 == i.className.indexOf('inside') ) { 
    242                         i = i.parentNode; 
    243                     } 
    244                     $('.tabs-panel', i).each(function() { 
     247                    tabPanels, 
     248                    wrapper = getParentWrapper(e.target, 'inside'), 
     249                    inputs = wrapper ? wrapper.getElementsByTagName('input') : [], 
     250                    i = inputs.length; 
     251 
     252                    // upon changing tabs, we want to uncheck all checkboxes 
     253                    while( i-- )  
     254                        inputs[i].checked = false; 
     255 
     256                    $('.tabs-panel', wrapper).each(function() { 
    245257                        if ( this.className ) 
    246258                            this.className = this.className.replace('tabs-panel-active', 'tabs-panel-inactive'); 
    247259                    }); 
    248260 
    249                     $('.tabs', i).each(function() { 
     261                    $('.tabs', wrapper).each(function() { 
    250262                        this.className = this.className.replace('tabs', ''); 
    251263                    }); 
     
    397409                        that.className = that.className.replace(/sortable-placeholder/g, ''); 
    398410                    } 
    399                 }, 500); 
     411                }, 800); 
    400412            })(dropEl); 
    401413        }, 
     
    564576                req = {}; 
    565577            var dropZone, 
     578            dummyListItem = document.getElementById(menuList.id + '-dummy-list-item'), 
    566579            i, 
    567580            listElements, 
     
    573586            while ( i-- ) { 
    574587                this.setupListItemDragAndDrop(listElements[i]); 
    575                 menuList.appendChild(listElements[i]); 
    576             } 
     588                if ( dummyListItem ) 
     589                    menuList.insertBefore(listElements[i], dummyListItem); 
     590                else 
     591                    menuList.appendChild(listElements[i]); 
     592            } 
     593 
     594            this.recalculateSortOrder(menuList); 
    577595 
    578596            /* set custom link form back to defaults */ 
  • trunk/wp-admin/js/nav-menu.js

    r14248 r14283  
    1 var WPNavMenuHandler=function(){var h=jQuery,a=false,j=null,g,d,m,i,l={},n=function(p,t,q,s){if(p&&p[0]){var r=h.parseJSON(p[0]);if(r.post_title){if(r.ID&&r.post_type){l[r.post_title]={ID:r.ID,object_type:r.post_type}}return r.post_title}}},o=function(p,t,q,s){if(p&&p[0]){var r=h.parseJSON(p[0]);if(r.post_title){return r.post_title}}},b=function(v,u){if(!v){return false}u=u||document;var q=["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"],p={},r=u.getElementsByTagName("input"),t=r.length,s,w=document.getElementById("nav-menu-meta-object-id").value;while(t--){s=q.length;while(s--){if(r[t]&&r[t].name&&"menu-item["+v+"]["+q[s]+"]"==r[t].name){p[q[s]]=r[t].value}}}return p},c=function(){var t=this.getElementsByTagName("input"),q=t.length,p,s,r;while(q--){if(-1!=t[q].name.indexOf("menu-item-parent-id["+parseInt(this.id.replace("menu-item-",""),10)+"]")){if(!this.parentNode.className||-1==this.parentNode.className.indexOf("sub-menu")){t[q].value=0}else{if("LI"==this.parentNode.parentNode.nodeName&&-1!=this.parentNode.parentNode.id.indexOf("menu-item-")){s=this.parentNode.parentNode;r=s.getElementsByTagName("input");p=r.length;while(p--){if(r[p].name&&-1!=r[p].name.indexOf("menu-item-object-id["+parseInt(s.id.replace("menu-item-",""),10)+"]")){t[q].value=parseInt(r[p].value,10);break}}}}break}}},e=function(p){var q=this;h(p).droppable({accept:".menu li",tolerance:"pointer",drop:function(s,r){q.eventOnDrop(r.draggable[0],this,r,s)},over:function(s,r){q.eventOnDragOver(r.draggable[0],this,r,s)},out:function(s,r){q.eventOnDragOut(r.draggable[0],this,r,s)}})},k,f=function(r){if(!r){return}var p=r.getElementsByTagName("li"),q=p.length;while(q--){this.setupListItemDragAndDrop(p[q])}};return{init:function(){k=document.getElementById("menu-to-edit");this.attachMenuEditListeners();this.attachMenuMetaListeners(document.getElementById("nav-menu-meta"));this.attachTabsPanelListeners();f.call(this,k);postboxes.add_postbox_toggles("nav-menus")},attachMenuEditListeners:function(){var p=this;h("#update-nav-menu").bind("click",function(q){if(q.target&&q.target.className){if(-1!=q.target.className.indexOf("item-edit")){return p.eventOnClickEditLink(q.target)}else{if(-1!=q.target.className.indexOf("menu-delete")){return p.eventOnClickMenuDelete(q.target)}else{if(-1!=q.target.className.indexOf("item-delete")){return p.eventOnClickMenuItemDelete(q.target)}}}}})},attachMenuMetaListeners:function(p){if(!p){return}var q=this;g=document.getElementById("custom-menu-item-name");d=document.getElementById("custom-menu-item-url");if(g){m="undefined"!=typeof g.defaultValue?g.defaultValue:g.getAttribute("value");i="undefined"!=typeof d.defaultValue?d.defaultValue:d.getAttribute("value");h(g).bind("focus",function(r){this.value=m==this.value?"":this.value});h(g).bind("blur",function(r){this.value=""==this.value?m:this.value})}h("input.quick-search").each(function(r,s){q.setupQuickSearchEventListeners(s)});h(p).bind("submit",function(r){return q.eventSubmitMetaForm.call(q,this,r)})},attachTabsPanelListeners:function(){h("#menu-settings-column").bind("click",function(t){if(t.target&&t.target.className&&-1!=t.target.className.indexOf("menu-tab-link")){var q=t.target.parentNode,u,p=/#(.*)$/.exec(t.target.href),s;while(!q.className||-1==q.className.indexOf("inside")){q=q.parentNode}h(".tabs-panel",q).each(function(){if(this.className){this.className=this.className.replace("tabs-panel-active","tabs-panel-inactive")}});h(".tabs",q).each(function(){this.className=this.className.replace("tabs","")});t.target.parentNode.className+=" tabs";if(p&&p[1]){u=document.getElementById(p[1]);if(u){u.className=u.className.replace("tabs-panel-inactive","tabs-panel-active")}}return false}else{if(t.target&&t.target.className&&-1!=t.target.className.indexOf("select-all")){var r=/#(.*)$/.exec(t.target.href);if(r&&r[1]){h("#"+r[1]+" .tabs-panel-active input[type=checkbox]").attr("checked","checked");return false}}}})},setupListItemDragAndDrop:function(r){var p=r.getElementsByTagName("dl"),s=this.makeListItemDropzone(r),q=p.length;e.call(this,s);this.makeListItemDraggable(r);while(q--){e.call(this,p[q])}},setupQuickSearchEventListeners:function(p){var q=this;h(p).autocomplete(ajaxurl+"?action=menu-quick-search&type="+p.name,{delay:500,formatItem:n,formatResult:o,minchars:2,multiple:false}).bind("blur",function(t){var r=l[this.value],s=this;if(r){h.post(ajaxurl+"?action=menu-quick-search&type=get-post-item&response-format=markup",r,function(u){q.processQuickSearchQueryResponse.call(q,u,r);l[s.value]=false})}})},eventOnClickEditLink:function(p){var r,q=/#(.*)$/.exec(p.href);if(q&&q[1]){r=document.getElementById(q[1]);if(r){if(-1!=r.className.indexOf("menu-item-edit-inactive")){r.className=r.className.replace("menu-item-edit-inactive","menu-item-edit-active")}else{r.className=r.className.replace("menu-item-edit-active","menu-item-edit-inactive")}return false}}},eventOnClickMenuDelete:function(p){if(confirm(navMenuL10n.warnDeleteMenu)){return true}else{return false}},eventOnClickMenuItemDelete:function(p){var s,r,q=this;if(confirm(navMenuL10n.warnDeleteMenuItem)){r=/_wpnonce=([a-zA-Z0-9]*)$/.exec(p.href);if(r&&r[1]){s=parseInt(p.id.replace("delete-",""),10);h.post(ajaxurl,{action:"delete-menu-item","menu-item":s,_wpnonce:r[1]},function(t){if("1"==t){q.removeMenuItem(document.getElementById("menu-item-"+s))}});return false}return true}else{return false}},eventOnDragOver:function(p,q){a=true;j=q;q.className+=" sortable-placeholder"},eventOnDragOut:function(p,q){a=false;(function(r){setTimeout(function(){if(r!=j||(!a&&r.className&&-1!=r.className.indexOf("sortable-placeholder"))){r.className=r.className.replace(/sortable-placeholder/g,"")}},500)})(q)},eventOnDrop:function(s,v){var t=!!(-1==v.className.indexOf("dropzone")),q=v.parentNode.getElementsByTagName("ul"),u=false,r=q.length,p;a=false;v.className=v.className.replace(/sortable-placeholder/g,"");if(t){while(r--){if(q[r]&&1!=q[r].className.indexOf("sub-menu")){u=true;p=q[r]}}if(!u){p=document.createElement("ul");p.className="sub-menu";v.parentNode.appendChild(p)}p.appendChild(s)}else{v.parentNode.parentNode.insertBefore(s,v.parentNode)}this.recalculateSortOrder(k);c.call(s)},eventSubmitMetaForm:function(q,w){var u=q.getElementsByTagName("input"),t=u.length,s,y,p,v,r={},x=function(){},z=new RegExp("menu-item\\[([^\\]]*)");q.className=q.className+" processing",that=this;r.action="";while(t--){if(u[t].name&&-1!=u[t].name.indexOf("menu-item-object-id")&&u[t].checked||("undefined"!=typeof u[t].id&&"custom-menu-item-url"==u[t].id&&""!=u[t].value&&"http://"!=u[t].value)){r.action="add-menu-item";x=that.processAddMenuItemResponse;v=z.exec(u[t].name);p="undefined"==typeof v[1]?0:parseInt(v[1],10);y=b(p);for(s in y){r["menu-item["+p+"]["+s+"]"]=y[s]}u[t].checked=false}else{if(""==r.action&&""!=u[t].value&&u[t].className&&-1!=u[t].className.search(/quick-search\b[^-]/)){r.action="menu-quick-search";r.q=u[t].value;r["response-format"]="markup";r.type=u[t].name;x=that.processQuickSearchQueryResponse}}}r.menu=q.elements.menu.value;r["menu-settings-column-nonce"]=q.elements["menu-settings-column-nonce"].value;h.post(ajaxurl,r,function(A){x.call(that,A,r);q.className=q.className.replace(/processing/g,"")});return false},makeListItemDraggable:function(p){h(p).draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100})},makeListItemDropzone:function(r){if(!r){return false}var q=r.getElementsByTagName("div"),p=q.length,s=document.createElement("div");while(p--){if(q[p].className&&-1!=q[p].className.indexOf("dropzone")&&(r==q[p].parentNode)){return q[p]}}s.className="dropzone";r.insertBefore(s,r.firstChild);return s},processAddMenuItemResponse:function(p,t){if(!t){t={}}var u,r,q,s=document.createElement("ul");s.innerHTML=p;q=s.getElementsByTagName("li");r=q.length;while(r--){this.setupListItemDragAndDrop(q[r]);k.appendChild(q[r])}if(g&&d){g.value=m;d.value=i}},processQuickSearchQueryResponse:function(t,y){if(!y){y={}}var q=document.createElement("ul"),p=document.getElementById("nav-menu-meta"),u,x,r,v,w=new RegExp("menu-item\\[([^\\]]*)"),s;r=w.exec(t);if(r&&r[1]){v=r[1];while(p.elements["menu-item["+v+"][menu-item-type]"]){v--}if(v!=r[1]){t=t.replace(new RegExp("menu-item\\["+r[1]+"\\]","g"),"menu-item["+v+"]")}}q.innerHTML=t;x=q.getElementsByTagName("li");if(x[0]&&y.object_type){s=document.getElementById(y.object_type+"-search-checklist");if(s){s.appendChild(x[0])}}else{if(y.type){r=/quick-search-posttype-([a-zA-Z_-]*)/.exec(y.type);if(r&&r[1]){s=document.getElementById(r[1]+"-search-checklist");if(s){u=x.length;while(u--){s.appendChild(x[u])}}}}}},recalculateSortOrder:function(r){var s=r.getElementsByTagName("input"),q,p=0;for(q=0;q<s.length;q++){if(s[q].name&&-1!=s[q].name.indexOf("menu-item-position")){s[q].value=++p}}},removeMenuItem:function(r){if(!r){return false}var s=r.getElementsByTagName("ul"),q,p;if(s[0]){q=s[0].getElementsByTagName("li");for(p=0;p<q.length;p++){if(q[p].id&&-1!=q[p].id.indexOf("menu-item-")&&q[p].parentNode==s[0]){r.parentNode.insertBefore(q[p],r)}}}r.className+=" deleting";h(r).fadeOut(350,function(){this.parentNode.removeChild(this)});this.recalculateSortOrder(k)}}};var wpNavMenu=new WPNavMenuHandler();jQuery(function(){wpNavMenu.init()}); 
     1var 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.target.parentNode.className+=" tabs";if(r&&r[1]){w=document.getElementById(r[1]);if(w){w.className=w.className.replace("tabs-panel-inactive","tabs-panel-active")}}return false}else{if(v.target&&v.target.className&&-1!=v.target.className.indexOf("select-all")){var t=/#(.*)$/.exec(v.target.href);if(t&&t[1]){i("#"+t[1]+" .tabs-panel-active input[type=checkbox]").attr("checked","checked");return false}}}})},setupListItemDragAndDrop:function(s){var q=s.getElementsByTagName("dl"),t=this.makeListItemDropzone(s),r=q.length;f.call(this,t);this.makeListItemDraggable(s);while(r--){f.call(this,q[r])}},setupQuickSearchEventListeners:function(q){var r=this;i(q).autocomplete(ajaxurl+"?action=menu-quick-search&type="+q.name,{delay:500,formatItem:o,formatResult:p,minchars:2,multiple:false}).bind("blur",function(u){var s=m[this.value],t=this;if(s){i.post(ajaxurl+"?action=menu-quick-search&type=get-post-item&response-format=markup",s,function(v){r.processQuickSearchQueryResponse.call(r,v,s);m[t.value]=false})}})},eventOnClickEditLink:function(q){var s,r=/#(.*)$/.exec(q.href);if(r&&r[1]){s=document.getElementById(r[1]);if(s){if(-1!=s.className.indexOf("menu-item-edit-inactive")){s.className=s.className.replace("menu-item-edit-inactive","menu-item-edit-active")}else{s.className=s.className.replace("menu-item-edit-active","menu-item-edit-inactive")}return false}}},eventOnClickMenuDelete:function(q){if(confirm(navMenuL10n.warnDeleteMenu)){return true}else{return false}},eventOnClickMenuItemDelete:function(q){var t,s,r=this;if(confirm(navMenuL10n.warnDeleteMenuItem)){s=/_wpnonce=([a-zA-Z0-9]*)$/.exec(q.href);if(s&&s[1]){t=parseInt(q.id.replace("delete-",""),10);i.post(ajaxurl,{action:"delete-menu-item","menu-item":t,_wpnonce:s[1]},function(u){if("1"==u){r.removeMenuItem(document.getElementById("menu-item-"+t))}});return false}return true}else{return false}},eventOnDragOver:function(q,r){a=true;k=r;r.className+=" sortable-placeholder"},eventOnDragOut:function(q,r){a=false;(function(s){setTimeout(function(){if(s!=k||(!a&&s.className&&-1!=s.className.indexOf("sortable-placeholder"))){s.className=s.className.replace(/sortable-placeholder/g,"")}},800)})(r)},eventOnDrop:function(t,w){var u=!!(-1==w.className.indexOf("dropzone")),r=w.parentNode.getElementsByTagName("ul"),v=false,s=r.length,q;a=false;w.className=w.className.replace(/sortable-placeholder/g,"");if(u){while(s--){if(r[s]&&1!=r[s].className.indexOf("sub-menu")){v=true;q=r[s]}}if(!v){q=document.createElement("ul");q.className="sub-menu";w.parentNode.appendChild(q)}q.appendChild(t)}else{w.parentNode.parentNode.insertBefore(t,w.parentNode)}this.recalculateSortOrder(l);c.call(t)},eventSubmitMetaForm:function(r,y){var v,w=r.getElementsByTagName("input"),u=w.length,t,A,q,x,s={},z=function(){},B=new RegExp("menu-item\\[([^\\]]*)");that=this;s.action="";while(u--){if(w[u].name&&-1!=w[u].name.indexOf("menu-item-object-id")&&w[u].checked||("undefined"!=typeof w[u].id&&"custom-menu-item-url"==w[u].id&&""!=w[u].value&&"http://"!=w[u].value)){s.action="add-menu-item";z=that.processAddMenuItemResponse;x=B.exec(w[u].name);q="undefined"==typeof x[1]?0:parseInt(x[1],10);A=b(q);for(t in A){s["menu-item["+q+"]["+t+"]"]=A[t]}v=e(w[u],"inside");w[u].checked=false}else{if(""==s.action&&""!=w[u].value&&w[u].className&&-1!=w[u].className.search(/quick-search\b[^-]/)){v=e(w[u],"inside");s.action="menu-quick-search";s.q=w[u].value;s["response-format"]="markup";s.type=w[u].name;z=that.processQuickSearchQueryResponse}}}if(v){v.className=v.className+" processing",s.menu=r.elements.menu.value}s["menu-settings-column-nonce"]=r.elements["menu-settings-column-nonce"].value;i.post(ajaxurl,s,function(C){z.call(that,C,s);v.className=v.className.replace(/processing/g,"")});return false},makeListItemDraggable:function(q){i(q).draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100})},makeListItemDropzone:function(s){if(!s){return false}var r=s.getElementsByTagName("div"),q=r.length,t=document.createElement("div");while(q--){if(r[q].className&&-1!=r[q].className.indexOf("dropzone")&&(s==r[q].parentNode)){return r[q]}}t.className="dropzone";s.insertBefore(t,s.firstChild);return t},processAddMenuItemResponse:function(q,v){if(!v){v={}}var w,r=document.getElementById(l.id+"-dummy-list-item"),t,s,u=document.createElement("ul");u.innerHTML=q;s=u.getElementsByTagName("li");t=s.length;while(t--){this.setupListItemDragAndDrop(s[t]);if(r){l.insertBefore(s[t],r)}else{l.appendChild(s[t])}}this.recalculateSortOrder(l);if(h&&d){h.value=n;d.value=j}},processQuickSearchQueryResponse:function(u,z){if(!z){z={}}var r=document.createElement("ul"),q=document.getElementById("nav-menu-meta"),v,y,s,w,x=new RegExp("menu-item\\[([^\\]]*)"),t;s=x.exec(u);if(s&&s[1]){w=s[1];while(q.elements["menu-item["+w+"][menu-item-type]"]){w--}if(w!=s[1]){u=u.replace(new RegExp("menu-item\\["+s[1]+"\\]","g"),"menu-item["+w+"]")}}r.innerHTML=u;y=r.getElementsByTagName("li");if(y[0]&&z.object_type){t=document.getElementById(z.object_type+"-search-checklist");if(t){t.innerHTML="";t.appendChild(y[0])}}else{if(z.type){s=/quick-search-posttype-([a-zA-Z_-]*)/.exec(z.type);if(s&&s[1]){t=document.getElementById(s[1]+"-search-checklist");if(t){t.innerHTML="";v=y.length;while(v--){t.appendChild(y[v])}}}}}},recalculateSortOrder:function(s){var t=s.getElementsByTagName("input"),r,q=0;for(r=0;r<t.length;r++){if(t[r].name&&-1!=t[r].name.indexOf("menu-item-position")){t[r].value=++q}}},removeMenuItem:function(s){if(!s){return false}var t=s.getElementsByTagName("ul"),r,q;if(t[0]){r=t[0].getElementsByTagName("li");for(q=0;q<r.length;q++){if(r[q].id&&-1!=r[q].id.indexOf("menu-item-")&&r[q].parentNode==t[0]){s.parentNode.insertBefore(r[q],s)}}}s.className+=" deleting";i(s).fadeOut(350,function(){this.parentNode.removeChild(this)});this.recalculateSortOrder(l)}}};var wpNavMenu=new WPNavMenuHandler();jQuery(function(){wpNavMenu.init()}); 
  • trunk/wp-includes/default-filters.php

    r14056 r14283  
    170170add_filter( 'pings_open',           '_close_comments_for_old_post', 10, 2 ); 
    171171add_filter( 'editable_slug',        'urldecode'                           ); 
     172add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object'    ); 
    172173 
    173174// Atom SSL support 
  • trunk/wp-includes/nav-menu-template.php

    r14248 r14283  
    133133     */ 
    134134    function start_el(&$output, $item, $depth, $args) { 
    135         static $_placeholder; 
    136         $_placeholder = 0 > $_placeholder ? $_placeholder - 1 : -1; 
    137         $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_placeholder; 
     135        global $_nav_menu_placeholder; 
     136 
     137        $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; 
     138        $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; 
    138139        $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; 
     140        $possible_parent_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->post_parent : 0; 
    139141 
    140142        $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; 
     
    148150        $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; 
    149151        $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />'; 
    150         $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->post_parent ) .'" />'; 
     152        $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. $possible_parent_id .'" />'; 
    151153        $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />'; 
    152154        $output .= '<input type="hidden" class="menu-item-append" name="menu-item[' . $possible_object_id . '][menu-item-append]" value="'. esc_attr( $item->append ) .'" />'; 
  • trunk/wp-includes/nav-menu.php

    r14270 r14283  
    5151    $menu_obj = wp_get_nav_menu_object( $menu ); 
    5252 
    53     if ( $menu_obj && ! is_wp_error( $menu_obj ) && ! empty( $menu_obj->term_id ) )  
     53    if (  
     54        $menu_obj &&  
     55        ! is_wp_error( $menu_obj ) &&  
     56        ! empty( $menu_obj->taxonomy ) && 
     57        'nav_menu' == $menu_obj->taxonomy 
     58    )  
    5459        return true; 
    5560     
     
    144149 * @param int $menu_id The ID of the menu 
    145150 * @param array $menu_data The array of menu data. 
    146  * @return int The menu's ID. 
     151 * @return int|error object The menu's ID or WP_Error object. 
    147152 */ 
    148153function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) { 
     
    152157 
    153158    // menu doesn't already exist 
    154     if ( ! $_menu || is_wp_error( $_menu ) ) { 
     159    if ( ! $_menu || is_wp_error( $_menu ) ) 
    155160        $_menu = wp_create_nav_menu( $menu_data['menu-name'] ); 
    156     } 
    157  
    158     if ( $_menu && isset( $_menu->term_id ) && ! is_wp_error( $_menu ) ) { 
     161 
     162    if ( is_wp_error( $_menu ) ) 
     163        return $_menu; 
     164 
     165    if ( $_menu && isset( $_menu->term_id ) ) { 
    159166        $args = array(  
    160167            'description' => ( isset( $menu_data['description'] ) ? $menu_data['description'] : '' ),  
     
    168175        $update_response = wp_update_term( $menu_id, 'nav_menu', $args ); 
    169176 
    170         if ( ! is_wp_error( $update_response ) ) { 
     177        if ( ! is_wp_error( $update_response ) ) 
    171178            return $menu_id; 
    172         } 
     179        else 
     180            return $update_response; 
    173181    } else { 
    174182        return 0; 
     
    238246    } 
    239247     
     248    if ( 'custom' != $args['menu-item-type'] ) { 
     249        /* if non-custom menu item, then: 
     250            * use original object's URL 
     251            * blank default title to sync with original object's 
     252        */ 
     253 
     254        $args['menu-item-url'] = ''; 
     255 
     256        $original_title = ''; 
     257        if ( 'taxonomy' == $args['menu-item-type'] ) { 
     258            $original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' ); 
     259        } elseif ( 'post_type' == $args['menu-item-type'] ) { 
     260            $original_object = get_post( $args['menu-item-object-id'] ); 
     261            $original_title = $original_object->post_title; 
     262        } 
     263 
     264        if ( empty( $args['menu-item-title'] ) || $args['menu-item-title'] == $original_title ) { 
     265            $args['menu-item-title'] = ''; 
     266 
     267            // hack to get wp to create a post object when too many properties are empty 
     268            if ( empty( $args['menu-item-description'] ) ) { 
     269                $args['menu-item-description'] = ' '; 
     270            } 
     271        } 
     272    } 
     273 
    240274    // Populate the menu item object 
    241275    $post = array( 
     
    363397 
    364398        $items = get_posts( $args ); 
     399 
     400        if ( is_wp_error( $items ) || ! is_array( $items ) ) { 
     401            return false; 
     402        } 
     403 
     404        $items = array_map( 'wp_setup_nav_menu_item', $items ); 
    365405 
    366406        if ( ARRAY_A == $args['output'] ) { 
     
    411451                $menu_item->append = $object->singular_label; 
    412452                $menu_item->url = get_permalink( $menu_item->object_id ); 
     453             
     454                $original_object = get_post( $menu_item->object_id ); 
     455                $original_title = $original_object->post_title; 
     456                $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; 
    413457 
    414458            } elseif ( 'taxonomy' == $menu_item->type ) { 
     
    417461                $menu_item->url = get_term_link( (int) $menu_item->object_id, $menu_item->object ); 
    418462 
     463                $original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' ); 
     464                $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; 
     465 
    419466            } else { 
    420467                $menu_item->append = __('Custom'); 
     468                $menu_item->title = $menu_item->post_title; 
    421469                $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true ); 
    422470            } 
    423471             
    424             $menu_item->title = $menu_item->post_title; 
    425472            $menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true ); 
    426473 
  • trunk/wp-includes/script-loader.php

    r14279 r14283  
    394394 
    395395        // Custom Navigation 
    396         $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100426' ); 
     396        $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100428' ); 
    397397        $scripts->localize( 'nav-menu', 'navMenuL10n', array( 
    398398            'custom' => _x('Custom', 'menu nav item type'), 
Note: See TracChangeset for help on using the changeset viewer.