-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): speed up navigation through turbolinks (VIV-1585)
- Loading branch information
1 parent
c98fb90
commit 2a7300d
Showing
10 changed files
with
137 additions
and
70 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'htmx.org'; | ||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
const navItems = document.querySelectorAll('vwc-nav-item'); | ||
for (const navItem of navItems) { | ||
navItem.setAttribute('hx-get', navItem.href); | ||
navItem.setAttribute('hx-push-url', 'true'); | ||
navItem.addEventListener('click', (e) => { e.preventDefault() }); | ||
window.htmx.process(navItem); | ||
} | ||
}); | ||
|
||
const handleLocationChange = () => { | ||
for (const el of document.querySelectorAll('vwc-nav-item[aria-current="page"], vwc-nav-disclosure[aria-current="page"]')) { | ||
el.removeAttribute('aria-current'); | ||
} | ||
|
||
let current = document.querySelector(` | ||
vwc-nav-item[href="${location.pathname}"], | ||
vwc-nav-item[href="${location.pathname.replace(/\/$/, '')}"] | ||
`); | ||
while (current) { | ||
if (current.tagName === 'VWC-NAV-ITEM' || current.tagName === 'VWC-NAV-DISCLOSURE') { | ||
current.setAttribute('aria-current', 'page'); | ||
} | ||
current = current.parentElement; | ||
} | ||
} | ||
|
||
window.addEventListener("popstate", handleLocationChange); | ||
window.addEventListener("htmx:pushedIntoHistory", handleLocationChange); |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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