Modify

Opened 11 years ago

Closed 8 months 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)

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

Download all attachments as: .zip

Change History (23)

comment:1 Changed 11 years ago by anonymous

Cc: jashugan@… added; anonymous removed

comment:2 Changed 11 years ago by sramij@…

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

Thanks

comment:3 Changed 11 years ago by sramij@…

Priority: lowhigh
Severity: minormajor
Trac Release: 0.90.10

is there a patch which fix it? any suggestions?

comment:4 Changed 10 years ago by hihi

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

comment:5 Changed 10 years ago by Michael Renzmann

Priority: highnormal
Severity: majornormal

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 10 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 Changed 10 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 10 years ago by Michael Renzmann

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 9 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 8 years ago by anonymous

No solution to highlight the button when active?

comment:11 Changed 8 years ago by Ryan J Ollos

Summary: main navigation menu item is not highlighted when activeMain navigation menu item is not highlighted when active

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

comment:12 Changed 7 years ago by Adam 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 7 years ago by Michael Renzmann

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 7 years ago by Adam Bellaire

Attachment: navadd.activelink.patch added

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

comment:14 Changed 7 years ago by Adam 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 6 years ago by Mitar

Cc: Mitar added

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

comment:16 Changed 4 years ago by Ryan J Ollos

#8591 closed as a duplicate.

comment:17 Changed 4 years ago by Ryan J Ollos

Owner: changed from Michael Renzmann to Ryan J Ollos
Status: newassigned

comment:18 in reply to:  12 Changed 8 months ago by walty8@…

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 months ago by Ryan J Ollos

Status: assignedaccepted

comment:20 Changed 8 months ago by Ryan J Ollos

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.

comment:21 in reply to:  15 Changed 8 months ago by Ryan J Ollos

Replying to mitar:

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

The repository appears to be deleted. Do you have an updated link?

comment:22 Changed 8 months ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

In 15977:

0.4: Highlight active navigation item

Patch by bellair, revised by walty8.

Fixes #592.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.

Add Comment


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

 
Note: See TracTickets for help on using tickets.