nav-selected hickups when two pages have similar names

Permalink
(probably a bug: when one page name contains another page's name, both are "nav-selected" instead of just the one that is actually active.)


Hi everyone,

I discovered a strange behaviour of the autonav block.
I am using version 5.5.2.1.

Say, I have three pages,
- page
- test
- test2

When I select "page" and "test", everything works fine - the page is displayed, and the correct <li> and <a> tags have the "nav-selected" class.

When I select "test2", however, both "test2" and "test" are displayed "nav-selected" in the autonav block.
This also works with something like "customer" and "customer's project".

This behaviour is not dependent on the order in which these appear in the site map.
Apparently, it always comes up when one page name fully contains the other.

Obviously, I want this to go away. :-)
Has anyone an idea how to make it?

Many thanks for any advice!

perdittmann
 
mckoenig replied on at Permalink Reply
mckoenig
I just tried reproducing the described behaviour. I set up two pages on the same level, one named "test" one named "test2". Navigating to the page named "test" provides this and ONLY this <li> and <a> with the "nav-path-selected nav-selected" classes. "test2" is without classes as it should be. I don't see how this could be any different as the code doesn't look for the name of the page but for the ID.
See default autonav view.php, around line 67:

if ($c->getCollectionID() == $_c->getCollectionID()) { 
            echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" ' . $target . ' href="' . $pageLink . '">' . $ni->getName() . '</a>');
         } elseif ( in_array($_c->getCollectionID(),$selectedPathCIDs) && ($_c->getCollectionID() != HOME_CID) ) {
            echo('<li class="nav-path-selected"><a class="nav-path-selected" href="' . $pageLink . '" ' . $target . '>' . $ni->getName() . '</a>');
         } else {
            echo('<li><a href="' . $pageLink . '" ' . $target . ' >' . $ni->getName() . '</a>');
         }


Have you modified the view.php of the autonav controller in any way? Are the pages in your setup on the same level? Because if they are underneath each other it might be the "nav-path-selected" class you are talking about which indicates the parents to the open page.
perdittmann replied on at Permalink Reply
perdittmann
Hi mckoenig,

thanks for your answer.

Maybe I didn't get the thought across correctly – the strange behaviour does not exist when I navigate to "test", but when I navigate to "test2" (both of which are on the same level). If I do, both "test2" (correctly) and "test" (incorrectly) have the "nav-selected" class.

I didn't alter the autonav code. And I am also confused as to why this would happen, because I also saw it only checks for the ID.

Nonetheless, the problem persists...
mckoenig replied on at Permalink Reply
mckoenig
Still can't confirm. If I navigate to "test2" in my setup the source looks like this:

<nav>
<ul class="nav">
<li><a href="/"  >Home</a></li>
<li><a href="/test/"  >test</a></li>
<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected"  href="/test2/">test2</a></li>
</ul>            
</nav>
perdittmann replied on at Permalink Reply
perdittmann
This is strange.

[I had changed the autonav controller to be able to display four levels of menu, but even with the standard autonav block, this problem persists.]

As a short-term workaround, I renamed the address and the problem disappeared.
But I am still rather confused about this.

<ul class="nav-header">
<li class="nav-selected first"><a href="/test/">test</a></li>
<li class="nav-selected "><a href="/test2/" class="nav-selected">test2</a></li>
</ul>
mckoenig replied on at Permalink Reply
mckoenig
The code you quoted doesn't seem to be generated by the original autonav block as the <ul> has the class "nav-header" which isn't set in the original code.
Have you tried reproducing this with a clean install, just for testing purposes?