Commit 4f4d08c2 authored by Gábor Hojtsy's avatar Gábor Hojtsy

#181564 by Crell: add first and last CSS classes to menu tree lists and themed...

#181564 by Crell: add first and last CSS classes to menu tree lists and themed item lists for themers to use
parent 2fcaa6a9
......@@ -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';
}
......
......@@ -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>";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment