Ajaxify pagination requests in menu boxes. Props filosofo. fixes #13204

git-svn-id: http://svn.automattic.com/wordpress/trunk@14943 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-05-26 14:49:43 +00:00
parent b085c18258
commit 1fa281b08c
4 changed files with 84 additions and 23 deletions

View File

@ -1091,6 +1091,45 @@ case 'hidden-columns' :
die('1');
break;
case 'menu-get-metabox' :
if ( ! current_user_can( 'edit_theme_options' ) )
die('-1');
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
if ( isset( $_POST['item-type'] ) && 'post_type' == $_POST['item-type'] ) {
$type = 'posttype';
$callback = 'wp_nav_menu_item_post_type_meta_box';
$items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
} elseif ( isset( $_POST['item-type'] ) && 'taxonomy' == $_POST['item-type'] ) {
$type = 'taxonomy';
$callback = 'wp_nav_menu_item_taxonomy_meta_box';
$items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' );
}
if ( ! empty( $_POST['item-object'] ) && isset( $items[$_POST['item-object']] ) ) {
$item = apply_filters( 'nav_menu_meta_box_object', $items[ $_POST['item-object'] ] );
ob_start();
call_user_func_array($callback, array(
null,
array(
'id' => 'add-' . $item->name,
'title' => $item->labels->name,
'callback' => $callback,
'args' => $item,
)
));
$markup = ob_get_clean();
echo json_encode(array(
'replace-id' => $type . '-' . $item->name,
'markup' => $markup,
));
}
exit;
break;
case 'menu-quick-search':
if ( ! current_user_can( 'edit_theme_options' ) )
die('-1');

View File

@ -455,7 +455,7 @@ function wp_nav_menu_item_link_meta_box() {
);
?>
<div class="customlinkdiv">
<div class="customlinkdiv" id="customlinkdiv">
<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
<p id="menu-item-url-wrap">
@ -478,7 +478,7 @@ function wp_nav_menu_item_link_meta_box() {
</span>
<span class="add-to-menu">
<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
<input type="submit" class="button-secondary" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" />
<input type="submit" class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
</span>
</p>
@ -533,6 +533,8 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
array(
$post_type_name . '-tab' => 'all',
'paged' => '%#%',
'item-type' => 'post_type',
'item-object' => $post_type_name,
)
),
'format' => '',
@ -662,7 +664,7 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
<span class="add-to-menu">
<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
<input type="submit" class="button-secondary" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-post-type-menu-item" />
<input type="submit" class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-post-type-menu-item" id="submit-posttype-<?php echo $post_type_name; ?>" />
</span>
</p>
@ -707,13 +709,15 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
return;
}
$num_pages = ceil( count($terms) / $per_page );
$num_pages = ceil( wp_count_terms( $taxonomy_name , array_merge( $args, array('number' => '', 'offset' => '') ) ) / $per_page );
$page_links = paginate_links( array(
'base' => add_query_arg(
array(
$taxonomy_name . '-tab' => 'all',
'paged' => '%#%',
'item-type' => 'taxonomy',
'item-object' => $taxonomy_name,
)
),
'format' => '',
@ -831,7 +835,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
<span class="add-to-menu">
<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
<input type="submit" class="button-secondary" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-taxonomy-menu-item" />
<input type="submit" class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-taxonomy-menu-item" id="submit-taxonomy-<?php echo $taxonomy_name; ?>" />
</span>
</p>

View File

@ -33,7 +33,6 @@ var wpNavMenu;
this.attachMenuEditListeners();
this.setupInputWithDefaultTitle();
this.attachAddMenuItemListeners();
this.attachQuickSearchListeners();
this.attachThemeLocationsListeners();
@ -412,22 +411,6 @@ var wpNavMenu;
});
},
attachAddMenuItemListeners : function() {
var form = $('#nav-menu-meta');
form.find('.add-to-menu input').click(function(){
api.registerChange();
$(this).trigger('wp-add-menu-item', [api.addMenuItemToBottom]);
return false;
});
form.find('.customlinkdiv').bind('wp-add-menu-item', function(e, processMethod) {
api.addCustomLink( processMethod );
});
form.find('.posttypediv, .taxonomydiv').bind('wp-add-menu-item', function(e, processMethod) {
$(this).addSelectedToMenu( processMethod );
});
},
attachThemeLocationsListeners : function() {
var loc = $('#nav-menu-theme-locations'), params = {};
params['action'] = 'menu-locations-save';
@ -618,6 +601,41 @@ var wpNavMenu;
items.attr('checked', 'checked');
return false;
}
} else if ( target.hasClass('submit-add-to-menu') ) {
api.registerChange();
if ( e.target.id && 'submit-customlinkdiv' == e.target.id )
api.addCustomLink( api.addMenuItemToBottom );
else if ( e.target.id && -1 != e.target.id.indexOf('submit-') )
$('#' + e.target.id.replace(/submit-/, '')).addSelectedToMenu( api.addMenuItemToBottom );
return false;
} else if ( target.hasClass('page-numbers') ) {
$.post( ajaxurl, e.target.href.replace(/.*\?/, '').replace(/action=([^&]*)/, '') + '&action=menu-get-metabox',
function( resp ) {
if ( -1 == resp.indexOf('replace-id') )
return;
var metaBoxData = $.parseJSON(resp),
toReplace = document.getElementById(metaBoxData['replace-id']),
placeholder = document.createElement('div'),
wrap = document.createElement('div');
if ( ! metaBoxData['markup'] || ! toReplace )
return;
wrap.innerHTML = metaBoxData['markup'] ? metaBoxData['markup'] : '';
toReplace.parentNode.insertBefore( placeholder, toReplace );
placeholder.parentNode.removeChild( toReplace );
placeholder.parentNode.insertBefore( wrap, placeholder );
placeholder.parentNode.removeChild( placeholder );
}
);
return false;
}
});
},

File diff suppressed because one or more lines are too long