main.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. console.log('salut');
  2. // menu burger open
  3. var burger = document.getElementById("block-burger");
  4. var burgertitle = document.getElementById("block-burger-menu");
  5. burgertitle.addEventListener("click", toggleMenu);
  6. function toggleMenu(event) {
  7. console.log(event);
  8. burger.classList.toggle('opened');
  9. }
  10. //////////////////////////
  11. // faq reponse open
  12. var answers = document.getElementsByClassName("field--name-field-reponse");
  13. var fichiers = document.getElementsByClassName("field--name-field-fichiers");
  14. var questions = document.getElementsByClassName("field--name-field-question");
  15. for (let i = 0; i < questions.length; i++) {
  16. const question = questions[i]
  17. question.addEventListener("click", toggleFaq);
  18. }
  19. function toggleFaq(event) {
  20. console.log(event, this);
  21. // fermé tout
  22. for (let i = 0; i < answers.length; i++) {
  23. answers[i].classList.remove('opened');
  24. }
  25. // la réponse correspndante a la question clické
  26. // | this c'est l'élément sur le quel on a clické
  27. // | |le parent |la réponse dans le parent
  28. let answer = this.parentNode.querySelector('.field--name-field-reponse');
  29. // console.log(answer);
  30. answer.classList.add('opened');
  31. }
  32. ///// répète fonction pour les fichiers, les liens et ressources
  33. //// il faudrait créer un tableau d'objet ?
  34. var fichiers = document.getElementsByClassName("field--name-field-fichiers");
  35. var questions = document.getElementsByClassName("field--name-field-question");
  36. for (let i = 0; i < questions.length; i++) {
  37. const question = questions[i]
  38. question.addEventListener("click", toggleFaqFichiers);
  39. }
  40. function toggleFaqFichiers(event) {
  41. console.log(event, this);
  42. for (let i = 0; i < fichiers.length; i++) {
  43. fichiers[i].classList.remove('opened');
  44. }
  45. let fichier = this.parentNode.querySelector('.field--name-field-fichiers');
  46. fichier.classList.add('opened');
  47. }
  48. //////
  49. var liens = document.getElementsByClassName("field--name-field-liens");
  50. var questions = document.getElementsByClassName("field--name-field-question");
  51. for (let i = 0; i < questions.length; i++) {
  52. const question = questions[i]
  53. question.addEventListener("click", toggleFaqLiens);
  54. }
  55. function toggleFaqLiens(event) {
  56. console.log(event, this);
  57. for (let i = 0; i < liens.length; i++) {
  58. liens[i].classList.remove('opened');
  59. }
  60. let lien = this.parentNode.querySelector('.field--name-field-liens');
  61. lien.classList.add('opened');
  62. }
  63. var ressources = document.getElementsByClassName("field--name-field-ress");
  64. var questions = document.getElementsByClassName("field--name-field-question");
  65. for (let i = 0; i < questions.length; i++) {
  66. const question = questions[i]
  67. question.addEventListener("click", toggleFaqRessources);
  68. }
  69. function toggleFaqRessources(event) {
  70. console.log(event, this);
  71. for (let i = 0; i < resources.length; i++) {
  72. ressources[i].classList.remove('opened');
  73. }
  74. let ressource = this.parentNode.querySelector('.field--name-field-ress');
  75. ressource.classList.add('opened');
  76. }
  77. ///////////////////////////////
  78. // fleche qui tourne faq
  79. // var questions = document.getElementsByClassName("field--name-field-question");
  80. // var paragraph = document.querySelector('.field--name-field-question p')
  81. // console.log(element)
  82. // var styles = window.getComputedStyle(element,':after')
  83. // var content = styles['content']
  84. // console.log(content)
  85. // for (let i = 0; i < questions.length; i++) {
  86. // const question = questions[i]
  87. // question.addEventListener("click", rotateFleche);
  88. // }
  89. // function rotateFleche(event) {
  90. // console.log(event, this);
  91. // // for (let i = 0; i < answers.length; i++) {
  92. // // answers[i].classList.remove('opened');
  93. // // }
  94. // }
  95. //////////////////////////////////////////
  96. // block collection reste bleu quand actif
  97. jQuery(function($) {
  98. var path = window.location.href; // because the 'href' property of the DOM element is the absolute path
  99. console.log(path);
  100. $(".view-id-collections .view-content .views-row a").each(function() {
  101. if (this.href === path) {
  102. $(this).parent().closest('.views-row').addClass('active');
  103. }
  104. });
  105. });
  106. // /////////////////
  107. //// ancre dans texte
  108. // document.querySelector('.paragraph--view-mode--textes-toc').click( function() {
  109. // var page = this.attr('href');
  110. // var speed = 750; // gérer la vitesse de défliement
  111. // // Ici on retranche la hauteur du bandeau (201px dans ta feuille de styles)
  112. // document.querySelector('html, body').animate( { scrollTop: page.offset().top - 201 }, speed );
  113. // return false;
  114. // });
  115. /// sticky header on scroll
  116. // // When the user scrolls the page, execute myFunction
  117. // window.onscroll = function() {stickyHeader()};
  118. // console.log(Event);
  119. // // Get the header
  120. // var header = document.getElementById("header-top");
  121. // // Get the offset position of the navbar
  122. // var sticky = header.offsetTop;
  123. // // Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
  124. // function stickyHeader() {
  125. // if (window.pageYOffset > sticky) {
  126. // header.classList.add("sticky");
  127. // } else {
  128. // header.classList.remove("sticky");
  129. // }
  130. // }
  131. ///////////////////