mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-20 15:54:15 +00:00
Compare commits
3 Commits
konnorroge
...
fix-scroll
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efb36b2e93 | ||
|
|
0fdf6edae8 | ||
|
|
2b37c54d7c |
@@ -125,7 +125,7 @@ export default async function (eleventyConfig) {
|
||||
eleventyConfig.addPlugin(currentLink());
|
||||
|
||||
// Add code examples for `<code class="example">` blocks
|
||||
eleventyConfig.addPlugin(codeExamplesPlugin);
|
||||
eleventyConfig.addPlugin(codeExamplesPlugin());
|
||||
|
||||
// Highlight code blocks with Prism
|
||||
eleventyConfig.addPlugin(highlightCodePlugin());
|
||||
@@ -136,6 +136,10 @@ export default async function (eleventyConfig) {
|
||||
// Various text replacements
|
||||
eleventyConfig.addPlugin(
|
||||
replaceTextPlugin([
|
||||
{
|
||||
replace: /\[version\]/gs,
|
||||
replaceWith: packageData.version,
|
||||
},
|
||||
// Replace [issue:1234] with a link to the issue on GitHub
|
||||
{
|
||||
replace: /\[pr:([0-9]+)\]/gs,
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
import { allDefined } from '/dist/webawesome.js';
|
||||
|
||||
/**
|
||||
* Determines how the page was loaded. Possible return values include "reload", "navigate", "back_forward", "prerender",
|
||||
* and "unknown".
|
||||
*/
|
||||
function getNavigationType() {
|
||||
if (performance.getEntriesByType) {
|
||||
const navEntries = performance.getEntriesByType('navigation');
|
||||
if (navEntries.length > 0) {
|
||||
return navEntries[0].type;
|
||||
}
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
// Smooth links
|
||||
document.addEventListener('click', event => {
|
||||
const link = event.target.closest('a');
|
||||
@@ -31,3 +47,26 @@ function updateScrollClass() {
|
||||
window.addEventListener('scroll', updateScrollClass);
|
||||
window.addEventListener('turbo:render', updateScrollClass);
|
||||
updateScrollClass();
|
||||
|
||||
// Restore scroll position after components are defined
|
||||
allDefined().then(() => {
|
||||
const navigationType = getNavigationType();
|
||||
const key = `wa-scroll-y-[${location.pathname}]`;
|
||||
const scrollY = sessionStorage.getItem(key);
|
||||
|
||||
// Only restore when reloading, otherwise clear it
|
||||
if (navigationType === 'reload' && scrollY) {
|
||||
window.scrollTo(0, scrollY);
|
||||
} else {
|
||||
sessionStorage.removeItem(key);
|
||||
}
|
||||
|
||||
// After restoring, keep tabs on the page's scroll position for next reload
|
||||
window.addEventListener(
|
||||
'scroll',
|
||||
() => {
|
||||
sessionStorage.setItem(key, window.scrollY);
|
||||
},
|
||||
{ passive: true },
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user