transition modale et début history

This commit is contained in:
Valentin 2024-07-31 02:13:40 +02:00
parent 35ec4a8388
commit a05f81c2d9
4 changed files with 109 additions and 58 deletions

View File

@ -61,11 +61,18 @@ import { useContentStore } from './stores/content';
let a = e.currentTarget; let a = e.currentTarget;
let nid = a.dataset.nodeNid; let nid = a.dataset.nodeNid;
console.log(nid); // console.log(nid);
let general_link_fields = document.querySelectorAll('#menu > ul > li > a');
for (let field of general_link_fields) {
if (field.classList.contains('is-active')) {
field.classList.remove('is-active');
}
}
if (category === 'etape') { if (category === 'etape') {
store.fetchEtapeData(nid); store.fetchEtapeData(nid);
} else if (category === 'static') { } else if (category === 'static') {
e.currentTarget.classList.add('is-active');
store.fetchStaticData(nid); store.fetchStaticData(nid);
} }
@ -73,7 +80,7 @@ import { useContentStore } from './stores/content';
} }
function processStaticLinks(store){ function processStaticLinks(store){
let general_link_fields = document.querySelectorAll('#menu > ul > li > a'); let general_link_fields = document.querySelectorAll('#menu > ul > li:not(:first-of-type) > a');
for (let field of general_link_fields) { for (let field of general_link_fields) {
let general_link_href = field.getAttribute('href'); let general_link_href = field.getAttribute('href');
const nid = general_link_href.charAt(general_link_href.length-1); const nid = general_link_href.charAt(general_link_href.length-1);
@ -114,12 +121,22 @@ import { useContentStore } from './stores/content';
const menuTitle = document.querySelector('#menu-title'); const menuTitle = document.querySelector('#menu-title');
const menuBurger = document.querySelector('#hamburger'); const menuBurger = document.querySelector('#hamburger');
const menuH2 = document.querySelector('#menu > h2'); const menuH2 = document.querySelector('#menu > h2');
menuButton.addEventListener('click', (e) => { menuButton.addEventListener('click', (e) => {
// e.preventDefault(); // e.preventDefault();
menuContainer.classList.toggle('open'); setTimeout(() => {
menuTitle.classList.toggle('open'); menuContainer.classList.toggle('open');
menuBurger.classList.toggle('open'); menuTitle.classList.toggle('open');
menuH2.classList.toggle('open'); menuBurger.classList.toggle('open');
menuH2.classList.toggle('open');
}, 50);
})
document.addEventListener('click', (e) => {
if (!menuContainer.contains(e.target) && !menuBurger.contains(e.target)) {
menuContainer.classList.remove('open');
menuTitle.classList.remove('open');
menuBurger.classList.remove('open');
menuH2.classList.remove('open');
}
}) })
} }

View File

@ -2,9 +2,9 @@ import { defineStore } from 'pinia';
import REST from '../api/rest-axios'; import REST from '../api/rest-axios';
export const useContentStore = defineStore('content', { export const useContentStore = defineStore('content', {
state: () => ({ state: () => ({
href: '',
etape: { etape: {
href: '',
title: '', title: '',
adresse: {}, adresse: {},
etape_number: '', etape_number: '',
@ -17,7 +17,6 @@ export const useContentStore = defineStore('content', {
vignette: {}, vignette: {},
}, },
page: { page: {
href: '',
title: '', title: '',
text: '', text: '',
}, },
@ -28,6 +27,7 @@ export const useContentStore = defineStore('content', {
async fetchEtapeData(nid) { async fetchEtapeData(nid) {
this.loading = true; this.loading = true;
this.error = null; this.error = null;
this.etape = {};
this.page = {}; this.page = {};
try { try {
const response = await REST.get(`/jsonapi/node/etape/`); const response = await REST.get(`/jsonapi/node/etape/`);
@ -35,7 +35,7 @@ export const useContentStore = defineStore('content', {
if (etape.attributes.drupal_internal__nid == nid) { if (etape.attributes.drupal_internal__nid == nid) {
for (let metatag of etape.attributes.metatag) { for (let metatag of etape.attributes.metatag) {
if (metatag.tag === "link") { if (metatag.tag === "link") {
this.etape.href = metatag.attributes.href; this.href = metatag.attributes.href;
} }
} }
this.etape.title = etape.attributes.title; this.etape.title = etape.attributes.title;
@ -69,6 +69,7 @@ export const useContentStore = defineStore('content', {
this.loading = true; this.loading = true;
this.error = null; this.error = null;
this.etape = {}; this.etape = {};
this.page = {};
try { try {
const response = await REST.get(`/jsonapi/node/static/`); const response = await REST.get(`/jsonapi/node/static/`);
for (let staticContent of response.data.data) { for (let staticContent of response.data.data) {
@ -78,11 +79,10 @@ export const useContentStore = defineStore('content', {
this.page.title = item.attributes.content; this.page.title = item.attributes.content;
} }
if (item.tag === 'link') { if (item.tag === 'link') {
this.page.href = item.attributes.href; this.href = item.attributes.href;
} }
}) })
this.page.text = staticContent.attributes.field_texte.value; this.page.text = staticContent.attributes.field_texte.value;
console.log(this.page.title, this.page.href, this.page.text);
} }
} }
} catch (error) { } catch (error) {

View File

@ -1,53 +1,58 @@
<template> <template>
<div v-if="etape.etape_number"> <Transition>
<header> <div v-if="etape.etape_number">
<h1>{{etape.adresse.locality}}, {{ etape.adresse.postal_code }}</h1> <header>
<h2>{{etape.title}}</h2> <h1>{{etape.adresse.locality}}, {{ etape.adresse.postal_code }}</h1>
<h2>{{etape.title}}</h2>
<div>
<p>Étape n°{{etape.etape_number}}</p>
<p>Du {{etape.dates.value}} au {{ etape.dates.end_value }}</p>
</div>
<img :src="etape.vignette.url" :alt="etape.vignette.alt">
</header>
<main>
<div v-for="partie in etape.parties">
<h3 v-html="partie.title"></h3>
<p v-html="partie.text"></p>
</div>
</main>
<!--
<div v-if="loading">Loading...</div>
<div v-if="error">{{ error }}</div>
-->
<div><pre>{{href}}</pre></div>
<div><pre><b>GEOFIELD</b>{{etape.geofield}}</pre></div>
<div><pre><b>GALERIES</b>{{etape.galeries}}</pre></div>
<div><pre><b>PARTIES</b>{{etape.parties}}</pre></div>
<div><pre><b>SAISON</b>{{etape.saison}}</pre></div>
<div><pre><b>THEMATIQUES</b>{{etape.thematiques}}</pre></div>
<div> <div>
<p>Étape n°{{etape.etape_number}}</p>
<p>Du {{etape.dates.value}} au {{ etape.dates.end_value }}</p>
</div> </div>
<img :src="etape.vignette.url" :alt="etape.vignette.alt">
</header>
<main>
<div v-for="partie in etape.parties">
<h3 v-html="partie.title"></h3>
<p v-html="partie.text"></p>
</div>
</main>
<!--
<div v-if="loading">Loading...</div>
<div v-if="error">{{ error }}</div>
-->
<div><pre>{{etape.href}}</pre></div>
<div><pre><b>GEOFIELD</b>{{etape.geofield}}</pre></div>
<div><pre><b>GALERIES</b>{{etape.galeries}}</pre></div>
<div><pre><b>PARTIES</b>{{etape.parties}}</pre></div>
<div><pre><b>SAISON</b>{{etape.saison}}</pre></div>
<div><pre><b>THEMATIQUES</b>{{etape.thematiques}}</pre></div>
<div>
</div> </div>
</div> </Transition>
<div v-if="page.title"> <Transition>
<header> <div v-if="page.title">
<h1>{{ page.title }}</h1> <header>
</header> <h1>{{ page.title }}</h1>
<main> </header>
<div v-html="page.text"></div> <main>
</main> <div v-html="page.text"></div>
</div> </main>
</div>
</Transition>
</template> </template>
<script setup> <script setup>
import { watch } from 'vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { useContentStore } from '../stores/content'; import { useContentStore } from '../stores/content';
@ -55,8 +60,33 @@
const { const {
loading, error, loading, error,
href,
etape, etape,
page, page,
} = storeToRefs(store); } = storeToRefs(store);
</script>
watch(() => href.value, (newHref) => {
if (newHref) {
history.pushState(null, '', newHref);
}
});
</script>
<style>
.v-enter-active,
.v-leave-active {
transition: all 0.3s ease;
}
.v-enter-from,
.v-leave-to {
transform: translateY(100%);
opacity: 0;
}
.v-leave-from {
transform: translateY(0%);
opacity: 1;
}
</style>

View File

@ -285,11 +285,15 @@ body{
top: 15vh; top: 15vh;
left: 25vw; left: 25vw;
width: 50vw; width: 50vw;
background-color: rgba(255,255,255,0.5); background-color: white;
img { img {
width: 100%; width: 100%;
height: auto; height: auto;
} }
> div {
width: 100%;
overflow: hidden;
}
} }
} }
} }