I love the work that's been done on DHTML menu but there's one feature that would make it perfect for me. I've edited the .js file to expand onmouseover which is working great. My only problem is that I want the active trail to always stay open.

Basically, I'd like the user to always be able to see where they are in the menu but still be able to hover over other other menu items and see what is in other sections.

I have "Keep only one menu open at a time" and I'd like for this feature to still work with the exception of the active trail. Really, I want two menus open at a time -- whatever the user is hovering over and the active trail.

I hope I've explained what I'm looking for correctly. I did a thorough search in the forum but couldn't find anything about a similar case.

If anyone has a solution or an alternative to DHTML Menu which will do what I'm asking, I'd much appreciate it.

Thanks!

Comments

billychan’s picture

bump and subscribe.

BigMike’s picture

HelloStephanie,

Any progress on this? I modified Nice Menu to do this, but I've since upgraded to DHTML Menu and need to keep the active menu open as well...

sumaiyajaved’s picture

some problem .. any progress?

stephaniefuda’s picture

I'd also love to have this function

alexhelkar’s picture

+1

BigMike’s picture

Ok guys,

I last looked into this when I posted above in 2010, and yesterday I got caught up on many projects and decided I'd check in on this. Two years have passed and I couldn't find a solution, so I decided to tackle this myself. I've learned a lot of PHP since 2010, and I got this functionality to work. This is for v6-3.5.

I added descriptions to explain what is going on. Please let me know if you have any questions. My site uses a menu structure of one parent and only one child (or leaf), but it should work with menus of any depth so long as the menu URL structure is preserved with each successive level.

File: dhtml_menu.module

After line 112,

111:  // Otherwise, add a class to identify this element for JS.
112:  $extra_class .= ' dhtml-menu ';

Add the following:


  // ---------------------------------------------------------------------------
  // BigMike's Active Menu Expander
  //   Description: Compares menu links against the current URL
  //   If the current URL is found within the menu link, add the class "TRAIL"
  //   A new variable $keep_open is used a few lines below to prevent
  //     parent menu from collapsing
  
  // $link is the full link with HREF, TITLE, and ID tags for each menu item.
  // We need to extract only the URL from the $link variable.
  // 1) Remove the first 10 characters, which is the '<a href="/' portion.
  $menuURL = substr($link, 10);
  // 2) Now search for the first quotation mark, which must be at the end of the
  //    HREF tag, and only keep what's in front, which is the Menu's URL
  $menuURL = substr($menuURL, 0, strpos($menuURL, '"'));   
  // 3) Get the current URL. This grabs the displayed URL, which will prevent
  //    confusion with the /<taxonomy>/### system URL if using the Clean URLs module. 
  $currentURL = check_plain(request_uri());
  // 4) Finally, check if the Menu's URL is found within the current URL
  if(strpos($currentURL,$menuURL)) {
    $extra_class .= ' TRAIL '; // Adds a class to each matching menu
    $keep_open = true; // Used below to prevent DHTML from collapsing menu
  }
  // ---------------------------------------------------------------------------

And also, 12 lines down you're find this, originally line 125:
if ($menu && !($in_active_trail || in_array(substr($item['options']['attributes']['id'], 5), $cookie))) {

Replace it with this:

  // $keep_open is set to TRUE if this is the active menu, so let's prevent
  //   collapsed and start-collapsed from being added to the menu's class.
  if (!$keep_open && $menu && !($in_active_trail || in_array(substr($item['options']['attributes']['id'], 5), $cookie))) {

The active menu should now remain open, and you'll have the CSS class of "TRAIL" for both levels so you can add styling to either the parent, the child, or both.

A few notes:
-- Because this is comparing Menu URLs against the current URL, your menu's must ultimately have a path that is structured the same as the Current URL being viewed. If this affects you, I suggest using the URL Alias module to change your menu paths to have the proper destination/intended path.
-- If your menus do not have unique path structures (ie. if they overlap), then multiple menus will remain open. This occurs because I built this script to prevent the collapse of _any_ Parent who's Menu URL is found anywhere within the Current URL.

I have this working on my Drupal + Ubercart Product website located here:
http://www.marlincrawler.com

Please let me know if you have any questions!

Regards,
BigMike

vuil’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

I closed the issue as Closed (outdated) because it is for unsupported 6.x version of Drupal.

Thanks for your time to working on and the contribution!