Demand load the category list. Props mdawaffe. see #6677

git-svn-id: https://develop.svn.wordpress.org/trunk@7689 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-04-15 18:00:52 +00:00
parent c3dda2241e
commit 97cfa272b0
7 changed files with 110 additions and 63 deletions

View File

@ -0,0 +1,28 @@
<?php
require('admin.php' );
$post_ID = (int) $_GET['post'];
if ( $post_ID ? !current_user_can( 'edit_post', $post_ID ) : !current_user_can( 'edit_posts' ) )
die();
ob_start();
$popular_ids = wp_popular_terms_checklist('category');
ob_end_clean();
?>
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
<?php dropdown_categories( 0, 0, $popular_ids ); ?>
</ul>
<div id="category-add-hidden" style="display: none;">
<input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e( 'New category name' ); ?>" tabindex="3" />
<?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?>
<input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e( 'Add' ); ?>" tabindex="3" />
<?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
<span id="category-ajax-response"></span>
</div>

View File

@ -219,29 +219,17 @@ endif; ?>
<div id="category-adder" class="wp-hidden-children">
<h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
<p id="category-add" class="wp-hidden-child">
<input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e( 'New category name' ); ?>" tabindex="3" />
<?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?>
<input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e( 'Add' ); ?>" tabindex="3" />
<?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
<span id="category-ajax-response"></span>
</p>
<p id="category-add" class="wp-hidden-child"></p>
</div>
<ul id="category-tabs">
<li class="ui-tabs-selected"><a href="#categories-all" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
<li class="wp-no-js-hidden"><a href="#categories-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
<li class="ui-tabs-selected"><a href="#categories-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
<li class="wp-no-js-hidden"><a id="category-tabs-all" href="edit-form-advanced-tabs.php?post=<?php echo $post_ID; ?>" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
</ul>
<div id="categories-pop" class="ui-tabs-panel" style="display: none;">
<ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
<?php $popular_ids = wp_popular_terms_checklist('category'); ?>
</ul>
</div>
<div id="categories-all" class="ui-tabs-panel">
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
<?php dropdown_categories( 0, 0, $popular_ids ); ?>
<?php $popular_ids = wp_popular_terms_checklist('category'); // If we up the # here we have to do so in edit-form-advanced-tabs.php too ?>
</ul>
</div>

BIN
wp-admin/images/loading.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -194,6 +194,8 @@ function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array()
}
function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) {
global $checked_categories;
wp_set_checked_post_categories( $default );
$categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) );
$popular_ids = array();
@ -204,7 +206,7 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) {
<li id="<?php echo $id; ?>" class="popular-category">
<label class="selectit" for="in-<?php echo $id; ?>">
<input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" />
<input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" name="post_category[]" <?php checked( in_array( $category->term_id, $checked_categories ), true ); ?> />
<?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?>
</label>
</li>

View File

@ -100,7 +100,17 @@ jQuery(document).ready( function() {
jQuery('#newtag').keypress( tag_press_key );
// category tabs
var categoryTabs =jQuery('#category-tabs').tabs();
var newCatFocus = false;
var categoryTabs =jQuery('#category-tabs').tabs( {
cache: true,
show: function(ui) {
if ( 'category-tabs-all' != ui.id ) { return; } // only do this for the all tab
var adder = jQuery('#category-add-hidden');
if ( !adder.size() ) { return; } // we're already done
// Put HTML in proper place and set up the wp-lists etc
jQuery('#category-add').html( adder.remove().html() );
// Ajax Cat
var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ).removeClass( 'form-input-tip' ) } );
@ -147,13 +157,22 @@ jQuery(document).ready( function() {
addBefore: catAddBefore,
addAfter: catAddAfter
} );
jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change();
if ( newCatFocus ) {
jQuery('#newcat').focus();
newCatFocus = false;
}
}
} );
jQuery('#category-add-toggle').click( function() {
jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' );
categoryTabs.tabsClick( 1 );
categoryTabs.tabsClick( 2 );
jQuery('#newcat').focus();
newCatFocus = true;
return false;
} );
jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change();
jQuery('.edit-timestamp').click(function () {
if (jQuery('#timestampdiv').is(":hidden")) {

View File

@ -1265,6 +1265,16 @@ ul.categorychecklist li {
margin: 0;
}
ul#category-tabs a {
width: 100%;
display: block;
}
.ui-tabs-loading {
outline: none;
background: url(../images/loading.gif) no-repeat 0 50%;
}
#linkcategorydiv ul#category-tabs {
float: left;
width: 120px;

View File

@ -144,7 +144,7 @@ class WP_Scripts {
'save' => __('Save'),
'cancel' => __('Cancel'),
) );
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080411' );
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080412' );
$this->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'),
'add' => attribute_escape(__('Add')),