Normally it's useful to have the active menu item marked, eg. by class="active". With this module it is only the case for the menu link itself. In order to style the surrounding box ( li ) it would be usefull to have it marked as well.
Find below my solution trough overriding of the theme function:

function pdda_nice_menu_build($menu) {
  $output = '';  

  foreach ($menu as $menu_item) {
    $mlid = $menu_item['link']['mlid'];
    if ($menu_item['link']['hidden'] == 0) {
      $clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']);
      $clean_path = str_replace('/', '-', $clean_path);
      $path_class = 'menu-path-'. $clean_path;
// ******* included check if active item ******* 
      $active_class = ($menu_item['link']['href'] == $_GET['q'] || ($menu_item['link']['href'] == '<front>' && drupal_is_front_page())) ? ' active ' : '';

      if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) {

        $children = theme('nice_menu_build', $menu_item['below']);

        $parent_class = $children ? 'menuparent ' : '';
// ******* included $active_class here: ******* 
        $output .= '<li id="menu-'. $mlid .'" class="'. $parent_class . $path_class . $active_class .'">'. theme('menu_item_link', $menu_item['link']);       

        if ($children) {
          $output .= '<ul>';
          $output .= $children;                     
          $output .= "</ul>\n";
        }
        $output .= "</li>\n";
      }
      else {
// ******* included $active_class here: ******* 
        $output .= '<li id="menu-'. $mlid .'" class="'. $path_class . $active_class .'">'. theme('menu_item_link', $menu_item['link']) .'</li>'."\n";
      }
    }
  }
  return $output;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

globetrotter’s picture

sorry, forgot to mention:
while overriding the theme function is ok, it would be nicer to have this detail in the module core.
:)

add1sun’s picture

Version: 6.x-1.1 » 6.x-2.x-dev
Status: Needs review » Active

Hm, well this is actually what core is doing, so it isn't a limitation of this module per se. Adding another class to the LI should probably work off the same direction as the #219804: Set active menu trail CSS selectors patch. So, we should wait until that patch settles and is in HEAD and then we can look at also adding the "active" class as well.

Patch needs review should only be set if there is actually a patch attached, so I'll reset this to active and to 6.x-2 where this sort of change would go in.

add1sun’s picture

Title: marking active menus » mark active menu LI

changing title to be clear

PMPP’s picture

Not only the li.active, but also something like:

li.selected a.selected
--- ul
----- li
----- li.selected a.selected

This way one could trace the path till the deepest selected item. That would be of great value to customization of Nice Menu.

add1sun’s picture

Well the active trail class is already in from the previous issue referenced above. I'd look at a patch to add this to NM, but won't work one up myself.

add1sun’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
jnettik’s picture

Version: 7.x-2.x-dev » 7.x-2.1
Status: Active » Needs review
FileSize
779 bytes

The active-trail link wasn't showing up on the home link for me. Here's a patch that added that for me tested against 2.1

cardpages’s picture

Just to confirm: Works like a charm!

int_ua’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 309642_li-active-trail.patch, failed testing.

apaderno’s picture

Title: mark active menu LI » Mark active menu LI
Version: 7.x-2.1 » 7.x-2.x-dev