main.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. jQuery(function ($) {
  2. console.log('salut');
  3. // MENU BURGER
  4. const burger = document.getElementById("block-burger");
  5. const burgertitle = document.getElementById("block-burger-menu");
  6. if (burger && burgertitle) {
  7. burgertitle.addEventListener("click", function () {
  8. burger.classList.toggle('opened');
  9. });
  10. }
  11. // FAQ — réponses
  12. const answers = document.getElementsByClassName("field--name-field-reponse");
  13. const fichiers = document.getElementsByClassName("field--name-field-fichiers");
  14. const liens = document.getElementsByClassName("field--name-field-liens");
  15. const ressources = document.getElementsByClassName("field--name-field-ress");
  16. const questions = document.getElementsByClassName("field--name-field-question");
  17. for (let i = 0; i < questions.length; i++) {
  18. const q = questions[i];
  19. q.addEventListener("click", function () {
  20. // Réponses
  21. Array.from(answers).forEach(a => a.classList.remove("opened"));
  22. const r = this.parentNode.querySelector(".field--name-field-reponse");
  23. if (r) r.classList.add("opened");
  24. // Fichiers
  25. Array.from(fichiers).forEach(f => f.classList.remove("opened"));
  26. const f = this.parentNode.querySelector(".field--name-field-fichiers");
  27. if (f) f.classList.add("opened");
  28. // Liens
  29. Array.from(liens).forEach(l => l.classList.remove("opened"));
  30. const l = this.parentNode.querySelector(".field--name-field-liens");
  31. if (l) l.classList.add("opened");
  32. // Ressources
  33. Array.from(ressources).forEach(r => r.classList.remove("opened"));
  34. const res = this.parentNode.querySelector(".field--name-field-ress");
  35. if (res) res.classList.add("opened");
  36. });
  37. }
  38. // SLIDESHOW INIT
  39. $('.path-frontpage .view-actus-blocks-pages .view-content .view-type-slide .views-row-wrapper').slick({
  40. slidesToShow: 1,
  41. dots: true,
  42. arrows: true,
  43. centerMode: true,
  44. responsive: [{
  45. breakpoint: 810,
  46. settings: {
  47. slidesToShow: 1,
  48. adaptiveHeight: true,
  49. arrows: false,
  50. draggable: true,
  51. centerMode: true,
  52. }
  53. }]
  54. });
  55. $('.page-node-type-actualite .block-entity-fieldnodefield-images .field--type-image').slick({
  56. dots: true,
  57. arrows: true,
  58. adaptiveHeight: true,
  59. responsive: [{
  60. breakpoint: 800,
  61. settings: { adaptiveHeight: true }
  62. }]
  63. });
  64. $('.page-node-type-projet .block-entity-fieldnodefield-photo .field--type-image').slick({
  65. slidesToShow: 1,
  66. dots: true,
  67. arrows: false,
  68. draggable: true,
  69. adaptiveHeight: true,
  70. responsive: [{
  71. breakpoint: 800,
  72. settings: { adaptiveHeight: true }
  73. }]
  74. });
  75. ///// fusion views-type-slide de class identique ////////////
  76. const seen = new Set();
  77. $('.view-type-slide').each(function () {
  78. const $slide = $(this);
  79. const classes = $slide.attr('class').split(/\s+/);
  80. const typeClass = classes.find(cls => cls.startsWith('type-'));
  81. if (typeClass) {
  82. if (seen.has(typeClass)) {
  83. // Trouver le premier slide avec cette classe
  84. const $target = $('.view-type-slide.' + typeClass).first();
  85. // Déplacer les rows de la slide actuelle vers la première
  86. $slide.find('.views-row').appendTo($target.find('.views-row-wrapper'));
  87. // Supprimer la slide en double
  88. $slide.remove();
  89. } else {
  90. seen.add(typeClass);
  91. }
  92. }
  93. });
  94. document.addEventListener('DOMContentLoaded', () => {
  95. const wrapper = document.querySelector('.view-content');
  96. if (wrapper && !wrapper.classList.contains('grid-layout')) {
  97. $('.path-ressources .view:not(.view-partenaires) .view-content .view-type-slide .views-row-wrapper').slick({
  98. slidesToShow: 3,
  99. dots: false,
  100. arrows: true,
  101. infinite: false,
  102. centerMode: false,
  103. draggable: true,
  104. responsive: [{
  105. breakpoint: 810,
  106. settings: {
  107. slidesToShow: 3,
  108. arrows: false,
  109. draggable: true,
  110. centerMode: true,
  111. }
  112. }]
  113. });
  114. }
  115. });
  116. // Classes media → .wrapper-ressource
  117. $(".wrapper-ressource").each(function () {
  118. const media = $(this).find(".field--name-field-type-de-media").text().trim();
  119. const className = media
  120. .toLowerCase()
  121. .normalize("NFD").replace(/[\u0300-\u036f]/g, "")
  122. .replace(/[^a-z0-9]+/g, '-')
  123. .replace(/(^-|-$)/g, '');
  124. $(this).addClass('type-media-' + className);
  125. });
  126. console.log("classses media");
  127. // MASQUER TYPE DE RESSOURCE DOUBLON
  128. if (document.body.classList.contains("path-ressources")) {
  129. $(".view-type-slide").each(function () {
  130. const h3Content = $(this).find("h3").text().trim();
  131. console.log(h3Content);
  132. $(this).find(".field--name-field-type-de-ressource .field__item a").each(function () {
  133. if ($(this).text().trim() === h3Content) {
  134. $(this).hide();
  135. }
  136. });
  137. });
  138. }
  139. // Ouvrir les liens externes dans un nouvel onglet
  140. document.querySelectorAll('a[href^="http"]').forEach(link => {
  141. if (!link.href.includes(location.hostname)) {
  142. link.setAttribute('target', '_blank');
  143. link.setAttribute('rel', 'noopener noreferrer');
  144. }
  145. });
  146. // Scroll automatique au filtre
  147. if (document.body.classList.contains("path-projets")) {
  148. const form = document.querySelector(".views-exposed-form");
  149. if (form) form.setAttribute("action", form.action.split("#")[0] + "#filtres");
  150. if (window.location.hash === "#filtres") {
  151. const target = document.getElementById("filtres");
  152. if (target) {
  153. const offset = 300;
  154. const top = target.getBoundingClientRect().top + window.pageYOffset - offset;
  155. window.scrollTo({ top: top, behavior: "smooth" });
  156. }
  157. }
  158. }
  159. });
  160. /////////////////diaporama ressource //////////
  161. document.addEventListener('DOMContentLoaded', function () {
  162. // Attendre que les éléments HTML soient bien présents
  163. const interval = setInterval(() => {
  164. const mainImage = document.getElementById('mainImage');
  165. const prevArrow = document.getElementById('prevArrow');
  166. const nextArrow = document.getElementById('nextArrow');
  167. const caption = document.getElementById('caption');
  168. const thumbsContainer = document.getElementById('thumbnails');
  169. const imagesInDom = document.querySelectorAll('.carousel-items .carousel-item img');
  170. if (mainImage && prevArrow && nextArrow && caption && thumbsContainer && imagesInDom) {
  171. clearInterval(interval); // Tous les éléments sont là, on lance le carrousel
  172. initCarousel({ mainImage, prevArrow, nextArrow, caption, thumbsContainer });
  173. }
  174. }, 100); // vérifie toutes les 100ms
  175. });
  176. function initCarousel({ mainImage, prevArrow, nextArrow, caption, thumbsContainer }) {
  177. const images = [];
  178. document.querySelectorAll('.carousel-items .carousel-item img').forEach((img) => {
  179. images.push({
  180. src: img.getAttribute('src'),
  181. caption: img.getAttribute('alt') || 'Image sans légende'
  182. });
  183. });
  184. console.log('Images chargées pour le carrousel :', images);
  185. if (!images.length) return;
  186. let currentIndex = 0;
  187. function showImage(index) {
  188. mainImage.src = images[index].src;
  189. caption.textContent = images[index].caption;
  190. const thumbnails = document.querySelectorAll('.thumbnails img');
  191. thumbnails.forEach(img => img.classList.remove('active'));
  192. if (thumbnails[index]) {
  193. thumbnails[index].classList.add('active');
  194. }
  195. }
  196. prevArrow.addEventListener('click', () => {
  197. currentIndex = (currentIndex - 1 + images.length) % images.length;
  198. showImage(currentIndex);
  199. });
  200. nextArrow.addEventListener('click', () => {
  201. currentIndex = (currentIndex + 1) % images.length;
  202. showImage(currentIndex);
  203. });
  204. images.forEach((img, index) => {
  205. const thumb = document.createElement('img');
  206. thumb.src = img.src;
  207. thumb.alt = img.caption;
  208. thumb.onclick = () => {
  209. currentIndex = index;
  210. showImage(index);
  211. };
  212. thumbsContainer.appendChild(thumb);
  213. });
  214. showImage(currentIndex);
  215. const thumbPrev = document.getElementById('thumbPrev');
  216. const thumbNext = document.getElementById('thumbNext');
  217. thumbPrev.addEventListener('click', () => {
  218. thumbsContainer.scrollBy({ left: -150, behavior: 'smooth' });
  219. });
  220. thumbNext.addEventListener('click', () => {
  221. thumbsContainer.scrollBy({ left: 150, behavior: 'smooth' });
  222. });
  223. }