Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
implement no scroll state
Browse files Browse the repository at this point in the history
  • Loading branch information
khaninD committed Sep 30, 2018
1 parent ff24877 commit c8bea64
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,17 @@ function prepare_page(target: Target): Promise<{
});
}

async function navigate(target: Target, id: number): Promise<any> {
async function navigate(target: Target, id: number, noscroll = false): Promise<any> {
if (id) {
// popstate or initial navigation
cid = id;
} else {
// clicked on a link. preserve scroll state
scroll_history[cid] = scroll_state();
const scrollState = scroll_state()
scroll_history[cid] = scrollState;

id = cid = ++uid;
scroll_history[cid] = { x: 0, y: 0 };
scroll_history[cid] = noscroll ? scrollState : { x: 0, y: 0 };
}

cid = id;
Expand Down Expand Up @@ -362,8 +363,9 @@ function handle_click(event: MouseEvent) {
if (url.pathname === window.location.pathname && url.search === window.location.search) return;

const target = select_route(url);
const hasNoscroll = a.hasAttribute('sapper-noscroll')
if (target) {
navigate(target, null);
navigate(target, null, hasNoscroll);
event.preventDefault();
history.pushState({ id: cid }, '', url.href);
}
Expand Down

0 comments on commit c8bea64

Please sign in to comment.