Two tags with "current" class

In the items/browse.php, I have added filters to the secondary nav menu so that users can search by item type, i.e. image, document, audio, etc. in addition to browsing all of the items or browsing the tags.

It all works, except that I am left with two

  • tags with the class "current." I understand why it's happening (the url for "View All" satisfies the requirement for the "current" class in every instance), but I'm not sure how to fix it.

    Here's the problem in action:

    `<ul class="navigation" id="secondary-nav">
    <li class="nav-view-all current"><a href="/omeka/items/browse/">View All</a></li>
    <li class="nav-images current"><a href="/omeka/items/browse/?type=6">Images</a></li>
    </ul>`

    Does anyone have any insight?

  • Hi Nathan,

    It looks like this might be a bug in the way the navigation helper function adds the "current" value to the class attribute. We'll have to check to confirm this. Like you say, the URLs do satisfy the requirement for getting current, but we may need to add a way for the helper to recognize parameters passed to the URL as unique.

    If we can come up with a solution, we'll let you know.

    Thanks,
    Jeremy

    I was just going to post about this same problem. Please keep us updated!

    I think the problem is located in the is_current_uri helper function located in UrlFunctions.php.

    In particular, I think the problem lies in the second condition of this line:

    return ($link == $current) or (strpos($current, $link) === 0);

    I wonder if this would work instead:

    return ($link == $current);

    With this change, "mydomain.com/items/browse/" would be considered a different url than "mydomain.com/items/browse/?type=6"

    Still, how would it handle anchors. We need to look at this function.

    Jeremy and Will,

    Thanks for such quick responses. You guys have the best support imaginable.

    Modifying UrlFunctions.php like Will suggested seems to do the trick for what I'm trying to accomplish.

    Thanks for helping me yet again!

    Nathan

    Right, I think I see the problem with the above fix. Now the main navigation menu looses its current class when you navigate in farther than the main page.

    For example, on the main Browse Items page (/items), the main nav li a class of current. But when you view an item (/item/show/1) the current class disappears from the main nav menu.

    This may be a hack, but you could use jQuery to remove the unwanted "current" class.

    I am getting the same result as Nathan--and initial fix, but the deeper I go it stops working. Plus, my last tab never seems to have the current class, even when clicked.

    Any hope for a fix or for further instruction for a non jQuery user?

    Thanks guys!

    kwhite, don't use the initial "fix" (the code above). In the short run, you will probably have to use jQuery to dynamically remove the unwanted "current" class.

    Maybe something like this would work in your common/header.php of your theme:

    <?php echo js('jQuery'); ?>
    		<script type="text/javascript">
    		    jQuery.noConflict();
    		    jQuery(document).ready(function(){
    		        var path = location.pathname;
    		        var search = location.search;
    		        var hash = location.hash;
    		        var pat = path + search + hash;
    
                    jQuery(".navigation a").parent().removeClass("current");
                    jQuery(".navigation a[href=" + pat  + "]").parent().addClass("current");
    	        });
    		</script>

    Thanks Will for the help with using the jQuery fix. However, I'm still struggling with the same issue Nathan mentioned earlier--The tabs stay current until you begin exploring page 2, or 3, etc. of a particular item type.

    Here's an example: http://omeka.lib.niu.edu/omeka/items/browse/?type=condolences

    It is fixed at first sight, but if you want to see the additional "condolences" items by clicking on the blue "2" the current class goes away again.

    Thanks for taking a look at this AGAIN. I keep getting stuck....

    Hi kwhtite,

    I went to the link you provided, but I don't see any blue "2" or any pagination on the condolences page.

    -Will

    Hi Will,
    I believe I changed the coloring shortly after posting this, so now the blues are reds.

    The problem is happening for any of my item tabs. On page 1 the item tab stays current, but when you click "next" or the next number to view more items the current class goes away on the item tabs.

    http://omeka.lib.niu.edu/omeka/items

    Does that make sense?

    Katharine

    Hi Omeka,
    I'm still having issues with the current class when you navigate deeper into the items (see above comment). If you get a moment could you let me know if it is a hopeless cause?

    Many thanks,
    Katharine