Force 3/2 format for non landscape photos on Location page
Center image on a background when square, portrait or other ratio - Fix MutuationObserver for using components (would think a component is an item)
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
export let photoAlt: string
|
export let photoAlt: string
|
||||||
export let title: string
|
export let title: string
|
||||||
export let index: string
|
export let index: string
|
||||||
|
export let orientation: string = undefined
|
||||||
export let date: string = undefined
|
export let date: string = undefined
|
||||||
export let city: string = undefined
|
export let city: string = undefined
|
||||||
</script>
|
</script>
|
||||||
@@ -28,7 +29,9 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<figure class="house__photo">
|
<figure class="house__photo"
|
||||||
|
class:not-landscape={orientation && orientation !== 'landscape'}
|
||||||
|
>
|
||||||
<a href={url} sveltekit:noscroll tabindex="0">
|
<a href={url} sveltekit:noscroll tabindex="0">
|
||||||
<Image
|
<Image
|
||||||
id={photoId}
|
id={photoId}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export async function get({ params }: RequestEvent): Promise<RequestHandlerOutpu
|
|||||||
id
|
id
|
||||||
title
|
title
|
||||||
}
|
}
|
||||||
|
orientation
|
||||||
city
|
city
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
import { getAssetUrlKey } from '$utils/helpers'
|
import { getAssetUrlKey } from '$utils/helpers'
|
||||||
import { fetchAPI } from '$utils/api'
|
import { fetchAPI } from '$utils/api'
|
||||||
import { DURATION } from '$utils/contants'
|
import { DURATION } from '$utils/contants'
|
||||||
|
import { photoFields } from '.'
|
||||||
// Components
|
// Components
|
||||||
import Metas from '$components/Metas.svelte'
|
import Metas from '$components/Metas.svelte'
|
||||||
import PageTransition from '$components/PageTransition.svelte'
|
import PageTransition from '$components/PageTransition.svelte'
|
||||||
@@ -75,15 +76,7 @@
|
|||||||
limit: ${import.meta.env.VITE_LIST_INCREMENT},
|
limit: ${import.meta.env.VITE_LIST_INCREMENT},
|
||||||
page: ${page},
|
page: ${page},
|
||||||
) {
|
) {
|
||||||
title
|
${photoFields}
|
||||||
slug
|
|
||||||
city
|
|
||||||
image {
|
|
||||||
id
|
|
||||||
title
|
|
||||||
}
|
|
||||||
date_taken
|
|
||||||
date_created
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
@@ -126,7 +119,9 @@
|
|||||||
for (const mutation of mutationsList) {
|
for (const mutation of mutationsList) {
|
||||||
if (mutation.type === 'childList') {
|
if (mutation.type === 'childList') {
|
||||||
// Observe new items
|
// Observe new items
|
||||||
mutation.addedNodes.forEach((item: HTMLElement) => observerPhotos.observe(item))
|
Array.from(mutation.addedNodes)
|
||||||
|
.filter(item => item.nodeType === Node.ELEMENT_NODE)
|
||||||
|
.forEach((item: HTMLElement) => observerPhotos.observe(item))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -269,11 +264,12 @@
|
|||||||
|
|
||||||
{#if photos.length}
|
{#if photos.length}
|
||||||
<section class="location-page__houses grid" bind:this={photosListEl}>
|
<section class="location-page__houses grid" bind:this={photosListEl}>
|
||||||
{#each photos as { title, image: { id, title: alt }, slug, city, date_taken }, index}
|
{#each photos as { title, image: { id, title: alt }, orientation, slug, city, date_taken }, index}
|
||||||
<House
|
<House
|
||||||
{title}
|
{title}
|
||||||
photoId={id}
|
photoId={id}
|
||||||
photoAlt={alt}
|
photoAlt={alt}
|
||||||
|
{orientation}
|
||||||
url="/{params.country}/{params.location}/{slug}"
|
url="/{params.country}/{params.location}/{slug}"
|
||||||
{city}
|
{city}
|
||||||
date={date_taken}
|
date={date_taken}
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit'
|
import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit'
|
||||||
import { fetchAPI } from '$utils/api'
|
import { fetchAPI } from '$utils/api'
|
||||||
|
|
||||||
|
export const photoFields = `
|
||||||
|
title
|
||||||
|
slug
|
||||||
|
city
|
||||||
|
image {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
}
|
||||||
|
orientation
|
||||||
|
date_taken
|
||||||
|
date_created
|
||||||
|
`
|
||||||
|
|
||||||
export async function get({ params }: RequestEvent): Promise<RequestHandlerOutput> {
|
export async function get({ params }: RequestEvent): Promise<RequestHandlerOutput> {
|
||||||
try {
|
try {
|
||||||
const { location } = params
|
const { location } = params
|
||||||
@@ -40,15 +53,7 @@ export async function get({ params }: RequestEvent): Promise<RequestHandlerOutpu
|
|||||||
limit: ${import.meta.env.VITE_LIST_AMOUNT},
|
limit: ${import.meta.env.VITE_LIST_AMOUNT},
|
||||||
page: 1,
|
page: 1,
|
||||||
) {
|
) {
|
||||||
title
|
${photoFields}
|
||||||
slug
|
|
||||||
city
|
|
||||||
image {
|
|
||||||
id
|
|
||||||
title
|
|
||||||
}
|
|
||||||
date_taken
|
|
||||||
date_created
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Total
|
# Total
|
||||||
|
|||||||
@@ -81,7 +81,6 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
background: $color-primary;
|
|
||||||
|
|
||||||
@include bp (sm) {
|
@include bp (sm) {
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -97,6 +96,38 @@
|
|||||||
will-change: transform;
|
will-change: transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Variant: Not landscape
|
||||||
|
&.not-landscape {
|
||||||
|
aspect-ratio: 3 / 2;
|
||||||
|
|
||||||
|
@supports not (aspect-ratio: auto) {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
padding-top: 66.66%;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
picture {
|
||||||
|
height: 100%;
|
||||||
|
background: $color-cream;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
|
||||||
|
@supports not (aspect-ratio: auto) {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
width: auto;
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Scale down image on hover
|
// Scale down image on hover
|
||||||
@media (hover: hover) {
|
@media (hover: hover) {
|
||||||
a:hover {
|
a:hover {
|
||||||
|
|||||||
Reference in New Issue
Block a user