summaryrefslogtreecommitdiff
path: root/examples/view-transitions/src/scripts/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'examples/view-transitions/src/scripts/utils.js')
-rw-r--r--examples/view-transitions/src/scripts/utils.js107
1 files changed, 52 insertions, 55 deletions
diff --git a/examples/view-transitions/src/scripts/utils.js b/examples/view-transitions/src/scripts/utils.js
index 3d98181ab..5b7f78535 100644
--- a/examples/view-transitions/src/scripts/utils.js
+++ b/examples/view-transitions/src/scripts/utils.js
@@ -1,79 +1,76 @@
export function getNavigationType(fromPath, toPath) {
- if (fromPath.startsWith('/movies') && toPath === '/') {
- return 'movie-to-home'
- }
+ if (fromPath.startsWith('/movies') && toPath === '/') {
+ return 'movie-to-home';
+ }
- if (fromPath === '/tv' && toPath.startsWith('/tv/')) {
- return 'tv-to-show'
- }
+ if (fromPath === '/tv' && toPath.startsWith('/tv/')) {
+ return 'tv-to-show';
+ }
- if (fromPath === '/' && toPath.startsWith('/movies')) {
- return 'home-to-movie'
- }
+ if (fromPath === '/' && toPath.startsWith('/movies')) {
+ return 'home-to-movie';
+ }
- if (fromPath.startsWith('/tv/') && toPath === '/tv') {
- return 'show-to-tv'
- }
+ if (fromPath.startsWith('/tv/') && toPath === '/tv') {
+ return 'show-to-tv';
+ }
- if (
- (fromPath.startsWith('/movies') || fromPath.startsWith('/tv')) &&
- toPath.startsWith('/people')
- ) {
- return 'movie-to-person'
- }
+ if (
+ (fromPath.startsWith('/movies') || fromPath.startsWith('/tv')) &&
+ toPath.startsWith('/people')
+ ) {
+ return 'movie-to-person';
+ }
- if (
- fromPath.startsWith('/people') &&
- (toPath.startsWith('/movies') || toPath.startsWith('/tv/'))
- ) {
- return 'person-to-movie'
- }
+ if (
+ fromPath.startsWith('/people') &&
+ (toPath.startsWith('/movies') || toPath.startsWith('/tv/'))
+ ) {
+ return 'person-to-movie';
+ }
- return 'other'
+ return 'other';
}
export function isBackNavigation(navigateEvent) {
- if (
- navigateEvent.navigationType === 'push' ||
- navigateEvent.navigationType === 'replace'
- ) {
- return false
- }
- if (
- navigateEvent.destination.index !== -1 &&
- navigateEvent.destination.index < navigation.currentEntry.index
- ) {
- return true
- }
- return false
+ if (navigateEvent.navigationType === 'push' || navigateEvent.navigationType === 'replace') {
+ return false;
+ }
+ if (
+ navigateEvent.destination.index !== -1 &&
+ navigateEvent.destination.index < navigation.currentEntry.index
+ ) {
+ return true;
+ }
+ return false;
}
export function shouldNotIntercept(navigationEvent) {
- return (
- navigationEvent.canIntercept === false ||
- // If this is just a hashChange,
- // just let the browser handle scrolling to the content.
- navigationEvent.hashChange ||
- // If this is a download,
- // let the browser perform the download.
- navigationEvent.downloadRequest ||
- // If this is a form submission,
- // let that go to the server.
- navigationEvent.formData
- )
+ return (
+ navigationEvent.canIntercept === false ||
+ // If this is just a hashChange,
+ // just let the browser handle scrolling to the content.
+ navigationEvent.hashChange ||
+ // If this is a download,
+ // let the browser perform the download.
+ navigationEvent.downloadRequest ||
+ // If this is a form submission,
+ // let that go to the server.
+ navigationEvent.formData
+ );
}
export function useTvFragment(navigateEvent) {
- const toUrl = new URL(navigateEvent.destination.url)
- const toPath = toUrl.pathname
+ const toUrl = new URL(navigateEvent.destination.url);
+ const toPath = toUrl.pathname;
- return toPath.startsWith('/tv')
+ return toPath.startsWith('/tv');
}
export function getPathId(path) {
- return path.split('/')[2]
+ return path.split('/')[2];
}
export function updateTheDOMSomehow(data) {
- document.getElementById('content').innerHTML = data
+ document.getElementById('content').innerHTML = data;
}