Start a new discussion

To start a new discussion please visit the discussions section of the GitHub home page of the project.

Discussions on GitHub

You can also search our old self-hosted forums for any useful information below but please note that posting new content here is not possible any more.

Set home page link to active, when no page is selected

Home Forums Older releases 0.9.x Set home page link to active, when no page is selected

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2374
    dannyrus
    Participant

    Hi there,

    Hard to explain – I’ve implemented SmartMenus ON THIS SITE http://sambuco.com.au/ – but when you type in the address and browse there, since the index.php page is not yet selected, all the menu items are in their active state (highlighted white). If you click the menu items, it behaves normally again (just the active link is highlighted white).

    How can I set the root level to just show HOME in the active state?

    Cheers!

    #2375
    Moe
    Participant

    You will need to add ~/ to the HREF for Home (Index)

    #2378
    dannyrus
    Participant

    Hi,

    Thanks for the reply – do you mean like this?

    <li><a href="~/index.php">HOME</a></li>

    If not, would you mind showing me what you mean? I tried the above but the result is the same.

    Thanks!

    #2387
    admin
    Keymaster

    You seem to be using some custom JS that doesn’t work properly:

            $(function(){
    
                var url = window.location.pathname, // in real app this would have to be replaced with window.location.pathname 
                    urlRegExp = new RegExp(url.replace(/\/$/,'')); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there
    
                // now grab every link from the navigation
                $('#centeredmenu a').each(function(){
                    // and test its href against the url pathname regexp
                    if(urlRegExp.test(this.href)){
                        $(this).addClass('active');
                    }
                });
    
            });

    To fix it, change the following line:

    urlRegExp = new RegExp(url.replace(/\/$/,'')); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there

    like this:

    urlRegExp = new RegExp(url.replace(/\/$/,'') || "index.php"); // create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there

    and then set your link like this:

    <li><a href="index.php">Home</a></li>

    Cheers!

    #2388
    dannyrus
    Participant

    Ah, superb 🙂 thanks so much for that, working perfectly. Always something simple!

    Much appreciated 😀

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘0.9.x’ is closed to new topics and replies.