WordPress.org

Make WordPress Core

Changeset 7670


Ignore:
Timestamp:
04/14/08 19:31:46 (7 years ago)
Author:
ryan
Message:

More efficient category and list JS from mdawaffe. fixes #6677 for 2.5

Location:
branches/2.5
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5/wp-admin/edit-form-advanced.php

    r7544 r7670  
    1 <?php 
     1 <?php 
    22$action = isset($action)? $action : ''; 
    33if ( isset($_GET['message']) ) 
     
    223223        <input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e( 'New category name' ); ?>" tabindex="3" /> 
    224224        <?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?> 
    225         <input type="button" id="category-add-sumbit" class="add:categorychecklist:categorydiv button" value="<?php _e( 'Add' ); ?>" tabindex="3" /> 
     225        <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e( 'Add' ); ?>" tabindex="3" /> 
    226226        <?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?> 
    227227        <span id="category-ajax-response"></span> 
     
    234234</ul> 
    235235 
     236<div id="categories-pop" class="ui-tabs-panel" style="display: none;"> 
     237    <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" > 
     238        <?php $popular_ids = wp_popular_terms_checklist('category'); ?> 
     239    </ul> 
     240</div> 
     241 
    236242<div id="categories-all" class="ui-tabs-panel"> 
    237243    <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 
    238         <?php dropdown_categories(); ?> 
    239     </ul> 
    240 </div> 
    241  
    242 <div id="categories-pop" class="ui-tabs-panel" style="display: none;"> 
    243     <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" > 
    244         <?php wp_popular_terms_checklist('category'); ?> 
     244        <?php dropdown_categories( 0, 0, $popular_ids ); ?> 
    245245    </ul> 
    246246</div> 
  • branches/2.5/wp-admin/includes/template.php

    r7596 r7670  
    176176} 
    177177 
    178 function write_nested_categories( $categories ) { 
     178function write_nested_categories( $categories, $popular_ids = array() ) { 
    179179    foreach ( $categories as $category ) { 
    180         echo "\n", '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), '</label>'; 
     180        $class = in_array( $category['cat_ID'], $popular_ids ) ? ' class="popular-category"' : ''; 
     181        echo "\n", "<li id='category-$category[cat_ID]'$class>", '<label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), '</label>'; 
    181182 
    182183        if ( $category['children'] ) { 
     
    189190} 
    190191 
    191 function dropdown_categories( $default = 0, $parent = 0 ) { 
    192     write_nested_categories( get_nested_categories( $default, $parent ) ); 
     192function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array() ) { 
     193    write_nested_categories( get_nested_categories( $default, $parent ), $popular_ids ); 
    193194} 
    194195 
     
    196197    $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) ); 
    197198 
     199    $popular_ids = array(); 
    198200    foreach ( (array) $categories as $category ) { 
     201        $popular_ids[] = $category->term_id; 
    199202        $id = "popular-category-$category->term_id"; 
    200203        ?> 
    201204 
    202         <li id="<?php echo $id; ?>" > 
     205        <li id="<?php echo $id; ?>" class="popular-category"> 
    203206            <label class="selectit" for="in-<?php echo $id; ?>"> 
    204207            <input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" /> 
     
    209212        <?php 
    210213    } 
     214    return $popular_ids; 
    211215} 
    212216 
  • branches/2.5/wp-admin/js/post.js

    r7529 r7670  
    119119        noSyncChecks = false; 
    120120    }; 
     121    var catAddBefore = function( s ) { 
     122        s.data += '&' + jQuery( '#categorychecklist :checked' ).serialize(); 
     123        return s; 
     124    }; 
    121125    var catAddAfter = function( r, s ) { 
    122126        if ( !newCatParent ) newCatParent = jQuery('#newcat_parent'); 
     
    141145        alt: '', 
    142146        response: 'category-ajax-response', 
     147        addBefore: catAddBefore, 
    143148        addAfter: catAddAfter 
    144149    } ); 
     
    149154        return false; 
    150155    } ); 
    151     jQuery('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change(); 
     156    jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change(); 
    152157 
    153158    jQuery('.edit-timestamp').click(function () { 
  • branches/2.5/wp-includes/js/wp-lists.js

    r7468 r7670  
    314314                var c = wpList.parseClass(this,'add')[2] || addEl.id; 
    315315                if ( !c ) { return; } 
    316                 var forms = []; var ins = []; 
     316                var forms = []; var ins = []; // this is all really inefficient 
    317317                $('#' + c + ' :input').focus( function() { currentFormEl = this; } ).blur( function() { currentFormEl = false; } ).each( function() { 
    318318                    ins.push(this); 
    319                     $.merge(forms,$(this).parents('form')); 
    320                     forms = $.unique(forms); 
     319                    var f = $(this).parents('form:first').get(0); 
     320                    if ( $.inArray(f,forms) < 0 ) { forms.push(f); } 
    321321                } ); 
    322322                $(forms).submit( function() { 
  • branches/2.5/wp-includes/script-loader.php

    r7621 r7670  
    5858        ) ); 
    5959 
    60         $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080322' ); 
     60        $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080411' ); 
    6161        $this->localize( 'wp-lists', 'wpListL10n', array( 
    6262            'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' 
     
    145145                'cancel' => __('Cancel'), 
    146146            ) ); 
    147             $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080322' ); 
     147            $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080411' ); 
    148148            $this->localize( 'post', 'postL10n', array( 
    149149                'tagsUsed' =>  __('Tags used on this post:'), 
Note: See TracChangeset for help on using the changeset viewer.