Skip to content

Commit

Permalink
Update secondary nav active item highlight from js router
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed May 29, 2024
1 parent 065fe46 commit 75a58d3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/assets/javascripts/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ OSM.Router = function (map, rts) {

var router = {};

function updateSecondaryNav() {
$("header nav.secondary > ul > li > a").each(function () {
var active = $(this).attr("href") === window.location.pathname;

$(this)
.toggleClass("text-secondary", !active)
.toggleClass("text-secondary-emphasis", active);
});
}

$(window).on("popstate", function (e) {
if (!e.originalEvent.state) return; // Is it a real popstate event or just a hash change?
var path = window.location.pathname + window.location.search,
Expand All @@ -110,6 +120,7 @@ OSM.Router = function (map, rts) {
currentPath = path;
currentRoute = route;
currentRoute.run("popstate", currentPath);
updateSecondaryNav();
map.setState(e.originalEvent.state, { animate: false });
});

Expand All @@ -124,6 +135,7 @@ OSM.Router = function (map, rts) {
currentPath = path;
currentRoute = route;
currentRoute.run("pushstate", currentPath);
updateSecondaryNav();
return true;
};

Expand Down

0 comments on commit 75a58d3

Please sign in to comment.