Changeset 11080

Show
Ignore:
Timestamp:
07/04/07 13:02:05 (2 years ago)
Author:
netblade
Message:

Added first and last-item classes and ability to show if node has childs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/MidCOM_2_8/fi.protie.navigation/config/manifest.inc

    r6038 r11080  
    11'name' => 'fi.protie.navigation', 
    2 'version' => '1.0.7', 
     2'version' => '1.0.8', 
    33'state' => 'stable', 
    44'purecode' => true, 
     
    2121            'role' => 'lead', 
    2222        ), 
     23        'netblade' => Array 
     24        ( 
     25            'name' => 'Oskari Kokko', 
     26            'email' => 'oskari.kokko@iki.fi', 
     27            'role' => 'lead', 
     28        ), 
    2329    ), 
    2430    'dependencies' => Array 
  • branches/MidCOM_2_8/fi.protie.navigation/main.php

    r6038 r11080  
    168168     
    169169    /** 
     170     * Add first and last-class names to list item ul class name 
     171     *  
     172     * @access public 
     173     * @var boolean 
     174     */ 
     175    var $first_and_last_to_class = false; 
     176     
     177    /** 
     178     * CSS class for first 
     179     *  
     180     * @access public 
     181     * @var string 
     182     */ 
     183    var $css_first = 'first'; 
     184     
     185    /** 
     186     * CSS class for last 
     187     *  
     188     * @access public 
     189     * @var string 
     190     */ 
     191    var $css_last = 'last'; 
     192     
     193    /** 
     194     * CSS class for first and last together 
     195     *  
     196     * @access public 
     197     * @var string 
     198     */ 
     199    var $css_first_last = 'first_last'; 
     200     
     201    /** 
     202     * Check if item has childs and if so, add childs-class to list item ul class name 
     203     *  
     204     * @access public 
     205     * @var boolean 
     206     */ 
     207    var $has_childs_to_class = false; 
     208     
     209    /** 
     210     * CSS class for has childs 
     211     *  
     212     * @access public 
     213     * @var string 
     214     */ 
     215    var $css_has_childs = 'childs'; 
     216     
     217    /** 
    170218     * CSS class for nodes 
    171219     *  
     
    310358        echo "{$indent}<ul class=\"{$this->css_list_style} node-{$id}\"{$element_id}>\n"; 
    311359         
     360        $item_count = count($children); 
     361        $item_counter = 0; 
     362         
    312363        // Draw each child element 
    313364        foreach ($children as $child) 
    314365        { 
     366            $item_counter++; 
     367             
    315368            $selected = ''; 
    316369            $active = ''; 
    317370            $component = ''; 
    318371            $url_name_to_class = ''; 
     372            $first_last = ''; 
     373            $has_childs = ''; 
     374             
     375            if($item_counter == 1 && $item_counter == $item_count) 
     376            { 
     377                $first_last = $this->css_first_last; 
     378            } 
     379            elseif($item_counter == 1) 
     380            { 
     381                $first_last = $this->css_first; 
     382            } 
     383            elseif($item_counter == $item_count) 
     384            { 
     385                $first_last = $this->css_last; 
     386            } 
    319387             
    320388            $item = $this->_nap->get_node($child); 
     
    326394            } 
    327395             
     396            if($this->has_childs_to_class) 
     397            { 
     398                $childs = $this->_nap->list_nodes($child[MIDCOM_NAV_ID]); 
     399                if(count($childs)>0) 
     400                { 
     401                    $has_childs = $this->css_has_childs; 
     402                } 
     403            } 
     404             
    328405            if (in_array($item[MIDCOM_NAV_ID], $this->node_path)) 
    329406            { 
     
    336413            } 
    337414             
    338             $this->_display_element($item, $indent, $active, $selected, $component, $url_name_to_class); 
     415            $this->_display_element($item, $indent, $active, $selected, $component, $url_name_to_class, $first_last, $has_childs); 
    339416        } 
    340417        echo "{$indent}</ul>\n"; 
     
    373450         
    374451        echo "{$indent}<ul class=\"{$this->css_list_style} node-{$id}\"{$element_id}>\n"; 
    375          
     452 
     453        $item_count = count($children); 
     454        $item_counter = 0; 
     455 
    376456        // Draw each child element 
    377457        foreach ($children as $child) 
    378458        { 
     459            $item_counter++; 
     460             
    379461            $selected = ''; 
    380462            $active = ''; 
    381463            $component = ''; 
    382464            $url_name_to_class = ''; 
    383              
     465            $first_last = ''; 
     466            $has_childs = ''; 
     467             
     468            if($item_counter == 1 && $item_counter == $item_count) 
     469            { 
     470                $first_last = $this->css_first_last; 
     471            } 
     472            elseif($item_counter == 1) 
     473            { 
     474                $first_last = $this->css_first; 
     475            } 
     476            elseif($item_counter == $item_count) 
     477            { 
     478                $first_last = $this->css_last; 
     479            } 
     480             
     481            if($this->has_childs_to_class) 
     482            { 
     483                $childs = $this->_nap->list_child_elements($child[MIDCOM_NAV_ID]); 
     484                if(is_array($childs) && count($childs)>0) 
     485                { 
     486                    $has_childs = $this->css_has_childs; 
     487                } 
     488            } 
     489 
    384490            if ($child[MIDCOM_NAV_TYPE] === 'node') 
    385491            { 
     
    389495                    continue; 
    390496                } 
     497                 
    391498                 
    392499                $item = $this->_nap->get_node($child[MIDCOM_NAV_ID]); 
     
    412519                $item = $this->_nap->get_leaf($child[MIDCOM_NAV_ID]); 
    413520                 
     521                 
    414522                // Place the corresponding css class for the currently active leaf) 
    415523                if ($item[MIDCOM_NAV_ID] === $this->_nap->get_current_leaf()) 
     
    420528            } 
    421529             
    422             $this->_display_element($item, $indent, $active, $selected, $component, $url_name_to_class); 
     530            $this->_display_element($item, $indent, $active, $selected, $component, $url_name_to_class, $first_last, $has_childs); 
    423531        } 
    424532         
     
    426534    } 
    427535     
    428     function _display_element($item, $indent, $active, $selected, $component, $url_name_to_class
     536    function _display_element($item, $indent, $active, $selected, $component, $url_name_to_class, $first_last, $has_childs
    429537    { 
    430538        // Check if user has requested URL name to be included in class 
     
    453561        { 
    454562            $css_class .= ' '.$url_name_to_class; 
     563        } 
     564         
     565         // Check if the first or last is supposed to be drawn 
     566        if ($this->first_and_last_to_class && $first_last !== '') 
     567        { 
     568            $css_class .= ' '.$first_last; 
     569        } 
     570         
     571         // Check if the has childs is supposed to be drawn 
     572        if ($this->has_childs_to_class && $has_childs !== '') 
     573        { 
     574            $css_class .= ' '.$has_childs; 
    455575        } 
    456576