From 0e4dbae91b1a54de21bac4f907c665bf592ef4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 13 Apr 2023 17:54:21 -0400 Subject: [PATCH] fix dropdown nav highlight --- public/src/app.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/public/src/app.js b/public/src/app.js index 252f65ccc4..295555f19f 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -189,11 +189,25 @@ if (document.readyState === 'loading') { }; function highlightNavigationLink() { + const pageParams = utils.params(); + function queryMatch(search) { + const mySearchParams = new URLSearchParams(search); + // eslint-disable-next-line no-restricted-syntax + for (const [key, value] of mySearchParams) { + if (pageParams[key] === value) { + return true; + } + } + return false; + } $('#main-nav li') .find('a') .removeClass('active') .filter(function (i, a) { - return $(a).attr('href') !== '#' && window.location.hostname === a.hostname && + const hasHref = $(a).attr('href') !== '#'; + const removeByQueryString = a.search && hasHref && !queryMatch(a.search); + return hasHref && window.location.hostname === a.hostname && + !removeByQueryString && ( window.location.pathname === a.pathname || window.location.pathname.startsWith(a.pathname + '/')