Some menus meta box cleanups. props filosofo, see #13143.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-04-28 04:09:00 +00:00
parent 4374cee7cd
commit b8b7d95dd0
3 changed files with 39 additions and 9 deletions

View File

@ -87,7 +87,7 @@
float: right; float: right;
} }
form.processing .add-to-menu { .processing .add-to-menu {
background: url("../images/wpspin_light.gif") no-repeat top center; background: url("../images/wpspin_light.gif") no-repeat top center;
display:block; display:block;
height:20px; height:20px;

View File

@ -260,7 +260,7 @@ function _wp_ajax_menu_quick_search( $request = array() ) {
* @since 3.0.0 * @since 3.0.0
**/ **/
function wp_nav_menu_meta_boxes_setup() { function wp_nav_menu_meta_boxes_setup() {
add_meta_box( 'add-custom-links', __('Add Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); add_meta_box( 'add-custom-links', __('Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
wp_nav_menu_post_type_meta_boxes(); wp_nav_menu_post_type_meta_boxes();
wp_nav_menu_taxonomy_meta_boxes(); wp_nav_menu_taxonomy_meta_boxes();
} }
@ -310,7 +310,7 @@ function wp_nav_menu_post_type_meta_boxes() {
foreach ( $post_types as $post_type ) { foreach ( $post_types as $post_type ) {
$id = $post_type->name; $id = $post_type->name;
add_meta_box( "add-{$id}", sprintf( __('Add %s'), $post_type->label ), 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type ); add_meta_box( "add-{$id}", $post_type->label, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type );
} }
} }
@ -327,7 +327,7 @@ function wp_nav_menu_taxonomy_meta_boxes() {
foreach ( $taxonomies as $tax ) { foreach ( $taxonomies as $tax ) {
$id = $tax->name; $id = $tax->name;
add_meta_box( "add-{$id}", sprintf( __('Add %s'), $tax->label ), 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); add_meta_box( "add-{$id}", $tax->label, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );
} }
} }
@ -486,7 +486,7 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
if ( !$posts ) if ( !$posts )
$error = '<li id="error">'. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'</li>'; $error = '<li id="error">'. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'</li>';
$current_tab = 'search'; $current_tab = 'all';
if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) { if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) {
$current_tab = $_REQUEST[$post_type_name . '-tab']; $current_tab = $_REQUEST[$post_type_name . '-tab'];
} }
@ -507,8 +507,8 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
?> ?>
<div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv"> <div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
<ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs"> <ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args)); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search"><?php _e('Search'); ?></a></li>
<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args)); ?>#<?php echo $post_type_name; ?>-all"><?php _e('View All'); ?></a></li> <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args)); ?>#<?php echo $post_type_name; ?>-all"><?php _e('View All'); ?></a></li>
<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="menu-tab-link" href="<?php echo add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args)); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search"><?php _e('Search'); ?></a></li>
</ul> </ul>
<div class="tabs-panel <?php <div class="tabs-panel <?php

View File

@ -111,6 +111,28 @@ var WPNavMenuHandler = function () {
} }
}, },
/**
* Get the parent element with the matching class, but go no higher than the form.
*
* @param DOM-element el The descendant element up from which we'll be searching
* @param string parentClass The class name of the desired parent element.
* @return DOM-element The parent element.
*/
getParentWrapper = function( el, parentClass ) {
var form = document.getElementById('nav-menu-meta'),
i;
while (
el.parentNode &&
( ! el.className || -1 == el.className.indexOf(parentClass) ) &&
el.parentNode != form
) {
el = el.parentNode;
}
return el;
},
makeDroppable = function(el) { makeDroppable = function(el) {
var that = this; var that = this;
@ -426,7 +448,8 @@ var WPNavMenuHandler = function () {
* @param object e The event object. * @param object e The event object.
*/ */
eventSubmitMetaForm : function(thisForm, e) { eventSubmitMetaForm : function(thisForm, e) {
var inputs = thisForm.getElementsByTagName('input'), var ancestor,
inputs = thisForm.getElementsByTagName('input'),
i = inputs.length, i = inputs.length,
j, j,
listItemData, listItemData,
@ -436,7 +459,6 @@ var WPNavMenuHandler = function () {
processMethod = function(){}, processMethod = function(){},
re = new RegExp('menu-item\\[(\[^\\]\]*)'); re = new RegExp('menu-item\\[(\[^\\]\]*)');
thisForm.className = thisForm.className + ' processing',
that = this; that = this;
params['action'] = ''; params['action'] = '';
@ -464,6 +486,7 @@ var WPNavMenuHandler = function () {
params['menu-item[' + listItemDBID + '][' + j + ']'] = listItemData[j]; params['menu-item[' + listItemDBID + '][' + j + ']'] = listItemData[j];
} }
ancestor = getParentWrapper(inputs[i], 'inside');
inputs[i].checked = false; inputs[i].checked = false;
// we're submitting a search term // we're submitting a search term
@ -473,6 +496,7 @@ var WPNavMenuHandler = function () {
inputs[i].className && inputs[i].className &&
-1 != inputs[i].className.search(/quick-search\b[^-]/) -1 != inputs[i].className.search(/quick-search\b[^-]/)
) { ) {
ancestor = getParentWrapper(inputs[i], 'inside');
params['action'] = 'menu-quick-search'; params['action'] = 'menu-quick-search';
params['q'] = inputs[i].value; params['q'] = inputs[i].value;
params['response-format'] = 'markup'; params['response-format'] = 'markup';
@ -480,12 +504,16 @@ var WPNavMenuHandler = function () {
processMethod = that.processQuickSearchQueryResponse; processMethod = that.processQuickSearchQueryResponse;
} }
} }
if ( ancestor )
ancestor.className = ancestor.className + ' processing',
params['menu'] = thisForm.elements['menu'].value; params['menu'] = thisForm.elements['menu'].value;
params['menu-settings-column-nonce'] = thisForm.elements['menu-settings-column-nonce'].value; params['menu-settings-column-nonce'] = thisForm.elements['menu-settings-column-nonce'].value;
$.post( ajaxurl, params, function(menuMarkup) { $.post( ajaxurl, params, function(menuMarkup) {
processMethod.call(that, menuMarkup, params); processMethod.call(that, menuMarkup, params);
thisForm.className = thisForm.className.replace(/processing/g, ''); ancestor.className = ancestor.className.replace(/processing/g, '');
}); });
return false; return false;
@ -592,6 +620,7 @@ var WPNavMenuHandler = function () {
if ( items[0] && req.object_type ) { if ( items[0] && req.object_type ) {
resultList = document.getElementById(req.object_type + '-search-checklist'); resultList = document.getElementById(req.object_type + '-search-checklist');
if ( resultList ) { if ( resultList ) {
resultList.innerHTML = '';
resultList.appendChild(items[0]); resultList.appendChild(items[0]);
} }
} else if ( req.type ) { } else if ( req.type ) {
@ -599,6 +628,7 @@ var WPNavMenuHandler = function () {
if ( matched && matched[1] ) { if ( matched && matched[1] ) {
resultList = document.getElementById(matched[1] + '-search-checklist'); resultList = document.getElementById(matched[1] + '-search-checklist');
if ( resultList ) { if ( resultList ) {
resultList.innerHTML = '';
i = items.length; i = items.length;
while( i-- ) { while( i-- ) {
resultList.appendChild(items[i]); resultList.appendChild(items[i]);