diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-10-08 14:15:09 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-10-08 14:15:09 +0000 |
commit | 4f4d08c23d6d4ef866902220fd4a155744207dda (patch) | |
tree | 39252ff319a0a0862c6555eae44f90779b0af946 /includes | |
parent | 2fcaa6a91a4d7be2db34371fc4dfb078e2ec018a (diff) | |
download | brdo-4f4d08c23d6d4ef866902220fd4a155744207dda.tar.gz brdo-4f4d08c23d6d4ef866902220fd4a155744207dda.tar.bz2 |
#181564 by Crell: add first and last CSS classes to menu tree lists and themed item lists for themers to use
Diffstat (limited to 'includes')
-rw-r--r-- | includes/menu.inc | 33 | ||||
-rw-r--r-- | includes/theme.inc | 9 |
2 files changed, 33 insertions, 9 deletions
diff --git a/includes/menu.inc b/includes/menu.inc index 7a42668bf..287d1c29f 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -585,15 +585,29 @@ function menu_tree($menu_name = 'navigation') { function menu_tree_output($tree) { $output = ''; + // Pull out just the menu items we are going to render so that we + // get an accurate count for the first/last classes. foreach ($tree as $data) { if (!$data['link']['hidden']) { - $link = theme('menu_item_link', $data['link']); - if ($data['below']) { - $output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail']); - } - else { - $output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail']); - } + $items[] = $data; + } + } + + $num_items = count($items); + foreach ($items as $i => $data) { + $extra_class = NULL; + if ($i == 0) { + $extra_class = 'first'; + } + if ($i == $num_items - 1) { + $extra_class = 'last'; + } + $link = theme('menu_item_link', $data['link']); + if ($data['below']) { + $output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class); + } + else { + $output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class); } } return $output ? theme('menu_tree', $output) : ''; @@ -921,8 +935,11 @@ function theme_menu_tree($tree) { /** * Generate the HTML output for a menu item and submenu. */ -function theme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE) { +function theme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) { $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf')); + if (!empty($extra_class)) { + $class .= ' '. $extra_class; + } if ($in_active_trail) { $class .= ' active-trail'; } diff --git a/includes/theme.inc b/includes/theme.inc index 5d6e07210..6f3dda76f 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1493,7 +1493,8 @@ function theme_item_list($items = array(), $title = NULL, $type = 'ul', $attribu if (!empty($items)) { $output .= "<$type". drupal_attributes($attributes) .'>'; - foreach ($items as $item) { + $num_items = count($items); + foreach ($items as $i => $item) { $attributes = array(); $children = array(); if (is_array($item)) { @@ -1515,6 +1516,12 @@ function theme_item_list($items = array(), $title = NULL, $type = 'ul', $attribu if (count($children) > 0) { $data .= theme_item_list($children, NULL, $type, $attributes); // Render nested list } + if ($i == 0) { + $attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] .' first'); + } + if ($i == $num_items - 1) { + $attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] .' last'); + } $output .= '<li'. drupal_attributes($attributes) .'>'. $data .'</li>'; } $output .= "</$type>"; |