From 9bf84290ac495bd717d94baca0217f7e101f98ec Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 14 Nov 2024 02:31:10 +0100 Subject: [PATCH] toggle animations --- .../custom/caravane/assets/js/stores/map.js | 56 ++++++--- .../assets/js/utils/set-active-nav-item.js | 6 +- .../caravane/assets/js/utils/vue-setup.js | 17 ++- .../assets/js/vuejs/AnimationToggle.vue | 37 ++++++ .../caravane/assets/js/vuejs/Modale.vue | 109 ++++++++++++------ .../js/vuejs/components/ModaleFooter.vue | 19 ++- .../custom/caravane/assets/scss/main.scss | 92 +++++++++++++-- .../layout--threecol-25-50-25.html.twig | 1 + 8 files changed, 258 insertions(+), 79 deletions(-) create mode 100644 web/themes/custom/caravane/assets/js/vuejs/AnimationToggle.vue diff --git a/web/themes/custom/caravane/assets/js/stores/map.js b/web/themes/custom/caravane/assets/js/stores/map.js index fb26011..613de31 100644 --- a/web/themes/custom/caravane/assets/js/stores/map.js +++ b/web/themes/custom/caravane/assets/js/stores/map.js @@ -10,23 +10,32 @@ export const useMapStore = defineStore('mapState', { currentPlace: Object, maxZoom: Number, currentZoom: Number, - duration: 3, + animationsAreEnabled: true, + animationDuration: 3, }), actions: { zoomToPlace(lat, long) { if (useLayoutStore().isDesktop) long = long - 0.03; - this.map.flyTo([lat, long], this.maxZoom, { duration: this.duration }); - this.currentZoom = this.maxZoom; + this.map.flyTo( + [lat, long], + this.maxZoom, + { animate: this.animationsAreEnabled, animationDuration: this.animationDuration }); + this.currentZoom = this.maxZoom; }, resetMap() { - this.map.flyTo(this.defaultMapCenter, useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile, { duration: this.duration }); + console.log(this.defaultMapCenter); + + this.map.flyTo( + this.defaultMapCenter, + useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile, + { animate: this.animationsAreEnabled, animationDuration: this.animationDuration }); this.currentZoom = useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile; }, lockMap() { setTimeout(() => { this.map.options.minZoom = this.currentZoom; this.map.options.maxZoom = this.currentZoom; - }, this.duration * 1000 + 100); + }, this.animationDuration * 1000 + 100); this.map.dragging.disable(); this.map.touchZoom.disable(); this.map.doubleClickZoom.disable(); @@ -34,17 +43,28 @@ export const useMapStore = defineStore('mapState', { this.map.boxZoom.disable(); this.map.keyboard.disable(); // map.tap.disable(); - }, - unlockMap() { - this.map.options.minZoom = useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile; - this.map.options.maxZoom = this.maxZoom; - this.map.dragging.enable(); - this.map.touchZoom.enable(); - this.map.doubleClickZoom.enable(); - this.map.scrollWheelZoom.enable(); - this.map.boxZoom.enable(); - this.map.keyboard.enable(); - // map.tap.enable(); - }, + }, + unlockMap() { + this.map.options.minZoom = useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile; + this.map.options.maxZoom = this.maxZoom; + this.map.dragging.enable(); + this.map.touchZoom.enable(); + this.map.doubleClickZoom.enable(); + this.map.scrollWheelZoom.enable(); + this.map.boxZoom.enable(); + this.map.keyboard.enable(); + // map.tap.enable(); + }, + toggleAnimation() { + this.animationsAreEnabled = !this.animationsAreEnabled; + }, + checkReducedMotion() { + const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)'); + this.animationsAreEnabled = !mediaQuery.matches; + + mediaQuery.addEventListener('change', (event) => { + this.animationsAreEnabled = !event.matches; + }); + }, }, -}); \ No newline at end of file +}); diff --git a/web/themes/custom/caravane/assets/js/utils/set-active-nav-item.js b/web/themes/custom/caravane/assets/js/utils/set-active-nav-item.js index fa18a08..26509c5 100644 --- a/web/themes/custom/caravane/assets/js/utils/set-active-nav-item.js +++ b/web/themes/custom/caravane/assets/js/utils/set-active-nav-item.js @@ -1,7 +1,7 @@ export function setActiveNavItem(contentType, href) { const staticNavItems = document.querySelectorAll('#menu > ul > li > a'); const etapeNavItems = document.querySelectorAll('#etapes-liste li a'); - + for (let item of staticNavItems) { item.classList.remove('is-active'); } @@ -15,7 +15,7 @@ export function setActiveNavItem(contentType, href) { for (let item of etapeNavItems) { item.closest('li').classList.remove('inactive'); } - + } else { if (contentType === 'static') { for (let item of staticNavItems) { @@ -32,4 +32,4 @@ export function setActiveNavItem(contentType, href) { } } -} \ No newline at end of file +} diff --git a/web/themes/custom/caravane/assets/js/utils/vue-setup.js b/web/themes/custom/caravane/assets/js/utils/vue-setup.js index e0cf6d2..6e9b286 100644 --- a/web/themes/custom/caravane/assets/js/utils/vue-setup.js +++ b/web/themes/custom/caravane/assets/js/utils/vue-setup.js @@ -2,6 +2,7 @@ import { createApp } from 'vue'; import { createPinia } from 'pinia'; import router from '../router/router'; import Modale from '../vuejs/Modale.vue'; +import AnimationToggle from '../vuejs/AnimationToggle.vue'; import VueImageZoomer from 'vue-image-zoomer'; import 'vue-image-zoomer/dist/style.css'; @@ -9,14 +10,20 @@ import { useContentStore } from '../stores/content'; import { useMapStore } from '../stores/map'; export function initVueContentModale() { + const pinia = createPinia(); + const app = createApp(Modale) - .use(createPinia()) - .use(router) - .use(VueImageZoomer); + .use(pinia) + .use(router) + .use(VueImageZoomer); const store = useContentStore(); const mapStore = useMapStore(); - app.mount('#content-modale'); + app.mount('#content-modale'); + + const animationToggle = createApp(AnimationToggle) + .use(pinia) + .mount('#animation-toggle'); return { store, mapStore, router }; -} \ No newline at end of file +} diff --git a/web/themes/custom/caravane/assets/js/vuejs/AnimationToggle.vue b/web/themes/custom/caravane/assets/js/vuejs/AnimationToggle.vue new file mode 100644 index 0000000..d34e712 --- /dev/null +++ b/web/themes/custom/caravane/assets/js/vuejs/AnimationToggle.vue @@ -0,0 +1,37 @@ + + + diff --git a/web/themes/custom/caravane/assets/js/vuejs/Modale.vue b/web/themes/custom/caravane/assets/js/vuejs/Modale.vue index 079b7fa..a37488e 100644 --- a/web/themes/custom/caravane/assets/js/vuejs/Modale.vue +++ b/web/themes/custom/caravane/assets/js/vuejs/Modale.vue @@ -1,5 +1,8 @@