-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor sidebar initialization in DoubleSidebar and SingleSidebar co…
…mponents
- Loading branch information
1 parent
b4202fc
commit 58edf6d
Showing
3 changed files
with
23 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/studiocms_dashboard/src/components/component-scripts/sidebarLinks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function removeTrailingSlash(url: string) { | ||
return url.replace(/\/$/, ''); | ||
} | ||
|
||
export function sidebarLinks() { | ||
const sidebar = document.querySelector<HTMLElement>('.sidebar'); | ||
if (!sidebar) { | ||
return; | ||
} | ||
const sidebarLinks = sidebar.querySelectorAll<HTMLAnchorElement>('a'); | ||
|
||
for (const link of sidebarLinks) { | ||
link.classList.remove('active'); | ||
if ( | ||
removeTrailingSlash(window.location.pathname) === | ||
removeTrailingSlash(new URL(link.href).pathname) | ||
) { | ||
link.classList.add('active'); | ||
} | ||
} | ||
} |