Modify

Opened 8 years ago

Last modified 7 months ago

#592 assigned defect

Main navigation menu item is not highlighted when active

Reported by: anonymous Owned by: rjollos
Priority: normal Component: NavAddPlugin
Severity: normal Keywords:
Cc: jashugan@…, nicolas.dumoulin@…, mmitar@… Trac Release: 0.10

Description

The navigation menu items created by NavAddPlugin are not highlighted when they are active. For example, I added a "Open Ticket" menu item to the main navigation menu. After I click on the "Open Ticket" link in the main navigation, it is not highlighted. I expected it to be highlighted like for "Wiki" or "New Ticket" links.

I'm not sure how feasible this is to do. BTW, thanks for the great plugin!

Attachments (1)

navadd.activelink.patch (3.1 KB) - added by bellaire 4 years ago.
Patch to use client-side jQuery to highlight the active link

Download all attachments as: .zip

Change History (18)

comment:1 Changed 8 years ago by anonymous

  • Cc jashugan@… added

comment:2 Changed 8 years ago by sramij@…

I agree, i faced the same problem exactly.
how can i fix it, any solutions?

Thanks

comment:3 Changed 8 years ago by sramij@…

  • Priority changed from low to high
  • Severity changed from minor to major
  • Trac Release changed from 0.9 to 0.10

is there a patch which fix it?
any suggestions?

comment:4 Changed 7 years ago by hihi

I have the same problem :( , It would be great to have that feature !

comment:5 Changed 7 years ago by otaku42

  • Priority changed from high to normal
  • Severity changed from major to normal

The buttons added by the plugin just link to other resources. Now imagine you add a button that links to /wiki/SomePage - how should the plugin (or Trac as a whole) know whether that page is visited by klicking on the button added by TracAddNav instead of one of the other ways to reach that page?

I'm open for suggestions, but I currently don't see a way to do that.

comment:6 Changed 7 years ago by jashugan

Now imagine you add a button that links to /wiki/SomePage - how should the plugin (or Trac as a whole) know whether that page is visited by klicking on the button added by TracAddNav? instead of one of the other ways to reach that page?

It doesn't matter to me how I reached that page. If it is highlighted when I'm on the page, then that will be sufficient. I am willing to test it out!

comment:7 follow-up: Changed 7 years ago by Flignet

Why not add simply check if the xxx.title is equal to the current wiki page, if so highlight the button?

comment:8 in reply to: ↑ 7 Changed 7 years ago by otaku42

Replying to Flignet:

Why not add simply check if the xxx.title is equal to the current wiki page, if so highlight the button?

Because this will lead to false results when the button links, for example, to a wiki page. You will have two highlighted buttons then, the regular Wiki one, and the one added with NavAddPlugin linking to this page. In my eyes this would be quite misleading, thus I'm not confident with this solution.

comment:9 Changed 6 years ago by NicolasDumoulin

  • Cc nicolas.dumoulin@… added

A solution could be to give the ability to put in the "url" an traclinks rather than an url. I think it sould be possible to hook the active page with this method … maybe.

comment:10 Changed 5 years ago by anonymous

No solution to highlight the button when active?

comment:11 Changed 5 years ago by rjollos

  • Summary changed from main navigation menu item is not highlighted when active to Main navigation menu item is not highlighted when active

See ticket #4914 for the MenusPlugin for a similar issue.

comment:12 follow-up: Changed 4 years ago by bellaire@…

Just an observation to the folks asking for this, the maintainer may be (is probably) already aware:

The way the plugin is implemented right now, you simply cannot indicate that you are on an active page. That's because the method get_active_navigation_item isn't invoked unless your INavigationProvider is *also* the IRequestHandler which is processing the current request and rendering the menu. This plugin just generates links, and doesn't actually implement the IRequestHandler interface. That wouldn't work anyway because the plugin would have to actually handle requests for the items it generates, and you want the actual handlers (e.g. the Wiki module) to do their work. Basically, doing this from within the python side would be almost impossible.

However, another approach could be taken: Implement this purely client-side using jQuery. Scan the URLs in the navigation menus, if one of them matches the menu location, add the .active class to that navigation item, and remove it from wherever it is currently. All you'd have to do is make your plugin an ITemplateProvider and provide the JS.

Here's a simple jQuery statement that I've tested which accomplishes this (for items in mainnav):

$('#mainnav ul li a').each(function() {
    if ($(this).attr('href') == location.pathname) {
           $('#mainnav ul li.active').removeClass('active');
           $(this).addClass('active');
    } 
});

comment:13 in reply to: ↑ 12 Changed 4 years ago by otaku42

Replying to bellaire@ufl.edu:

All you'd have to do is make your plugin an ITemplateProvider and provide the JS.

Nice idea. I unfortunately don't have the time to implement that now, but if someone provides a patch I'd commit that.

Changed 4 years ago by bellaire

Patch to use client-side jQuery to highlight the active link

comment:14 Changed 4 years ago by bellaire

Note there was a bug in my pasted code on 2/16 which didn't work. That's fixed in the patch I just uploaded.

comment:15 Changed 3 years ago by mitar

  • Cc mmitar@… added

I have enabled that in my fork with server-side solution.

comment:16 Changed 11 months ago by rjollos

#8591 closed as a duplicate.

comment:17 Changed 7 months ago by rjollos

  • Owner changed from otaku42 to rjollos
  • Status changed from new to assigned

Add Comment

Modify Ticket

Action
as assigned .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.