drupal-caravane/web/themes/custom/caravane/assets/js/vuejs/Modale.vue

205 lines
6.8 KiB
Vue
Raw Normal View History

<template>
2024-11-14 02:31:10 +01:00
<Transition
:enter-active-class="animationsAreEnabled ? 'v-enter-active' : 'no-transition'"
:leave-active-class="animationsAreEnabled ? 'v-leave-active' : 'no-transition'"
>
2024-11-15 13:33:36 +01:00
<div v-if="!loading && (
contentType === 'etape'
|| contentType === 'static'
|| contentType === 'equipe'
|| contentType === 'partenaires'
)">
<div class="content-wrapper">
<ModaleHeader
:contentType="contentType"
:content="content"
:couleur="content.couleur || brandColor" />
<main>
<div v-for="partie in content.parties" class="partie">
2024-11-14 02:31:10 +01:00
<ModaleCarteSensible
v-if="partie.type === 'carte_sensible'"
:partie="partie" />
<ModaleTitreTexte
v-if="partie.type === 'titre_texte'"
:partie="partie"
:couleur="content.couleur || brandColor" />
<ModaleChiffresCles
v-if="partie.type === 'chiffres_cles'"
:partie="partie"
:couleur="content.couleur || brandColor" />
<ModaleDiaporama
v-if="partie.type === 'diaporama'"
:partie="partie"
:couleur="content.couleur || brandColor" />
<ModaleEntretien
v-if="partie.type === 'entretien'"
:partie="partie"
:couleur="content.couleur || brandColor" />
<ModaleExergue
v-if="partie.type === 'exergue'"
:partie="partie"
:couleur="content.couleur || brandColor" />
<ModaleVideos
v-if="partie.type === 'video'"
:partie="partie" />
</div>
2024-11-15 13:33:36 +01:00
<EquipeContent
v-if="contentType === 'equipe'"
:content="content" />
<PartenairesContent
v-if="contentType === 'partenaires'"
:content="content" />
</main>
<ModaleFooter
:contentType="contentType"
:content="content"
:couleur="content.couleur || brandColor"
/>
2024-09-29 21:36:21 +02:00
</div>
</div>
</Transition>
</template>
<script setup>
2024-11-15 13:33:36 +01:00
import { watch, onMounted } from 'vue';
2024-08-05 21:08:09 +02:00
import { storeToRefs } from 'pinia';
import { useContentStore } from '../stores/content';
2024-10-19 04:08:11 +02:00
import { useMapStore } from '../stores/map';
2024-09-29 21:36:21 +02:00
import ModaleHeader from './components/ModaleHeader.vue';
import ModaleFooter from './components/ModaleFooter.vue';
2024-11-15 13:33:36 +01:00
import EquipeContent from './components/EquipeContent.vue';
import PartenairesContent from './components/PartenairesContent.vue';
import ModaleCarteSensible from './components/parties/ModaleCarteSensible.vue';
import ModaleTitreTexte from './components/parties/ModaleTitreTexte.vue';
import ModaleChiffresCles from './components/parties/ModaleChiffresCles.vue';
import ModaleDiaporama from './components/parties/ModaleDiaporama.vue';
import ModaleEntretien from './components/parties/ModaleEntretien.vue';
import ModaleExergue from './components/parties/ModaleExergue.vue';
import ModaleVideos from './components/parties/ModaleVideos.vue';
2024-09-29 21:36:21 +02:00
2024-08-05 21:08:09 +02:00
const store = useContentStore();
const mapState = useMapStore();
const {
contentType,
content,
loading,
2024-11-14 02:31:10 +01:00
error,
} = storeToRefs(store);
2024-11-14 02:31:10 +01:00
const { defaultMapCenter, animationDuration, animationsAreEnabled } = storeToRefs(mapState);
2024-07-31 02:13:40 +02:00
let isModaleEtape, wasModaleEtape;
const brandColor = "#80c8bf";
2024-08-05 21:08:09 +02:00
const handleColorChange = () => {
watch(
() => content.value.couleur,
2024-11-14 02:31:10 +01:00
() => {
if (contentType.value === 'etape' && content.value.couleur) {
document.documentElement.style.setProperty('--etape-couleur', content.value.couleur || brandColor);
2024-11-14 02:31:10 +01:00
}
2024-07-31 02:13:40 +02:00
}
);
2024-09-29 21:36:21 +02:00
};
const handleMapMovement = () => {
watch(
() => loading.value,
() => {
if (!loading.value) {
2024-11-14 02:31:10 +01:00
isModaleEtape = contentType.value === 'etape';
// Define helper functions in variables
const disableModaleTransition = () => {
document.documentElement.style.setProperty('margin-top', '0');
document.documentElement.style.setProperty('transition', 'none');
}
const setModaleTransition = (enterDelay) => {
document.documentElement.style.setProperty('--modale-enter-delay', `${enterDelay}s`);
};
const zoomToContentPlace = () => {
mapState.zoomToPlace(
content.value.coordinates.lat ? content.value.coordinates.lat : defaultMapCenter.value.lat,
content.value.coordinates.lon ? content.value.coordinates.lon : defaultMapCenter.value.lng
);
};
if (animationsAreEnabled.value) {
if (isModaleEtape) {
if (!wasModaleEtape) {
console.log('national -> détail');
setModaleTransition(animationDuration.value);
zoomToContentPlace();
} else {
console.log('détail -> détail');
setModaleTransition(animationDuration.value);
zoomToContentPlace();
}
} else {
if (wasModaleEtape) {
console.log('détail -> national');
setModaleTransition(animationDuration.value);
mapState.resetMap();
} else {
console.log('national -> national');
setModaleTransition(0);
}
}
} else {
if (isModaleEtape) {
zoomToContentPlace();
} else {
mapState.resetMap();
2024-11-14 02:31:10 +01:00
}
disableModaleTransition();
}
2024-11-14 02:31:10 +01:00
scrollTo(0, 0);
wasModaleEtape = isModaleEtape;
}
},
);
};
onMounted(() => {
isModaleEtape = contentType.value === 'etape';
2024-11-14 02:31:10 +01:00
wasModaleEtape = isModaleEtape;
handleColorChange();
handleMapMovement();
});
</script>
2024-07-31 02:13:40 +02:00
<style scoped scss>
.v-enter-active {
transition: margin-top 0.5s ease-out var(--modale-enter-delay);
}
2024-07-31 02:13:40 +02:00
.v-leave-active {
2024-11-14 02:31:10 +01:00
transition: margin-top 0.5s ease-in;
2024-07-31 02:13:40 +02:00
}
.v-enter-from,
.v-leave-to {
margin-top: 150vh;
2024-07-31 02:13:40 +02:00
}
.v-enter-to,
2024-07-31 02:13:40 +02:00
.v-leave-from {
2024-11-14 02:31:10 +01:00
margin-top: 0vh;
}
/* This class will disable transitions */
.no-transition {
margin-top: 0 !important;
transition: none !important;
2024-07-31 02:13:40 +02:00
}
2024-11-14 02:31:10 +01:00
</style>