Let me start out by saying I'm a total Drupal/PHP newb (though an old-school programmer). In any case, I'm in the process of building a new site for my company in Drupal, and stumbled upon Nice Menus.

While very nice, it lacked a feature I wanted, so I decided to play around and see if I could hack it in, and much to my surprise it turned out to be pretty easy (after realizing I needed to run update.php to get the new hooks to be noticed!)

The new feature is this: 3-level menus using tables for presentation.

What this is useful for is when you have a menu structure where the 2nd-level has only a few items but level 3 has many (in the case of my company, we have a few categories of products, and 20 or so in each category). If a menu like this is implemented using regular popups, it looks ugly as sin and is hard for the user to navigate.

With a table-based menu, the first level looks and works just as it does in a regular Nice Menu, and level 2 and 3 are folded into a table; the level 2 menu items are TH items in the first row, and the level 3 menus (if there are any) are underneath in the next row in TDs. It currently only works in places where a "down" menu would work, but could be fairly easily extended to handle left and right menus as well.

Before I ran into Drupal, I mocked up how these kind of menus might work; you can see that mockup at http://beta.animeigo.com/home.t to give you an idea of the presentation effect I was after.

One thing that is very nice about this menu style is that it naturally handles user-zooming of the font sizes without any hackery; the table naturally goes in just the right place. I've tested it on Mac Safari/Firefox/Opera but haven't had a chance to test on Windows.

In any case, attached is a .zip of the hacked version. As I'm a newb, I have no idea of the etiquette involved in submitting a feature like this (educate me), but I've tried to make it as easy to follow the changes

* All changes have comments with my initials (RJW) in them.
* new CSS in nice_menus_default.css and nice_menus.css is located at the ends of the file.
* In nice_menus.module, the changes are:

1) adding a new menu type (table) to $form['nice_menus_type_'. $delta]
2) adding hooks to nice_menu_table, nice_menu_build_table for generating tabled menus
3) the two new functions in (2), which are very similar to nice_menu_tree and nice_menu_build
4) a conditional in nice_menu that calls nice_menu_table instead of nice_menu_tree if needed.

The table-specific code ignores menu items more than 3 levels deep (it could probably be hacked to do a popup for deeper stuff, but it would be ugly).

Anyway, hope you find it interesting, and look forward to comments/suggestions.

Comments

MadOverlord’s picture

Title: Table-based menus for Nice Menus » Table-based menus for Nice Menus (with code!)
volocuga’s picture

Wow,cool!
This is what I looking for a long time and related to this issue http://drupal.org/node/357020

Here is one bad thing: the children dropdown items dont work in ie6

MadOverlord’s picture

StatusFileSize
new2.52 KB
new57.5 KB

The smartass answer to that is "nothing works in IE6". But if you can figure out what needs to be fixed to get it to work, I'm happy to incorporate it!

I just put up a live test site using tabled menus, http://test.animeigo.com/

Check it out and tell me what you think. One tweak since my last code post is that it also handles 2 level deep menus as well as 3 level deep ones. And you can use simple CSS to either line up the table under the tab, or left/right justify it, which is handy in the case of wide tables (like the Liner Notes one on my site)

Once it has been beaten on a bit and I've taken the site to full production status, I'll clean things up and post a patch vs. the current dev version.

In the meantime here's my latest version and the .css file I use on the above site. Happy non-denominational gift-getting day!

toma’s picture

Nice work, i was looking for this, can we use image in the menu, like menu icon, or image product ?!

MadOverlord’s picture

I would expect you would have to do that with css. As I understand it, the nice_menus module just takes the output of the menu system (a structure of names and urls) and restructures it; my tweak just provides an extra layout of tables.

But you can certainly use CSS to replace text links with images; I do this on test.animeigo.com with the main header tabs. Each menu item has an ID you can refer to, so you can customize things. For example, in the Products listing on the site, you'll notice that the "T-shirts and Character goods" menu item has a blank line above it, that's done by tweaking the layout of that particular item.

Actually, while writing this reply, I noticed that the level 2 td's in the structure have CSS class "nice-menu-level2-row" when they should be "nice-menu-level2-col"... taptaptap... that's fixed.

izmeez’s picture

subscribing

MadOverlord’s picture

StatusFileSize
new57.71 KB
new14.99 KB

OK, here is a patch against the current release version -- the dev version has a lot of internal rearrangement and plugging things in would best be done by add1sun, since he understands his code [and drupal] better than I. If he specifically asks, I'll take a stab at it though.

Also a complete archive of the modified release version, including the changes mentioned in #5 above. I also added some additional comments to better explain the table generation logic.

Some user documentation on how the menus are laid out.

The primary (level 0) menus are in lis, which contain a table

If *all* of the level 1 menus are childless, they are in spans contained in a single tr td. If one or more of them have children, each span is inside its own th.

Level 2 menus are spans inside a td in a second tr.

Or graphically:

LI
  level-0 A
  TABLE
    TR
      TD
        CHILDLESS level-1 SPAN + A
      /TD
    /TR
  /TABLE
/LI

LI
  level-0 A
  TABLE
    TR
      TH (one or more)
        level-1 SPAN + A
      /TH
    /TR
    TR
      TH (same # as above)
        level-2 SPAN + A (multiple)
      /TH
    /TR
  /TABLE
/LI

There are numerous classes and ids defined to make customization easier (including ids that make it easy to refer to related level 1 and 2 tds). I find using Safari's "inspect element" option very useful in understanding these kind of structures.

volocuga’s picture

MadOverlord: Do you plan to add the same feature for drop-to-right style?
An example - walmart.com

MadOverlord’s picture

Hmmm...

Since the root level element is just a UL with LI's containing tables, I don't see why you couldn't implement that style just by tweaking the CSS. I don't have a need for that kind of CSS but if you want to come up with some and post it, I'm sure it would be useful to others.

Or am I missing something?

modjodandy’s picture

StatusFileSize
new350.89 KB

it work like a charm!

I replaced tables by divs, and make a couple of crazy things to populate those menus:
Check the attachment

toma’s picture

Can you share your code plz, and you test with all browser ?! looks great

MadOverlord’s picture

If you are talking about my original code, there are attachments that contain it earlier in the thread.

I have tested it and it works with Internet Exploder 7 and 8, Opera, Safari (desktop and iPhone) and Firefox.

IE 6 is, of course, a lost cause.

Anwalen’s picture

i trying to make the submenus appear on a fixed position and not under the main menu element. Isnt succeded. Can you help me where should i search the solution?

MadOverlord’s picture

That would be done with CSS positioning. If you're trying to do something similar to guillem, I suggest you look at the CSS on his site for some tips.

Anwalen’s picture

His web page seems to out of order. I alredy checked it. Tryed to sole it with css manipulation. I tryed to position the tabled child menu here:

ul.nice-menu-table li table {
position: absolute;
left : -2px;
}

But i cannot position it to the page side only can position depending to the main menu element.

As you think alredy i am not a css guru. Maybe the solution is very simple i just cant see.

MadOverlord’s picture

The first thing you need to do is get a good CSS book; I would suggest "CSS: The Definitive Guide". If you're going to do any sort of serious drupal theming you need to be up to speed on CSS.

The second is you need to know that absolute is relative to the containing block. What you want is position: fixed, which is relative to the window viewport.

Anwalen’s picture

The main problem as i see is this? the menu first level item and the submenu is in the same div and i cannot make the submenu table position independent from the main menu item. i tryed the position: fixed parameter but that makes it only relative too. i dont know why.

.nice-menu-table-table
{
position: fixed;
left: 50px;
}

This pulls the submenus to right with 50px relative to the main menu item.

I made some tryings with converting table into divs, but i failed at half.

Maybe the div based multi column menu should based on original div based one and not on the tabled one because there the main elements are in independent div-s.

Anyway i dont feel the knowledge in myself to modify a module.

MadOverlord’s picture

position: fixed allows you to position relative to the viewport (ie: absolute positions on the webpage).

The initial position of the block is wherever it would have been placed anyway. So to move it, you need to specify both a left: and a top: (for example).

However, you have to make sure that the various components touch each other, so you can move from one to the other without the hover failing.

CSS can be very tricky. I always have a copy of "CSS: The Definitive Guide" from O'Reilly nearby.

modjodandy’s picture

Contact me by mail so I can provide a valid html file, I'm kinda busy these days ;)

1mundus’s picture

Hi,

this one looks great, but I can't split 2-level menu into columns.

Menu looks like this:

A B C (subitems 1, 2, 3, 4, 5, 6) D E F (subitems 1, 2, 3) G H

These subitems are shown like one column list. How can I output them in multi-column list?

Thank you in advance!

MadOverlord’s picture

Take a look at the html and css output on http://www.animeigo.com/, it does multi-column dropdowns.

Basically, your toplevel menu items are tabs that trigger dropdowns, the level-2 menus are column headings, and the level-3 menus go in columns. Table-based menus can't nest deeper than three levels.

So your menu structure (to drupal) looks like this:

Tab Menu
-- Column Header Menu
---- Menu
---- Menu
---- Menu
-- Column Header Menu
---- Menu
---- Menu
---- Menu

and so on.

If a Tab Menu has only 1 level of menus under it, they are displayed as a column with no header.

1mundus’s picture

I see. I wanted to display level-2 links in 2 columns, but I'll be creative then and downgrade them to level-3 and use some links as headings.

Thank you for a quick reply!

dbkern’s picture

I can't figure out what I'm doing wrong. I replaced nice menus module with the modified release from #7, updated, and the tables never appear in the dropdowns. I can update to the dev release of nice menus and roll back to the last without difficulty and everything is in order. I'm noticing no change in the menu's source code when I . Caching is disabled. Suggestions?

MadOverlord’s picture

Nice menus are configured through the block config interface.

In other words, go to /admin/build/block, add a nice menus block to whatever part of the page you want it in (typically the main header), configure it, and select "table" as the style

dbkern’s picture

MadOverlord,

Somehow I managed to miss the table selection in the dropdown. Evidently, I was having a bad day. Thanks for your quick response and the work you've put into this!

MadOverlord’s picture

No problem. That's the whole point of open-source; you run into a problem, you fix it, you post it for the next poor bastard.

3cwebdev’s picture

Can this be made to display the first level links in two columns?

Like: http://www.raystedman.org/

MadOverlord’s picture

I think so, with some clever CSS. The site you link to seems to be displaying things in multi-column format, so I am not quite sure what you are going for, but in my code, if the main link (the "tab", so to speak) that triggers the popup has 2-sublevels of items, the first sublevel are the column headers, and the second sublevel are the column items under them.

If there is only one sublevel, then you just get the column items. The CSS has lots of ids and class names that you can use to lay out stuff the way you want. Or you could just tweak the patch to do exactly what you need.

http://www.animeigo.com/ shows how I use it. If adding some classes to the spans would help (for example, to make it easier to break to a new line every N items), then let me know and I will try and get out another version.

add1sun’s picture

Version: 6.x-1.3 » 6.x-2.x-dev
Status: Needs review » Needs work

If someone can reroll this against 6.x-2.x-dev then I can take a look at it to see if we can include this in NM proper. Otherwise, I'll have to close this feature and leave it for documentation for those that want to implement it on their own.

MadOverlord’s picture

TBH I am stacked with other work right now and IIRC there are significant differences to how it would hook into 6.x-2.x-dev, so if someone else could carry the ball on this, I would be obliged. If not I will see if I can get to it sometime this summer. Is there any deadline on this?

R

add1sun’s picture

No deadline at all on volunteer work. :-) In terms of timing this probably wouldn't go into NM until the D7 version, which will be a little while yet coming anyway.

ainz’s picture

For all those who wanted to check out the html output for the png shown in issue #10, here's the link.

http://www.consomacteurs.com/boutique. This is pretty good!

Oh and this one too...

http://www.consomacteurs.com/association

These are pretty useless in ie6 and I'd usually say most things are but whitehouse.gov got their menus to work exactly the same in ie6 as it does in other browsers. (sigh)

gooddesignusa’s picture

wow looks like a nice addition. subscribing.

jho1086’s picture

subscribing .... very nice, I looking this for a long time.

thanks to God that gave You all the ability to do this.

Thanks all !!!

toma’s picture

Any news for an official release ?

MadOverlord’s picture

I haven't heard anything..

add1sun’s picture

As I noted above, this will wait until D7 and there is no patch against the latest D6 code to even test it for the new Nice Menus, so this won't be in a release for quite a while. I'll open HEAD for D7 dev in a week or so and hopefully we can get the D7 upgrade taken care of quickly.

gooddesignusa’s picture

I'm going to need this for a upcoming project that needs to be done by the end of december. If there isn't a patch for the latest dev or if this functionality isn't totally worked out yet I will have to talk to my boss about throwing a bounty towards this. It seems like a lot of people would like this functionality maybe we could even all chip some in to get someone working on it.

add1sun’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev

First significant step to getting this in is to help get Nice Menus ported to 7 (#735848: Drupal 7 port of Nice Menus). Then we will need a patch against that new version.

giozzz’s picture

Version: 7.x-2.x-dev » 6.x-2.1

This is great, and I managed to make it work... only, I don't know if for is the same, but it completely breaks in both firefox and chrome.... could it be the usual z-index thing? ... anyone with the same problem?

add1sun’s picture

Version: 6.x-2.1 » 7.x-2.x-dev

Please dont' change the issue version. This is a feature request for Drupal 7.

giozzz’s picture

Sorry for that!! I patched the code as suggested in #7 .. and I've problems with browser compatibility ...should I open a dedicated issue? no one with such problems?thanks anyway

vordude’s picture

Status: Needs work » Postponed

Changing the status, since this has gotten stale with no d7 talk/code.

sunset_bill’s picture

Killer! I've just started playing around with it (in D 6.19), no CSS yet. I've inherited a project where they'd already implemented something like this with a 300+ line modification of theme_nice_menu_build()--and they were using a custom-modified version of Nice Menus for every site. This is beautiful, thank you!

SB

luco’s picture

tip: you can also try Megamenu or OM Maximenu.

astonvictor’s picture

Status: Postponed » Closed (outdated)

I'm closing it because the issue was created a long time ago without any further steps.

if you still need it then raise a new one.
thanks