Opened 18 years ago
Closed 8 years ago
#592 closed defect (fixed)
Main navigation menu item is not highlighted when active
Reported by: | anonymous | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Component: | NavAddPlugin |
Severity: | normal | Keywords: | |
Cc: | jashugan@…, nicolas.dumoulin@…, Mitar | 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)
Change History (23)
comment:1 Changed 18 years ago by
Cc: | jashugan@… added; anonymous removed |
---|
comment:2 Changed 18 years ago by
comment:3 Changed 18 years ago by
Priority: | low → high |
---|---|
Severity: | minor → major |
Trac Release: | 0.9 → 0.10 |
is there a patch which fix it? any suggestions?
comment:4 Changed 18 years ago by
I have the same problem :( , It would be great to have that feature !
comment:5 Changed 18 years ago by
Priority: | high → normal |
---|---|
Severity: | major → 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 18 years ago by
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: 8 Changed 17 years ago by
Why not add simply check if the xxx.title is equal to the current wiki page, if so highlight the button?
comment:8 Changed 17 years ago by
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 16 years ago by
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:11 Changed 15 years ago by
Summary: | main navigation menu item is not highlighted when active → Main navigation menu item is not highlighted when active |
---|
See ticket #4914 for the MenusPlugin for a similar issue.
comment:12 follow-ups: 13 18 Changed 15 years ago by
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 Changed 15 years ago by
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 15 years ago by
Attachment: | navadd.activelink.patch added |
---|
Patch to use client-side jQuery to highlight the active link
comment:14 Changed 15 years ago by
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 follow-up: 21 Changed 14 years ago by
Cc: | Mitar added |
---|
I have enabled that in my fork with server-side solution.
comment:17 Changed 11 years ago by
Owner: | changed from Michael Renzmann to Ryan J Ollos |
---|---|
Status: | new → assigned |
comment:18 Changed 8 years ago by
Replying to bellaire:
Fixed two minor issues in the code:
$(document).ready(function(){ $('#mainnav ul li a').each(function() { var currentPath = location.pathname + location.search; if ($(this).attr('href') == currentPath) { $('#mainnav ul li.active').removeClass('active'); $(this).parent().addClass('active'); } }); });
comment:19 Changed 8 years ago by
Status: | assigned → accepted |
---|
comment:20 Changed 8 years ago by
I'm not sure that a client side solution is ideal, but I expect this plugin will soon be deprecated, so better to have a fix for the issue now.
I agree, i faced the same problem exactly. how can i fix it, any solutions?
Thanks