swup 4.3.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Swup.cjs +1 -1
- package/dist/Swup.cjs.map +1 -1
- package/dist/Swup.modern.js +1 -1
- package/dist/Swup.modern.js.map +1 -1
- package/dist/Swup.module.js +1 -1
- package/dist/Swup.module.js.map +1 -1
- package/dist/Swup.umd.js +1 -1
- package/dist/Swup.umd.js.map +1 -1
- package/dist/types/modules/Visit.d.ts +2 -7
- package/package.json +1 -1
- package/src/Swup.ts +19 -11
- package/src/modules/Visit.ts +6 -21
- package/src/modules/scrollToContent.ts +1 -1
package/src/Swup.ts
CHANGED
|
@@ -167,6 +167,11 @@ export default class Swup {
|
|
|
167
167
|
|
|
168
168
|
window.addEventListener('popstate', this.handlePopState);
|
|
169
169
|
|
|
170
|
+
// Set scroll restoration to manual if animating history visits
|
|
171
|
+
if (this.options.animateHistoryBrowsing) {
|
|
172
|
+
window.history.scrollRestoration = 'manual';
|
|
173
|
+
}
|
|
174
|
+
|
|
170
175
|
// Initial save to cache
|
|
171
176
|
if (this.options.cache) {
|
|
172
177
|
// Disabled to avoid caching modified dom state: logic moved to preload plugin
|
|
@@ -310,18 +315,10 @@ export default class Swup {
|
|
|
310
315
|
}
|
|
311
316
|
|
|
312
317
|
const { url, hash } = Location.fromUrl(href);
|
|
313
|
-
const animate = this.options.animateHistoryBrowsing;
|
|
314
|
-
const resetScroll = this.options.animateHistoryBrowsing;
|
|
315
|
-
|
|
316
|
-
this.visit = this.createVisit({
|
|
317
|
-
to: url,
|
|
318
|
-
hash,
|
|
319
|
-
event,
|
|
320
|
-
animate,
|
|
321
|
-
resetScroll
|
|
322
|
-
});
|
|
323
318
|
|
|
324
|
-
|
|
319
|
+
this.visit = this.createVisit({ to: url, hash, event });
|
|
320
|
+
|
|
321
|
+
// Mark as history visit
|
|
325
322
|
this.visit.history.popstate = true;
|
|
326
323
|
|
|
327
324
|
// Determine direction of history visit
|
|
@@ -331,6 +328,17 @@ export default class Swup {
|
|
|
331
328
|
this.visit.history.direction = direction;
|
|
332
329
|
}
|
|
333
330
|
|
|
331
|
+
// Disable animation & scrolling for history visits
|
|
332
|
+
this.visit.animation.animate = false;
|
|
333
|
+
this.visit.scroll.reset = false;
|
|
334
|
+
this.visit.scroll.target = false;
|
|
335
|
+
|
|
336
|
+
// Animated history visit: re-enable animation & scroll reset
|
|
337
|
+
if (this.options.animateHistoryBrowsing) {
|
|
338
|
+
this.visit.animation.animate = true;
|
|
339
|
+
this.visit.scroll.reset = true;
|
|
340
|
+
}
|
|
341
|
+
|
|
334
342
|
// Does this even do anything?
|
|
335
343
|
// if (!hash) {
|
|
336
344
|
// event.preventDefault();
|
package/src/modules/Visit.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface VisitScroll {
|
|
|
52
52
|
/** Whether to reset the scroll position after the visit. Default: `true` */
|
|
53
53
|
reset: boolean;
|
|
54
54
|
/** Anchor element to scroll to on the next page. */
|
|
55
|
-
target?: string;
|
|
55
|
+
target?: string | false;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export interface VisitTrigger {
|
|
@@ -82,38 +82,23 @@ export interface VisitInitOptions {
|
|
|
82
82
|
to: string;
|
|
83
83
|
from?: string;
|
|
84
84
|
hash?: string;
|
|
85
|
-
animate?: boolean;
|
|
86
|
-
animation?: string;
|
|
87
|
-
targets?: string[];
|
|
88
85
|
el?: Element;
|
|
89
86
|
event?: Event;
|
|
90
|
-
action?: HistoryAction;
|
|
91
|
-
resetScroll?: boolean;
|
|
92
87
|
}
|
|
93
88
|
|
|
94
89
|
/** Create a new visit object. */
|
|
95
90
|
export function createVisit(
|
|
96
91
|
this: Swup,
|
|
97
|
-
{
|
|
98
|
-
to,
|
|
99
|
-
from = this.currentPageUrl,
|
|
100
|
-
hash,
|
|
101
|
-
animate = true,
|
|
102
|
-
animation: name,
|
|
103
|
-
el,
|
|
104
|
-
event,
|
|
105
|
-
action = 'push',
|
|
106
|
-
resetScroll: reset = true
|
|
107
|
-
}: VisitInitOptions
|
|
92
|
+
{ to, from = this.currentPageUrl, hash, el, event }: VisitInitOptions
|
|
108
93
|
): Visit {
|
|
109
94
|
return {
|
|
110
95
|
from: { url: from },
|
|
111
96
|
to: { url: to, hash },
|
|
112
97
|
containers: this.options.containers,
|
|
113
98
|
animation: {
|
|
114
|
-
animate,
|
|
99
|
+
animate: true,
|
|
115
100
|
wait: false,
|
|
116
|
-
name,
|
|
101
|
+
name: undefined,
|
|
117
102
|
scope: this.options.animationScope,
|
|
118
103
|
selector: this.options.animationSelector
|
|
119
104
|
},
|
|
@@ -126,12 +111,12 @@ export function createVisit(
|
|
|
126
111
|
write: this.options.cache
|
|
127
112
|
},
|
|
128
113
|
history: {
|
|
129
|
-
action,
|
|
114
|
+
action: 'push',
|
|
130
115
|
popstate: false,
|
|
131
116
|
direction: undefined
|
|
132
117
|
},
|
|
133
118
|
scroll: {
|
|
134
|
-
reset,
|
|
119
|
+
reset: true,
|
|
135
120
|
target: undefined
|
|
136
121
|
}
|
|
137
122
|
};
|
|
@@ -7,7 +7,7 @@ import Swup from '../Swup.js';
|
|
|
7
7
|
export const scrollToContent = function (this: Swup): boolean {
|
|
8
8
|
const options: ScrollIntoViewOptions = { behavior: 'auto' };
|
|
9
9
|
const { target, reset } = this.visit.scroll;
|
|
10
|
-
const scrollTarget = target
|
|
10
|
+
const scrollTarget = target ?? this.visit.to.hash;
|
|
11
11
|
|
|
12
12
|
let scrolled = false;
|
|
13
13
|
|