Code clean,
This commit is contained in:
1
.env
1
.env
@@ -1,6 +1,7 @@
|
|||||||
# Website
|
# Website
|
||||||
PROD_URL="https://housesof.world"
|
PROD_URL="https://housesof.world"
|
||||||
TRANSITION=true
|
TRANSITION=true
|
||||||
|
HOME_PHOTOS_LIMIT=6
|
||||||
|
|
||||||
# API
|
# API
|
||||||
API_TOKEN="NJk0urljsdSvApUDzWxGgoO6"
|
API_TOKEN="NJk0urljsdSvApUDzWxGgoO6"
|
||||||
|
|||||||
@@ -7,21 +7,20 @@ import { animDelay } from 'utils/store'
|
|||||||
** Transition In
|
** Transition In
|
||||||
*/
|
*/
|
||||||
export const animateIn = (scope, init) => {
|
export const animateIn = (scope, init) => {
|
||||||
const tl = anime.timeline({
|
|
||||||
easing: 'easeOutQuart',
|
|
||||||
duration: 1000
|
|
||||||
})
|
|
||||||
// Stagger each letters and words
|
// Stagger each letters and words
|
||||||
tl.add({
|
const letters = anime({
|
||||||
targets: scope.querySelectorAll('span, em span'),
|
targets: scope.querySelectorAll('span, em span'),
|
||||||
translateY: ['100%', 0],
|
translateY: ['100%', 0],
|
||||||
|
easing: 'easeOutQuart',
|
||||||
|
duration: 1000,
|
||||||
delay: anime.stagger(40, { start: init ? 0 : animDelay }),
|
delay: anime.stagger(40, { start: init ? 0 : animDelay }),
|
||||||
|
autoplay: false
|
||||||
})
|
})
|
||||||
|
|
||||||
// On scroll animation
|
// On scroll animation
|
||||||
const title = ScrollOut({
|
const title = ScrollOut({
|
||||||
once: true,
|
once: true,
|
||||||
targets: scope,
|
targets: scope,
|
||||||
onShown: () => tl.restart()
|
onShown: () => letters.restart()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ export const animateIn = () => {
|
|||||||
duration: animDuration,
|
duration: animDuration,
|
||||||
autoplay: false
|
autoplay: false
|
||||||
})
|
})
|
||||||
window.addEventListener('scroll', throttle(() => parallaxAnime(document.getElementById('title-houses'), translate), 10))
|
window.addEventListener('scroll', throttle(() => parallaxAnime(document.getElementById('title-houses'), translate), 5))
|
||||||
requestAnimationFrame(() => parallaxAnime(document.getElementById('title-houses'), translate), 50)
|
requestAnimationFrame(() => parallaxAnime(document.getElementById('title-houses'), translate))
|
||||||
|
|
||||||
// Intro: Description
|
// Intro: Description
|
||||||
const introDescription = anime({
|
const introDescription = anime({
|
||||||
|
|||||||
@@ -3,60 +3,61 @@
|
|||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
let toggleEl
|
let toggleEl
|
||||||
let toggleLayout
|
let grid
|
||||||
|
let pill
|
||||||
let layoutSetting
|
let layoutSetting
|
||||||
|
|
||||||
|
// Elements
|
||||||
|
const layoutGridClass = 'photos--grid'
|
||||||
|
const layoutListClass = 'photos--list'
|
||||||
|
|
||||||
|
// Change active pill
|
||||||
|
const toggleAnimate = (elem, pill, toggle) => {
|
||||||
|
pill.style.width = Math.round(elem.getBoundingClientRect().width) + 'px'
|
||||||
|
pill.style.left = Math.round(elem.getBoundingClientRect().left - toggleEl.getBoundingClientRect().left) + 'px'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle layout
|
||||||
|
const toggleLayout = event => {
|
||||||
|
const clicked = event.currentTarget
|
||||||
|
const type = clicked.dataset.layout
|
||||||
|
|
||||||
|
// Change the layout
|
||||||
|
switch (type) {
|
||||||
|
case 'grid':
|
||||||
|
grid.classList.add(layoutGridClass)
|
||||||
|
grid.classList.remove(layoutListClass)
|
||||||
|
break
|
||||||
|
case 'list':
|
||||||
|
grid.classList.add(layoutListClass)
|
||||||
|
grid.classList.remove(layoutGridClass)
|
||||||
|
break
|
||||||
|
default: break
|
||||||
|
}
|
||||||
|
|
||||||
|
// Animate the active pill
|
||||||
|
toggleAnimate(clicked, pill, toggleEl)
|
||||||
|
|
||||||
|
// Add/Remove active classes
|
||||||
|
toggleEl.querySelectorAll('button').forEach(button => button.classList.remove('active'))
|
||||||
|
clicked.classList.add('active')
|
||||||
|
|
||||||
|
// Remember this setting
|
||||||
|
localStorage.setItem('photosLayout', type)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Run code when mounted
|
** Run code when mounted
|
||||||
*/
|
*/
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
grid = document.querySelector('.photos')
|
||||||
|
|
||||||
// Get layout setting from storage
|
// Get layout setting from storage
|
||||||
layoutSetting = (localStorage.getItem('photosLayout')) ? localStorage.getItem('photosLayout') : 'list'
|
layoutSetting = (localStorage.getItem('photosLayout')) ? localStorage.getItem('photosLayout') : 'list'
|
||||||
|
|
||||||
// Variables
|
|
||||||
const layoutGridClass = 'photos--grid'
|
|
||||||
const layoutListClass = 'photos--list'
|
|
||||||
const grid = document.querySelector('.photos')
|
|
||||||
const pill = toggleEl.querySelector('.pill')
|
|
||||||
|
|
||||||
// Change active pill
|
|
||||||
const toggleAnimate = (elem, pill, toggle) => {
|
|
||||||
pill.style.width = Math.round(elem.getBoundingClientRect().width) + 'px'
|
|
||||||
pill.style.left = Math.round(elem.getBoundingClientRect().left - toggleEl.getBoundingClientRect().left) + 'px'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init of first option
|
// Init of first option
|
||||||
toggleAnimate(toggleEl.querySelector(`[data-layout="${layoutSetting}"]`), pill, toggleEl)
|
toggleAnimate(toggleEl.querySelector(`[data-layout="${layoutSetting}"]`), pill, toggleEl)
|
||||||
|
|
||||||
// Toggle layout
|
|
||||||
toggleLayout = event => {
|
|
||||||
const clicked = event.currentTarget
|
|
||||||
const type = clicked.dataset.layout
|
|
||||||
|
|
||||||
// Change the layout
|
|
||||||
switch (type) {
|
|
||||||
case 'grid':
|
|
||||||
grid.classList.add(layoutGridClass)
|
|
||||||
grid.classList.remove(layoutListClass)
|
|
||||||
break
|
|
||||||
case 'list':
|
|
||||||
grid.classList.add(layoutListClass)
|
|
||||||
grid.classList.remove(layoutGridClass)
|
|
||||||
break
|
|
||||||
default: break
|
|
||||||
}
|
|
||||||
|
|
||||||
// Animate the active pill
|
|
||||||
toggleAnimate(clicked, pill, toggleEl)
|
|
||||||
|
|
||||||
// Add/Remove active classes
|
|
||||||
toggleEl.querySelectorAll('button').forEach(button => button.classList.remove('active'))
|
|
||||||
clicked.classList.add('active')
|
|
||||||
|
|
||||||
// Remember this setting
|
|
||||||
localStorage.setItem('photosLayout', type)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -84,5 +85,5 @@
|
|||||||
<span>Grid</span>
|
<span>Grid</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="pill" aria-hidden="true" role="presentation"></div>
|
<div class="pill" aria-hidden="true" role="presentation" bind:this={pill}></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
description
|
description
|
||||||
explore_globe
|
explore_globe
|
||||||
explore_list
|
explore_list
|
||||||
homepage_photos_limit
|
|
||||||
photos_per_page
|
photos_per_page
|
||||||
instagram
|
instagram
|
||||||
seo_name
|
seo_name
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script context="module">
|
<script context="module">
|
||||||
// Variables
|
// Variables
|
||||||
let limit
|
let limit = process.env.CONFIG.HOME_PHOTOS_LIMIT
|
||||||
|
|
||||||
// Preload data (photos to display)
|
// Preload data (photos to display)
|
||||||
export async function preload (page, session) {
|
export async function preload (page, session) {
|
||||||
@@ -11,12 +11,9 @@
|
|||||||
]
|
]
|
||||||
// Random sort
|
// Random sort
|
||||||
const sort = '?'
|
const sort = '?'
|
||||||
// Get the limit from API
|
|
||||||
site.subscribe(store => limit = store.homepage_photos_limit)
|
|
||||||
|
|
||||||
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`)
|
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`)
|
||||||
const photos = await req.json()
|
const photos = await req.json()
|
||||||
if (req.ok) {
|
if (req.ok) {
|
||||||
return { photos: photos.data }
|
return { photos: photos.data }
|
||||||
}
|
}
|
||||||
this.error(404, 'Not found')
|
this.error(404, 'Not found')
|
||||||
@@ -103,10 +100,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="intro-carousel">
|
<div id="intro-carousel">
|
||||||
{#if photos}
|
|
||||||
<Carousel {photos} />
|
<Carousel {photos} />
|
||||||
<Fullscreen />
|
<Fullscreen />
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
{#if show || !process.browser}
|
{#if show || !process.browser}
|
||||||
<slot />
|
<slot />
|
||||||
|
|
||||||
{:else}
|
{:else if process.env.CONFIG.TRANSITION}
|
||||||
<div class="transition" id="transition" aria-hidden="true" bind:this={scope}>
|
<div class="transition" id="transition" aria-hidden="true" bind:this={scope}>
|
||||||
<div class="transition__loader"
|
<div class="transition__loader"
|
||||||
in:fly={{ y: 32, duration: 1000, easing: quartOut }}
|
in:fly={{ y: 32, duration: 1000, easing: quartOut }}
|
||||||
|
|||||||
Reference in New Issue
Block a user