summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/menu.inc33
-rw-r--r--includes/theme.inc9
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>";