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);
@ -116,10 +123,20 @@ import { useContentStore } from './stores/content';
const menuH2 = document.querySelector('#menu > h2'); const menuH2 = document.querySelector('#menu > h2');
menuButton.addEventListener('click', (e) => { menuButton.addEventListener('click', (e) => {
// e.preventDefault(); // e.preventDefault();
setTimeout(() => {
menuContainer.classList.toggle('open'); menuContainer.classList.toggle('open');
menuTitle.classList.toggle('open'); menuTitle.classList.toggle('open');
menuBurger.classList.toggle('open'); menuBurger.classList.toggle('open');
menuH2.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

@ -3,8 +3,8 @@ import REST from '../api/rest-axios';
export const useContentStore = defineStore('content', { export const useContentStore = defineStore('content', {
state: () => ({ state: () => ({
etape: {
href: '', href: '',
etape: {
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,4 +1,5 @@
<template> <template>
<Transition>
<div v-if="etape.etape_number"> <div v-if="etape.etape_number">
<header> <header>
<h1>{{etape.adresse.locality}}, {{ etape.adresse.postal_code }}</h1> <h1>{{etape.adresse.locality}}, {{ etape.adresse.postal_code }}</h1>
@ -19,12 +20,12 @@
<!-- <!--
<div v-if="loading">Loading...</div> <div v-if="loading">Loading...</div>
<div v-if="error">{{ error }}</div> <div v-if="error">{{ error }}</div>
--> -->
<div><pre>{{etape.href}}</pre></div> <div><pre>{{href}}</pre></div>
<div><pre><b>GEOFIELD</b>{{etape.geofield}}</pre></div> <div><pre><b>GEOFIELD</b>{{etape.geofield}}</pre></div>
@ -37,6 +38,8 @@
<div> <div>
</div> </div>
</div> </div>
</Transition>
<Transition>
<div v-if="page.title"> <div v-if="page.title">
<header> <header>
<h1>{{ page.title }}</h1> <h1>{{ page.title }}</h1>
@ -45,9 +48,11 @@
<div v-html="page.text"></div> <div v-html="page.text"></div>
</main> </main>
</div> </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);
watch(() => href.value, (newHref) => {
if (newHref) {
history.pushState(null, '', newHref);
}
});
</script> </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;
}
} }
} }
} }