195 lines
6.2 KiB
JavaScript
195 lines
6.2 KiB
JavaScript
jQuery(function ($) {
|
|
console.log('salut');
|
|
|
|
// MENU BURGER
|
|
const burger = document.getElementById("block-burger");
|
|
const burgertitle = document.getElementById("block-burger-menu");
|
|
if (burger && burgertitle) {
|
|
burgertitle.addEventListener("click", function () {
|
|
burger.classList.toggle('opened');
|
|
});
|
|
}
|
|
|
|
// FAQ — réponses
|
|
const answers = document.getElementsByClassName("field--name-field-reponse");
|
|
const fichiers = document.getElementsByClassName("field--name-field-fichiers");
|
|
const liens = document.getElementsByClassName("field--name-field-liens");
|
|
const ressources = document.getElementsByClassName("field--name-field-ress");
|
|
const questions = document.getElementsByClassName("field--name-field-question");
|
|
|
|
for (let i = 0; i < questions.length; i++) {
|
|
const q = questions[i];
|
|
q.addEventListener("click", function () {
|
|
// Réponses
|
|
Array.from(answers).forEach(a => a.classList.remove("opened"));
|
|
const r = this.parentNode.querySelector(".field--name-field-reponse");
|
|
if (r) r.classList.add("opened");
|
|
|
|
// Fichiers
|
|
Array.from(fichiers).forEach(f => f.classList.remove("opened"));
|
|
const f = this.parentNode.querySelector(".field--name-field-fichiers");
|
|
if (f) f.classList.add("opened");
|
|
|
|
// Liens
|
|
Array.from(liens).forEach(l => l.classList.remove("opened"));
|
|
const l = this.parentNode.querySelector(".field--name-field-liens");
|
|
if (l) l.classList.add("opened");
|
|
|
|
// Ressources
|
|
Array.from(ressources).forEach(r => r.classList.remove("opened"));
|
|
const res = this.parentNode.querySelector(".field--name-field-ress");
|
|
if (res) res.classList.add("opened");
|
|
});
|
|
}
|
|
|
|
// SLIDESHOW INIT
|
|
$('.path-frontpage .view-actus-blocks-pages .view-content .view-type-slide .views-row-wrapper').slick({
|
|
slidesToShow: 1,
|
|
dots: true,
|
|
arrows: true,
|
|
centerMode: true,
|
|
responsive: [{
|
|
breakpoint: 810,
|
|
settings: {
|
|
slidesToShow: 1,
|
|
adaptiveHeight: true,
|
|
arrows: false,
|
|
draggable: true,
|
|
centerMode: true,
|
|
}
|
|
}]
|
|
});
|
|
|
|
$('.page-node-type-actualite .block-entity-fieldnodefield-images .field--type-image').slick({
|
|
dots: true,
|
|
arrows: true,
|
|
adaptiveHeight: true,
|
|
responsive: [{
|
|
breakpoint: 800,
|
|
settings: { adaptiveHeight: true }
|
|
}]
|
|
});
|
|
|
|
$('.page-node-type-projet .block-entity-fieldnodefield-photo .field--type-image').slick({
|
|
slidesToShow: 1,
|
|
dots: true,
|
|
arrows: false,
|
|
draggable: true,
|
|
adaptiveHeight: true,
|
|
responsive: [{
|
|
breakpoint: 800,
|
|
settings: { adaptiveHeight: true }
|
|
}]
|
|
});
|
|
|
|
// Classes media → .wrapper-ressource
|
|
$(".wrapper-ressource").each(function () {
|
|
const media = $(this).find(".field--name-field-type-de-media").text().trim();
|
|
const className = media
|
|
.toLowerCase()
|
|
.normalize("NFD").replace(/[\u0300-\u036f]/g, "")
|
|
.replace(/[^a-z0-9]+/g, '-')
|
|
.replace(/(^-|-$)/g, '');
|
|
$(this).addClass('type-media-' + className);
|
|
});
|
|
|
|
// SLIDES RECONSTRUCTION LORS DU CHARGEMENT COMPLET
|
|
$(window).on('load', function () {
|
|
const $viewContent = $('.path-ressources .view-content').first();
|
|
if ($viewContent.length === 0) return;
|
|
$viewContent.addClass('view-ressources-hidden');
|
|
|
|
const allowedTypes = [
|
|
'type-publication-issue-du-programme-eqld',
|
|
'type-paroles-de-laureats',
|
|
'type-les-projets-en-images',
|
|
'type-presse'
|
|
];
|
|
|
|
// const $viewContent = $('.view-content');
|
|
const allRows = $('.path-ressources .view-base-de-donnees .views-row').detach();
|
|
function toLabel(str) {
|
|
return str.replace('type-', '').replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
|
|
}
|
|
allowedTypes.forEach(type => {
|
|
const label = toLabel(type);
|
|
const $slide = $(`
|
|
<div class="view-type-slide ${type}">
|
|
<h3 class="${type}">${label}</h3>
|
|
<div class="views-row-wrapper"></div>
|
|
</div>
|
|
`);
|
|
$viewContent.append($slide);
|
|
});
|
|
|
|
allRows.each(function () {
|
|
const $row = $(this);
|
|
const classList = $row.attr('class').split(/\s+/);
|
|
classList.forEach(cls => {
|
|
if (allowedTypes.includes(cls)) {
|
|
$(`.view-type-slide.${cls} .views-row-wrapper`).append($row.clone(true, true));
|
|
}
|
|
});
|
|
});
|
|
|
|
$('.path-ressources .view:not(.view-partenaires) .view-content .view-type-slide .views-row-wrapper').slick({
|
|
slidesToShow: 3,
|
|
dots: false,
|
|
arrows: true,
|
|
infinite: false,
|
|
centerMode: false,
|
|
responsive: [{
|
|
breakpoint: 810,
|
|
settings: {
|
|
slidesToShow: 3,
|
|
arrows: false,
|
|
draggable: true,
|
|
centerMode: true,
|
|
}
|
|
}]
|
|
});
|
|
// Supprimer les .view-type-slide originales générées par Drupal (vides ou non autorisées)
|
|
$('.path-ressources .view-base-de-donnees .view-type-slide').each(function () {
|
|
const classes = $(this).attr('class').split(/\s+/);
|
|
const isCustom = classes.some(cls => allowedTypes.includes(cls));
|
|
if (!isCustom) {
|
|
$(this).remove();
|
|
}
|
|
});
|
|
|
|
$viewContent.removeClass('view-ressources-hidden');
|
|
|
|
});
|
|
|
|
// Ouvrir les liens externes dans un nouvel onglet
|
|
document.querySelectorAll('a[href^="http"]').forEach(link => {
|
|
if (!link.href.includes(location.hostname)) {
|
|
link.setAttribute('target', '_blank');
|
|
link.setAttribute('rel', 'noopener noreferrer');
|
|
}
|
|
});
|
|
|
|
// Scroll automatique au filtre
|
|
const form = document.querySelector(".views-exposed-form");
|
|
if (form) form.setAttribute("action", form.action.split("#")[0] + "#filtres");
|
|
|
|
if (window.location.hash === "#filtres") {
|
|
const target = document.getElementById("filtres");
|
|
if (target) {
|
|
const offset = 300;
|
|
const top = target.getBoundingClientRect().top + window.pageYOffset - offset;
|
|
window.scrollTo({ top: top, behavior: "smooth" });
|
|
}
|
|
}
|
|
|
|
// MASQUER TYPE DE RESSOURCE DOUBLON
|
|
$(".view-type-slide").each(function () {
|
|
const h3Content = $(this).find("h3").text().trim();
|
|
$(this).find(".field--name-field-type-de-ressource").each(function () {
|
|
if ($(this).text().trim() === h3Content) {
|
|
$(this).hide();
|
|
}
|
|
});
|
|
});
|
|
});
|