main.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. if (!$('.view-content').hasClass('filtered')) {
  95. $('.path-ressources .view:not(.view-partenaires) .view-content .view-type-slide .views-row-wrapper').slick({
  96. slidesToShow: 3,
  97. dots: false,
  98. arrows: true,
  99. infinite: false,
  100. centerMode: false,
  101. draggable: true,
  102. responsive: [{
  103. breakpoint: 810,
  104. settings: {
  105. slidesToShow: 3,
  106. arrows: true,
  107. draggable: true,
  108. centerMode: false,
  109. }
  110. }]
  111. });
  112. }
  113. // Classes media → .wrapper-ressource
  114. $(".wrapper-ressource").each(function () {
  115. const media = $(this).find(".field--name-field-type-de-media").text().trim();
  116. const className = media
  117. .toLowerCase()
  118. .normalize("NFD").replace(/[\u0300-\u036f]/g, "")
  119. .replace(/[^a-z0-9]+/g, '-')
  120. .replace(/(^-|-$)/g, '');
  121. $(this).addClass('type-media-' + className);
  122. });
  123. console.log("classses media");
  124. // MASQUER TYPE DE RESSOURCE DOUBLON
  125. if (document.body.classList.contains("path-ressources")) {
  126. $(".view-type-slide").each(function () {
  127. const h3Content = $(this).find("h3").text().trim();
  128. console.log(h3Content);
  129. $(this).find(".field--name-field-type-de-ressource .field__item a").each(function () {
  130. if ($(this).text().trim() === h3Content) {
  131. $(this).hide();
  132. }
  133. });
  134. });
  135. }
  136. // Ouvrir les liens externes dans un nouvel onglet
  137. document.querySelectorAll('a[href^="http"]').forEach(link => {
  138. if (!link.href.includes(location.hostname)) {
  139. link.setAttribute('target', '_blank');
  140. link.setAttribute('rel', 'noopener noreferrer');
  141. }
  142. });
  143. // Scroll automatique au filtre
  144. if (document.body.classList.contains("path-projets")) {
  145. const form = document.querySelector(".views-exposed-form");
  146. if (form) form.setAttribute("action", form.action.split("#")[0] + "#filtres");
  147. if (window.location.hash === "#filtres") {
  148. const target = document.getElementById("filtres");
  149. if (target) {
  150. const offset = 300;
  151. const top = target.getBoundingClientRect().top + window.pageYOffset - offset;
  152. window.scrollTo({ top: top, behavior: "smooth" });
  153. }
  154. }
  155. }
  156. });
  157. /////////////////diaporama ressource //////////
  158. document.addEventListener('DOMContentLoaded', function () {
  159. // Attendre que les éléments HTML soient bien présents
  160. const interval = setInterval(() => {
  161. const mainImage = document.getElementById('mainImage');
  162. const prevArrow = document.getElementById('prevArrow');
  163. const nextArrow = document.getElementById('nextArrow');
  164. const caption = document.getElementById('caption');
  165. const thumbsContainer = document.getElementById('thumbnails');
  166. const imagesInDom = document.querySelectorAll('.carousel-items .carousel-item img');
  167. if (mainImage && prevArrow && nextArrow && caption && thumbsContainer && imagesInDom) {
  168. clearInterval(interval); // Tous les éléments sont là, on lance le carrousel
  169. initCarousel({ mainImage, prevArrow, nextArrow, caption, thumbsContainer });
  170. }
  171. }, 100); // vérifie toutes les 100ms
  172. });
  173. function initCarousel({ mainImage, prevArrow, nextArrow, caption, thumbsContainer }) {
  174. const images = [];
  175. document.querySelectorAll('.carousel-items .carousel-item img').forEach((img) => {
  176. images.push({
  177. src: img.getAttribute('src'),
  178. caption: img.getAttribute('alt') || 'Image sans légende'
  179. });
  180. });
  181. console.log('Images chargées pour le carrousel :', images);
  182. if (!images.length) return;
  183. let currentIndex = 0;
  184. function showImage(index) {
  185. mainImage.src = images[index].src;
  186. caption.textContent = images[index].caption;
  187. const thumbnails = document.querySelectorAll('.thumbnails img');
  188. thumbnails.forEach(img => img.classList.remove('active'));
  189. if (thumbnails[index]) {
  190. thumbnails[index].classList.add('active');
  191. }
  192. }
  193. prevArrow.addEventListener('click', () => {
  194. currentIndex = (currentIndex - 1 + images.length) % images.length;
  195. showImage(currentIndex);
  196. });
  197. nextArrow.addEventListener('click', () => {
  198. currentIndex = (currentIndex + 1) % images.length;
  199. showImage(currentIndex);
  200. });
  201. images.forEach((img, index) => {
  202. const thumb = document.createElement('img');
  203. thumb.src = img.src;
  204. thumb.alt = img.caption;
  205. thumb.onclick = () => {
  206. currentIndex = index;
  207. showImage(index);
  208. };
  209. thumbsContainer.appendChild(thumb);
  210. });
  211. showImage(currentIndex);
  212. const thumbPrev = document.getElementById('thumbPrev');
  213. const thumbNext = document.getElementById('thumbNext');
  214. thumbPrev.addEventListener('click', () => {
  215. thumbsContainer.scrollBy({ left: -150, behavior: 'smooth' });
  216. });
  217. thumbNext.addEventListener('click', () => {
  218. thumbsContainer.scrollBy({ left: 150, behavior: 'smooth' });
  219. });
  220. }
  221. //////////////////////////start classe en JS si des filtres sont présents///////////
  222. document.addEventListener('DOMContentLoaded', () => {
  223. if (window.location.search.length > 0) {
  224. document.querySelector('.view-content')?.classList.add('filtered');
  225. document.querySelectorAll('.tout-voir').forEach(btn => btn.remove());
  226. }
  227. });