Why in ver. 3.2 this module ignore default expanded menu item? In ver. 2.2 it worked well.
I would like to when open the site, some items have already been expanded.

CommentFileSizeAuthor
#15 dhtml_menu.module.patch972 bytesberenddeboer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cburschka’s picture

Version: 6.x-3.2 » 6.x-3.3
Status: Active » Postponed (maintainer needs more info)

This may be a bug. After updating to 6.x-3.3, could you please check the following:

1.) Disable the "Close siblings" effect in DHTML Menu settings (if it is enabled)
2.) Open a few menus
3.) Click a link to another page
4.) Check whether the menus you opened in 2.) are still open.

If this works, and you mean the "always expanded" menus set in the menu settings are not automatically open, that isn't possible right now, but may be added in a future version.

HallSL’s picture

The help text on the click box for expanded reads "If selected and this menu item has children, the menu will always appear expanded."

And that's the functionality I thought I'd seen in the past and need for my current site. +1 on the feature request. In the mean time, the help text should be changed to something like "If selected, this menu will stay expanded after the user expands it."

m4t’s picture

I'm interesting too!

I'd like to have expansion menu as a default behaviour...

MrVee’s picture

Any update on this? I would like this feature too work as well

thtas’s picture

I just hacked together this bit of code to open up one of my top level menu items by default when the page is loaded.

It's not ideal, but it might help somebody else who needs this functionality

Added to the header section of page.tpl.php

<script>
  	$(document).ready(function(){
		var mId = 798; //the menu id which will be expanded
		$('#dhtml_menu-'+mId).parent().removeClass('collapsed')
		$('#dhtml_menu-'+mId).parent().addClass('expanded')
		$('#dhtml_menu-'+mId).parent().children('ul').show();
		$('#dhtml_menu-'+mId).unbind('click');
		$('#dhtml_menu-'+mId).attr("href", "#");
	}); 
</script>
cburschka’s picture

Title: default expanded item » Expand items that are set to be always expanded.
Version: 6.x-3.3 » 6.x-3.x-dev
Status: Postponed (maintainer needs more info) » Postponed

This would be a nice feature to have, but seeing as the menu tree is readily expandable by hand without requiring extra page-loads, having certain menus pre-expanded is not essential; so it's postponed for a while.

This feature could cause problems combined with the "leave only one item open at a time" feature, when multiple items are opened, but the D7 version already sanitizes contradictory options, so D6 could do so as well.

All in all, what is necessary here is a call to variable_get('menu_expanded') in the dhtml_menu_theme_menu_item function (right next to the $_COOKIE part, I'd say).

cburschka’s picture

Version: 6.x-3.x-dev » 7.x-1.x-dev
Status: Postponed » Active

Looks fairly easy. I'll patch just as soon as the rest of the D7 changes are done.

May be backported to D6 if it turns out to be as simple as it seems.

heyqule’s picture

thanks thtas... here is my version... The listed items are expanded by default. Then it will follow dhtml_menu cookie..

<script type="text/javascript">
    $(document).ready(function(){
        if(Drupal.dhtmlMenu.cookieGet() == "") {
          var mId = new Array(350,1952,1953); //the menu id which will be expanded

          for(var i in mId) {
            $('#dhtml_menu-'+mId[i]).parent().removeClass('collapsed');
            $('#dhtml_menu-'+mId[i]).parent().addClass('expanded');
            $('#dhtml_menu-'+mId[i]).parent().children('ul').show();
          }

          Drupal.dhtmlMenu.cookieSet();
        }
    });
</script>
Boobaa’s picture

It seems to be quite easy to solve: all we have to to in hook_init() (?) is pushing down the always-expanded mlid's to jQuery, and add a slightly modified version of #8's JS, which iterates through Drupal.settings.whatever, and not a burn-in constant array. If we want to be efficient, then we push down only the displayed always-expanded mlid's, and not all of them.

Should I prepare a patch (for d6), which does this?

AdrianB’s picture

+1 for this feature simply because the Expanded attribute clearly says so ("If selected and this menu item has children, the menu will always appear expanded.") and DHTML Menu should honor that instead of creating a confusing user experience.

cburschka’s picture

Status: Active » Fixed

This has been fixed in 6.x-4.x and 7.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

lduerig’s picture

Status: Closed (fixed) » Active

I upgraded to version 4 for drupal 6, and it doesn't seem very fixed to me...

jaarong’s picture

I'm needing a fix on this also.

berenddeboer’s picture

Version: 7.x-1.x-dev » 6.x-3.5
Status: Active » Needs review
FileSize
972 bytes

Tested this with 3.5 and indeed expanded is not honoured. This is not about how easy it is to open the menu, it is that certain customers want menus always to be displayed in a certain way.

The following simple patch makes sure that expanded is always honoured. I.e. when you say a menu is expanded, on every page it will be expanded, unless you have closed it manually.

Dirk’s picture

Seems to work for me on 3.5, thanks for posting this.

liminu’s picture

I try this, but not function.
When I select in the menu expanded the menu will be expanded but when I uncheck the checkbox, clear the cache, but the menu will expanded.
edit: the first 15 menu work correctly, only the last 3 in the display block has this problem
edit2: the problem was with the taxonomy, if the menu will be create with the module taxonomy menu it function correctly.

maxilein’s picture

Version: 6.x-3.5 » 6.x-4.x-dev
Category: feature » bug
Status: Needs review » Needs work

It does definitely not work with a book toc. Although the nodes are set to expanded the book toc (on which I am using dhtml menu) always opens collapsed.
Ideally I'd like to start with the top-level collapsed; opening a top-level items shows all sub-levels expanded.

pgillis’s picture

6.x-4.x seems to work for me. Any idea of when the 4.x line will be released?

ionmedia’s picture

Version: 6.x-4.x-dev » 7.x-1.x-dev

it is not working at all

<ul class="menu">
<li class="first dhtml-menu collapsed start-collapsed" id="dhtml_menu-668">
<li class="last collapsed dhtml-menu collapsed start-collapsed" id="dhtml_menu-677">

first menu expanded in menu item settings and second not

dianacastillo’s picture

I am trying to do this with javascript since it doesnt work for me with jquery , this is the script, it changes the class to expanded but doesnt expand it. any help would be apreciated:

<script>
var mclass=document.getElementById('dhtml_menu-3061').className;
document.getElementById('dhtml_menu-3061').className = document.getElementById('dhtml_menu-3061').className.replace ( /(?:^|\s)collapsed(?!\S)/g , '' );
var mclass=document.getElementById('dhtml_menu-3061').className;
document.getElementById('dhtml_menu-3061').className += " expanded";
var mclass=document.getElementById('dhtml_menu-3061').className;
</script>
dianacastillo’s picture

I get $ is not a function .
how would you rewrite it for drupal 7 ?
http://technotes.tostaky.biz/2012/05/about-jquery-usage-in-drupal.html

dianacastillo’s picture

I get TypeError: Drupal.dhtmlMenu.cookieGet is not a function

dianacastillo’s picture

Ive got it working like this

<script type="text/javascript">
(function ($) {
  $(document).ready(function(){
         $('#dhtml_menu-3061').removeClass('collapsed');
         $('#dhtml_menu-3061').addClass('expanded');
        $('#dhtml_menu-3068').removeClass('expanded');
         $('#dhtml_menu-3068').addClass('collapsed');
         $('#dhtml_menu-3074').removeClass('expanded');
         $('#dhtml_menu-3074').addClass('collapsed');
          var mId = new Array(3062,3063,3064); //the menu id which will be expanded
          for(var i in mId) {
            $('#dhtml_menu-'+mId[i]).parent().css("display","block");
            $('#dhtml_menu-'+mId[i]).parent().children('ul').show();
          }

    });

})(jQuery);
</script>
atiba’s picture

Any updates on this? "Show as expanded" still doesn't work for me in the latest dev version (7.x-1.x-dev).

gittosj’s picture

Issue summary: View changes

My solution was to test if the front page is being loaded and then fake a click on the first menu link. Seemed simpler and doesn't require hard coding of #ids etc:

$(document).ready(function(){
 path = window.location.pathname
  if (path =="/") {     
  $link = $('li>a:first');
  // console.log($link); // uncomment for debugging
  $link.click()
     }       
  });

Seems to work as a workaround