2024-07-15 16:34:28 +02:00
|
|
|
import { createApp } from 'vue'
|
2024-07-23 00:01:44 +02:00
|
|
|
import { createPinia } from 'pinia'
|
2024-07-15 16:34:28 +02:00
|
|
|
import '../scss/main.scss'
|
2024-07-31 00:33:21 +02:00
|
|
|
import Modale from './vuejs/Modale.vue'
|
2024-07-15 16:34:28 +02:00
|
|
|
|
2024-09-29 21:36:21 +02:00
|
|
|
import VueImageZoomer from 'vue-image-zoomer'
|
|
|
|
import 'vue-image-zoomer/dist/style.css';
|
|
|
|
|
2024-07-31 00:33:21 +02:00
|
|
|
import { useContentStore } from './stores/content';
|
2024-08-05 21:08:09 +02:00
|
|
|
import router from './router/router';
|
2024-07-15 16:34:28 +02:00
|
|
|
|
2024-07-23 00:01:44 +02:00
|
|
|
// Working with the history API
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API
|
2024-07-10 16:16:51 +02:00
|
|
|
|
2024-07-16 17:01:09 +02:00
|
|
|
// /**
|
|
|
|
// * @file
|
|
|
|
// * reha behaviors.
|
|
|
|
// * https://www.drupal.org/docs/drupal-apis/javascript-api/javascript-api-overview
|
|
|
|
// */
|
|
|
|
// (function (Drupal) {
|
2024-07-10 16:16:51 +02:00
|
|
|
|
2024-07-16 17:01:09 +02:00
|
|
|
// 'use strict';
|
|
|
|
|
|
|
|
// Drupal.behaviors.reha = {
|
|
|
|
// attach: function (context, settings) {
|
|
|
|
// console.log('It works!');
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// } (Drupal));
|
|
|
|
|
2024-10-01 11:40:10 +02:00
|
|
|
(function ($, Drupal, drupalSettings) {
|
2024-07-16 17:01:09 +02:00
|
|
|
const CaravaneTheme = function () {
|
|
|
|
const _is_front = drupalSettings.path.isFront
|
|
|
|
console.log('drupalSettings', drupalSettings)
|
|
|
|
|
|
|
|
// let _I18n
|
|
|
|
|
|
|
|
// ___ _ _
|
|
|
|
// |_ _|_ _ (_) |_
|
|
|
|
// | || ' \| | _|
|
|
|
|
// |___|_||_|_|\__|
|
|
|
|
function init () {
|
|
|
|
console.log('CaravaneTheme init()')
|
|
|
|
initVues()
|
2024-07-29 23:39:35 +02:00
|
|
|
toggleMenu()
|
2024-07-16 17:01:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function initVues(){
|
2024-07-31 00:33:21 +02:00
|
|
|
initVueContentModale();
|
2024-07-16 17:01:09 +02:00
|
|
|
}
|
|
|
|
|
2024-07-31 00:33:21 +02:00
|
|
|
function initVueContentModale(){
|
2024-09-29 21:36:21 +02:00
|
|
|
const app = createApp(Modale)
|
|
|
|
.use(createPinia()).use(router)
|
|
|
|
.use(VueImageZoomer);
|
2024-07-31 00:33:21 +02:00
|
|
|
const store = useContentStore();
|
|
|
|
app.mount('#content-modale');
|
2024-07-10 16:16:51 +02:00
|
|
|
|
2024-07-23 00:01:44 +02:00
|
|
|
processEtapeLinks(store);
|
2024-08-09 17:04:53 +02:00
|
|
|
processStaticLinks(store);
|
|
|
|
|
|
|
|
setupEtapeMapPopup(store);
|
2024-07-10 16:16:51 +02:00
|
|
|
}
|
|
|
|
|
2024-07-16 17:01:09 +02:00
|
|
|
|
2024-07-31 00:33:21 +02:00
|
|
|
function onClickContentLink(e, store, category){
|
2024-07-16 17:01:09 +02:00
|
|
|
e.preventDefault();
|
2024-08-09 17:04:53 +02:00
|
|
|
let a;
|
|
|
|
|
|
|
|
const li = e.target.closest('li');
|
|
|
|
a = li.querySelector('a');
|
|
|
|
|
2024-07-16 17:01:09 +02:00
|
|
|
let nid = a.dataset.nodeNid;
|
|
|
|
|
2024-07-31 00:33:21 +02:00
|
|
|
if (category === 'etape') {
|
|
|
|
store.fetchEtapeData(nid);
|
|
|
|
} else if (category === 'static') {
|
|
|
|
store.fetchStaticData(nid);
|
|
|
|
}
|
2024-07-16 17:01:09 +02:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-07-31 00:33:21 +02:00
|
|
|
function processStaticLinks(store){
|
2024-07-31 02:13:40 +02:00
|
|
|
let general_link_fields = document.querySelectorAll('#menu > ul > li:not(:first-of-type) > a');
|
2024-07-31 00:33:21 +02:00
|
|
|
for (let field of general_link_fields) {
|
|
|
|
let general_link_href = field.getAttribute('href');
|
|
|
|
const nid = general_link_href.charAt(general_link_href.length-1);
|
|
|
|
field.setAttribute('data-node-nid', nid);
|
|
|
|
field.addEventListener('click', (e) => onClickContentLink(e, store, 'static'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-16 17:01:09 +02:00
|
|
|
|
2024-07-23 00:01:44 +02:00
|
|
|
function processEtapeLinks(store){
|
2024-08-09 17:04:53 +02:00
|
|
|
let etape_li = document.querySelectorAll('#etapes-liste li');
|
|
|
|
etape_li.forEach((li) => {
|
|
|
|
let field = li.querySelector('div.views-field-title');
|
2024-07-16 17:01:09 +02:00
|
|
|
let nid = null;
|
|
|
|
let classList = field.classList;
|
|
|
|
classList.forEach((classe) => {
|
|
|
|
let reg = /data-node-(\d+)/;
|
|
|
|
let result = classe.match(reg);
|
|
|
|
if (result) {
|
|
|
|
nid = result[1];
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (nid) {
|
|
|
|
let a = field.querySelector('a');
|
|
|
|
a.setAttribute('data-node-nid', nid);
|
2024-08-09 17:04:53 +02:00
|
|
|
li.addEventListener('click', (e) => onClickContentLink(e, store, 'etape'));
|
2024-07-16 17:01:09 +02:00
|
|
|
}
|
2024-08-09 17:04:53 +02:00
|
|
|
let couleur = li.querySelector('.views-field-field-couleur .snippets-description').innerText;
|
|
|
|
let iconElements = li.querySelectorAll('.icone-arret > div');
|
|
|
|
for (let element of iconElements) {
|
|
|
|
element.style.backgroundColor = couleur;
|
|
|
|
}
|
|
|
|
|
2024-07-29 23:39:35 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleMenu() {
|
|
|
|
const menuButton = document.querySelector('#block-caravane-mainnavigation > #menu');
|
|
|
|
const menuContainer = document.querySelector('#block-caravane-mainnavigation > #menu > ul');
|
|
|
|
const menuTitle = document.querySelector('#menu-title');
|
|
|
|
const menuBurger = document.querySelector('#hamburger');
|
|
|
|
const menuH2 = document.querySelector('#menu > h2');
|
2024-07-31 02:13:40 +02:00
|
|
|
menuButton.addEventListener('click', (e) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
menuContainer.classList.toggle('open');
|
|
|
|
menuTitle.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');
|
|
|
|
}
|
2024-07-16 17:01:09 +02:00
|
|
|
})
|
|
|
|
}
|
2024-08-09 17:04:53 +02:00
|
|
|
|
|
|
|
function setupEtapeMapPopup(store) {
|
2024-10-01 11:40:10 +02:00
|
|
|
Drupal.behaviors.customLeafletInteraction = {
|
|
|
|
attach: function(context, settings) {
|
|
|
|
$(context).on('leafletMapInit', function (e, settings, map, mapid, markers) {
|
|
|
|
const icons = document.querySelectorAll('.leaflet-map-divicon');
|
|
|
|
for (let icon of icons) {
|
|
|
|
const colorContainer = icon.querySelector('.couleur');
|
|
|
|
const colorDiv = colorContainer.querySelector('div > div:nth-of-type(4)');
|
|
|
|
const color = colorDiv.innerText.substring(colorDiv.innerText.indexOf('>') + 1, colorDiv.innerText.indexOf('<', colorDiv.innerText.indexOf('>') + 1)).trim();
|
|
|
|
console.log(color);
|
|
|
|
|
|
|
|
|
|
|
|
const nid = icon.querySelector('.nid');
|
|
|
|
const nidValue = nid.querySelector('div > div').innerText;
|
|
|
|
|
|
|
|
icon.addEventListener('click', function(event) {
|
|
|
|
store.fetchEtapeData(nidValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
colorContainer.remove();
|
|
|
|
nid.remove();
|
|
|
|
const iconElements = icon.querySelectorAll('div');
|
|
|
|
for (let iconElement of iconElements) {
|
|
|
|
iconElement.style.backgroundColor = color;
|
|
|
|
}
|
|
|
|
icon.removeAttribute('title');
|
|
|
|
|
|
|
|
icon.addEventListener('mouseenter', function (event) {
|
|
|
|
icon.style.transform = `${icon.style.transform} scale(1.1)`;
|
|
|
|
const popup = document.querySelector('.leaflet-tooltip-center > div');
|
|
|
|
popup.style.opacity = "1";
|
|
|
|
});
|
|
|
|
|
|
|
|
icon.addEventListener('mouseleave', function (event) {
|
|
|
|
icon.style.transform = icon.style.transform.split(' ')[0] + icon.style.transform.split(' ')[1] + icon.style.transform.split(' ')[2];
|
|
|
|
})
|
|
|
|
}
|
2024-08-09 17:04:53 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2024-10-01 11:40:10 +02:00
|
|
|
}
|
2024-08-09 17:04:53 +02:00
|
|
|
}
|
2024-07-16 17:01:09 +02:00
|
|
|
|
|
|
|
init()
|
|
|
|
} // end CaravaneTheme()
|
|
|
|
|
|
|
|
CaravaneTheme()
|
2024-10-01 11:40:10 +02:00
|
|
|
})(jQuery, Drupal, drupalSettings)
|