Hi,
I just began using superfish, and I like it alot! Great job.
While I was exploring it's functionality, I noticed that the class active-trail is not being attached along the trail route. It is only showing up on the list tag at the end of the trail. Drupal core menu attaches active-trail to each List tag along the way and onto the final link as well.
I'm not much of a programmer, but I figured out that the following addition makes the superfish menu build the active-trail like the drupal core menu. I'm not very knowledgeable with regard to the data structures involved, but adding a $link_class line after the $item_class line works. I'm also sorry that my patch is not a standard patch; I haven't figured out how to set up my netbeans to do patches in the drupal format.
--- sites\all\modules\superfish\superfish.module
+++ sites\all\modules\superfish\new_superfish.module
@@ -875,6 +875,7 @@
if (!isset($menu_item['link']['hidden']) || $menu_item['link']['hidden'] == 0) {
$item_class[] = ($trail && in_array($mlid, $trail)) ? 'active-trail' : '';
+ $link_class[] = ($trail && in_array($mlid, $trail)) ? 'active-trail' : '';
// Add helper classes to the menu items and hyperlinks.
$settings['firstlast'] = ($settings['dfirstlast'] == 1 && $total_children == 1) ? 0 : $settings['firstlast'];
I also added the following to my libraries/superfish/css/superfish-navbar.css file to make the active trail show.
.sf-navbar .active-trail {
background-color:#aaa;
}
To test it, I created a small 3 level menu. I placed it in 2 blocks; 1 superfish block, 1 Drupal block; placing one on the left sidebar and one one the right.
With the patch, both blocks show a similar active-trail path. The css code makes the background gray to demonstrate. When the link at the bottom of the trail is active, and the menu links expanded, each trail link's box is gray.
Without the patch; only the final list tag has active-trail, and the link itself only has active (no active trail).
I hope that this helps everyone.
Best wishes,
Bob
Comments
Comment #1
mehrpadin commentedHey Bob,
Thanks for your remarks.
I think I already explained this in some other posts; the menu items (
<LI>elements) in the active route get the "active-trail" class, and hyperlinks (<A>elements) pointing out to the current page get an "active" class, they've nothing to do with each other and shouldn't be replaced, changed, etc.Also, if you need to style the active trail:
Hope it helps.
Comment #2
bmarcotte commentedSorry Mehrpadin, but that css isn't doing anything for me. I placed it in superfish-navbar.css and superfish.css with default and coffee styles.
I'm running the latest version (7.x-1.8) as is on the superfish project page. Is this the latest version?
also, I get active-trail placed in only the very last list (LI) element before the (A) element, which indeed only has the "active" class. Active-trail is not following the route from top to bottom. I think it should since then it would match the Drupal menu process.
With my patch, active-trail is placed in the parent (A) element, the child (LI) element, and the child (A) element. I believe that this would be the same as in the Drupal Menu stream.
I had been using the coffee style with the NavBar menu type. I just created another menu with the default style. Default style (default.css) adjusts the background color for each item along the trail which, in effect, duplicates the active-trail effect I've been looking for. Coffee.css is missing this feature.
I'm beginning to look into another issue. For whatever reason, the trail does not stay expanded when I use a custom menu. It only works on a drupal menu like Navigation or Management. I have to look into some more but, this may be the subject of an up coming thread.
Thanks for the support!
Bob
Comment #3
bmarcotte commentedI found the solution to this in: http://drupal.org/node/942782
Yeah!
-Bob
Comment #4
derMatze commentedThis issue doesn't seem to be fixed, right?
Even in 1.9beta2 I don't get any active-trail classes anywhere in my superfish menu...
Comment #5
star-szrThis is actually a core issue in Drupal 7, because there are no active-trail classes showing up anywhere in Nice Menus either.
The patch from http://drupal.org/node/942782#comment-4417194 works for me.
Comment #6
derMatze commentedSo the patch works for your nice menus?
For (my) Superfish module it doesn't solve the issue...
Comment #7
star-szrIt worked for Superfish too (set the .active-trail class on the parent
<li>). I'm running Drupal 7.2, and tested with Superfish 1.8 and 1.9beta2. However there was mention in the issue comments that the patch may not fix all cases. Cleared your cache?Comment #8
derMatze commentedDamn. I'm spending days to tell people to clean the cache at first, but when it comes to me...
Thanks! ;)
Comment #9
Wappie08 commentedMehrpadin, in reaction to #1:
I understand but in (my) case using multiple images it is very unlogical to theme the a of the first level when active and theme the li when in active trail..
My case: a navbar with level 1 +2 and a conditional menu (level 3 + 4 + 5), menu block module, which shows the deeper children in the left sidebar when you arrive at a level 2 link.
Actually when going to level >3 css becomes very unlogical (which is a bug):
level 1:
- nothing has an active trail anymore. li only has some obscure classes I need to theme: "sfHover" and "sf-breadcrumb". a doesn't have any good classes.
level 2: li has an active-trail class (yay!) and a doesn't have anything.
level 3 + 4 + 5 (menu block module): these links are themed quite nice: all li + a have an active-trail class.
In my opinion it is of great importance that both the li and the a receive an active trail property. I worked with images and multi-level menus a lot and sometimes both the li and a receive different images. I think one of the main advantages of using superfish (instead of coding yourself a menu) should be that it is easy to theme!
Greetings Wappie
Comment #10
thesos commentedHi
i am new at drupal and don't know much about js, and i have searched for this info for hours !
This above worked perfect for me.
Now my superfish menu looks great with its coloured active menu
Thanks a lot !
Comment #11
mehrpadin commentedLooks like the issue is fixed in the core.
To Wappie: That's not needed, you can use
.sf-menu li.active-trail > afor the first level,.sf-menu li li.active-trail > afor the second level, and so on and so forth.Comment #12
barwonhack commentedWhen using navbar setting, active second level trail is not remaining displayed (open/expanded) in Drupal 7.12.
This does work in D6 version (on same server: Nginx, PHP5.3).
Comment #13
barwonhack commentedThis seems to be a theme related issue. Works with Bartik, but not with AdaptiveTheme 7.x-2.2
Comment #14
mehrpadin commentedHey Stewart,
Are you using v1.9-beta4 ?
Comment #15
barwonhack commentedHey mehrpadin,
The latest dev version didn't fix the problem.
Jeff made some comments comments: http://drupal.org/node/1460976
Regards,
S.
Comment #16
mehrpadin commentedTry this one: http://drupal.org/node/1351768 the dev is actually outdated, and email me the URL if it's online.
Comment #17
barwonhack commentedHi merphadin,
Thanks for the dev link. This version work well for me but it did not resolve the nav bar submenu defect
I removed this CSS from AT Subtheme navigation.css: ul.sf-menu li ul { display: none; Prevent momentary display of sub menus /* } .
I think Jeff expects the superfish JS to over-ride the CSS declaration.
I'll leave this open so that you may determine whether this is a valid expectation for the JS to override the CSS.
IMHO, Jeff reasoning and intent is correct.
Regards,
Stewart.
Comment #18
barwonhack commentedThe active trail class is only applied to the current page link. None of the parents are marked as "active-trail". This is kinda a big deal. Anyone know of a fix?
Currently I am hacking it out this way:
body.section-online-courses #block-superfish-1 ul li#menu-577-1 a.menuparent ,
body.section-current-students #block-superfish-1 ul li#menu-578-1 a.menuparent ,
IE: The page class corresponds to the menu ID.
Comment #19
kennywyland commentedI'm using a Superfish menu as the main menu for my site and I really need the active-trail applied properly. For example, I have a section of my site for Live video and I've got a series of URLs..
live/foo/hd
live/foo/low
live/bar/hd
live/bar/low
etc.
When I'm anywhere in the live/* branch of the site, I'd like the Live menu item on my main menu to have the active-trail class so that I can keep it highlighted.
This issue has been open for more than a year, I would be willing to pay money to get this fixed for real.
Comment #20
1140 commentedSame here. Superfish + Context isn't working too.
Comment #21
rickupdegrove commentedI use adaptivetheme_subtheme
so I had to go to admin/build/themes/settings/adaptivetheme_subtheme and
Advanced theme settings -> Theme development settings -> Menu Classes
Print the .active classes on menu list items (active classes always print on the anchor).
Advanced theme settings -> Theme development settings -> Primary and Secondary Links Classes
Print the active classes on Primary and Secondary links.
Comment #22
marktheshark commentedI have active-trail class appearing when the language is set to the 2nd language (Greek), but for the primary language it isn't...
Also note a difference in classes added to the li that contains a 2nd level ul:
Greek:
middle odd sf-item-3 sf-depth-1 sf-total-children-6 sf-parent-children-0 sf-single-children-6 menuparent sfHover sf-breadcrumbEnglish:
middle odd sf-item-3 sf-depth-1 sf-total-children-6 sf-parent-children-0 sf-single-children-6 menuparentComment #23
barwonhack commentedAlso can augment CSS markup with some jQuery to add classes to parent items...
Just use the CSS selectors you require as these are psuedo-code.
Comment #24
mehrpadin commentedWill reproduce all these asap, before the v1.9 release; thank you all, much appreciated!!
Comment #25
Siracher commentedthanks for the comment. I went almost crazy trying to achieve the menu I'm looking for with CSS Rules and a missing active-trail class on the first menu item.
I modified your coding for my need and it looks like this to add the class active-trail to each li when the link within has the class active:
this solved my issue
cheers
Comment #26
marktheshark commentedAny update on this issue?
Comment #27
Jānis Bebrītis commentedi solved this by updating menu_block module.
Comment #28
mudsurfer commentedI had this issue, but had a number of sites with very similar setup, and only had issue on SOME of the sites.
I'm using D7.18 core, superfish 7.x-1.8 and a custom subtheme of Omega 7.x-3.1
So through trial and error, I have found that the superfish menu settings, on the block config dialogue, make a difference to whether the active-trail class appears or not.
i.e.: If I go Configure Block > Advanced CSS Settings > Helper classes
And I remove the check from "Add item count" and "Add children counter", that causes the active-trail class to dissappear from the li element. However if I put those classes back in, by checking those boxes, the active-trial class returns, and can be styled effectively.
I'm sorry I have no idea *why* - only that this seems to work consistantly for me. Others may be clever enough to work out why :)
more info: I'm also using the "horiztonal" "Default" style in Superfish. In case that makes a difference to people experience.
Comment #29
giorgosklatest dev still does not give active-trail
like #23 it gives me active-trail on non default language menu
but not on default language
using omega subtheme and core all other module are latest dev/stable releases
I don't see a patch in this issue so active is more appropriate
also changing the version since it appears on the latest dev (that is where the fix should be expected)
EDIT: 1.9beta5 has exact same problems
EDIT2: temporary fix based on #25 (commented out line I don't think its needed)
Comment #30
marktheshark commentedPeculiar how this is language specific...
Comment #31
Trendoid commentedFYI I used this JQuery 'ready' to make mine work (with JQ 1.4.4)
(my first post - YAY)
Comment #32
Vinsssounet commentedSo... those comments starts to be a little old.
Is there a known fix that allows Superfish to get an active trail ?
All I really need is the Active Link to be Highlighted on a Superfish menu.
The above proposed fix...
... added in superfish different css and styles did nothing for me (yep, I cleared the cache)
Anything I missed ?
Comment #33
cgdrupalkwk commented#32. My problem was Active trail not working on the Navbar (works with other styles fine). I used the ".sfHover" attribute in my CSS to change the styling of parent menu links given the absence of active-trail.
Comment #34
Ricardo BM commentedI try all updates that I find and never work as spected. I have a nine menú elements, no one have second level, and only works 1,2,8 and 9 elements.
Never asign active-trail class to those menú options.
I think the javascript solutions is the fast one, and it works, but not those above for me.
My propouse is edit page.tpl.php and add this
just on the last of the template.
Comment #35
mibfire commentedIt works only with node links, but if the submenu is a view menu then doesnt.
Comment #36
lobsterr commented