[JQ] Tree

Discussion in 'PHP' started by Doom123, 5 Mar 2012.

  1. Doom123

    Doom123 Elder - Старейшина

    Joined:
    11 Nov 2006
    Messages:
    749
    Likes Received:
    244
    Reputations:
    22
    Всем привет! я учусь работать с Jquery...
    нужно было мне написать просмотр дерева на таблицах ..

    Написал .. всё работатет .. но чуствую от незнания наделал там салат ... не подскажите моменты в которых я мог бы исправить код?

    PHP:
    jQuery(document).ready(function(){

        
    jQuery("div.wnm_pm").live('click', function() {    
                
    jQuery(this).toggle(
                    function () {
                            
    jQuery(this).css({backgroundImage:"url(/wp-content/plugins/wnm-network/minus.gif)"});
                            
    //var tabl = jQuery("table.widefat");
                            
    var tabl jQuery(this).parents('tr.alternate');
                            var 
    vars jQuery(this).attr("id");
                            
    vars vars.split('-');
                            var 
    id vars[0];
                            
                            var 
    cls tabl.attr("class").split(" ");
                            
                            
                            
                            if(
    cls.length 2)
                            {
                                
    cls cls[0];
                                var 
    clas cls '-' id;
                                var 
    subs tabl.parent().find('tr[class~=' cls '-' id ']'); 
                            } else {
                                
    cls '';
                                var 
    clas 'subs-of-' id;
                                var 
    subs tabl.parent().find('tr[class~=subs-of-' id ']');
                            }
                            
                            if(
    subs.length 0)
                            {
                                
    subs.addClass("vis").show("slow");
                                
                                
    tabl.parent().find('tr[class^=' clas '-]').each(function()
                                {
                                    if(
    jQuery(this).hasClass("vis") == true)
                                    {
                                        
    jQuery(this).show("slow");
                                    }
                                });
                                
                            } else {
                                
                                
    jQuery.post(
                                       
    ajaxurl
                                       {
                                          
    'action':'wnm_subblogs',
                                          
    'wnm_id':id,
                                          
    'wnm_level':vars[1],
                                          
    'wnm_class'cls,
                                       },
                                       
                                       
                                       function(
    response){
                                          
    //subs.html(response);
                                           
    tabl.after(response);
                                       }               
                                    );
                            }
                    },
                    function () {
                        
    jQuery(this).css({backgroundImage:"url(/wp-content/plugins/wnm-network/plus.gif)"});
                        var 
    tabl jQuery(this).parents('tr.alternate');
                        
    //var tabl = jQuery(this).parents('tr.alternate');
                        
    var vars jQuery(this).attr("id");
                        
    vars vars.split('-');
                        var 
    id vars[0];
                        var 
    arr tabl.attr("class").split(" ");
                        
                        if(
    arr.length 2)
                        {   
                            var 
    subs arr[0] + '-';
                            
                        } else {
                            var 
    subs 'subs-of-';
                        }
                        
                        
    tabl.parent().find('tr[class~=' subs  id ']').removeClass("vis").hide("slow");                
                        
    tabl.parent().find('tr[class^=' subs  id '-]').hide("slow");
                
                    }
                ).
    trigger('click');
        });
    });
    таблица вида

    PHP:
    <table width="100%" cellpadding="3" cellspacing="3" class="widefat"> 
                    <thead>
                        <tr>
                        <th class="manage-column column-cb check-column" id="cb" scope="col">
                            <input type="checkbox" />
                        </th>
                        <th scope="col">
                            ID
                        </th>
                                        <th scope="col">
                            Название
                        </th>
                                        <th scope="col">
                            Создан
                        </th>
                                        <th scope="col">
                            URL
                        </th>
                                        <th scope="col">
                            Владельцы
                        </th>
                                                            <th scope="col">
                            Суб-Блогов
                        </th>
                        </tr>
                    </thead>
                    
                    <?php wnm_get_blogs(); ?> 

                </table>
    а функция / аякс выдаёт

    PHP:
        <tr class="<?php if($id != '') echo $subs_of.'-'.$id.' '?>alternate vis" >                            
                <th scope="row" class="check-column">
                        <input type='checkbox' id='<?=$blog->blog_id?>' name='allblogs[]' value='<?=$blog->blog_id?>' />
                </th>
                <th scope="row" valign="top">
                    <label for='<?=$blog->blog_id?>'><?=$blog->blog_id?></label>

                </th>
                <td valign='top'>
                <?php if($sub 0) echo '<div id="'.$blog->blog_id.'-'.$level.'" class="wnm_pm"></div>'?>
                        
                    
                    <label for='<?=$blog->blog_id?>'><?=str_repeat("-- ",$blog->level-$level).$blog_details->blogname?></label>

                </td>
                <td valign='top'><label for='<?=$blog->blog_id?>'><?=$blog_details->registered?></label></td>
                <td valign='top'><label for='<?=$blog->blog_id?>'>http://<?=$blog_details->domain.$blog_details->path?></label></td>
                <td valign='top'><label for='<?=$blog->blog_id?>'><?=$users?></label></td>
                <td valign='top'><label for='<?=$blog->blog_id?>'><?=$sub?></label></td>
                </tr>
    зарание спасибо если ктото решися помочь =)
     
    #1 Doom123, 5 Mar 2012
    Last edited: 5 Mar 2012