main.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. //////////////////////
  64. var ressources = document.getElementsByClassName("field--name-field-ress");
  65. var questions = document.getElementsByClassName("field--name-field-question");
  66. for (let i = 0; i < questions.length; i++) {
  67. const question = questions[i]
  68. question.addEventListener("click", toggleFaqRessources);
  69. }
  70. function toggleFaqRessources(event) {
  71. // console.log(event, this);
  72. for (let i = 0; i < resources.length; i++) {
  73. ressources[i].classList.remove('opened');
  74. }
  75. let ressource = this.parentNode.querySelector('.field--name-field-ress');
  76. ressource.classList.add('opened');
  77. }
  78. ///////////////////////////////
  79. ////////////////////////////////
  80. // fleche qui tourne faq
  81. // var questions = document.getElementsByClassName("field--name-field-question");
  82. // var paragraph = document.querySelector('.field--name-field-question p::after');
  83. // console.log(paragraph)
  84. // var styles = window.getComputedStyle(element,':after')
  85. // console.log(styles)
  86. // var content = styles['content']
  87. // console.log(content)
  88. // for (let i = 0; i < questions.length; i++) {
  89. // const question = questions[i]
  90. // question.addEventListener("click", rotateFleche);
  91. // }
  92. // function rotateFleche(event) {
  93. // console.log(event, this);
  94. // // for (let i = 0; i < answers.length; i++) {
  95. // // answers[i].classList.remove('opened');
  96. // // }
  97. // }
  98. //////////////////////////////////////////
  99. // block collection reste bleu quand actif
  100. jQuery(function($) {
  101. var path = window.location.href; // because the 'href' property of the DOM element is the absolute path
  102. console.log(path);
  103. $(".view-id-collections .view-content .views-row a").each(function() {
  104. if (this.href === path) {
  105. $(this).parent().closest('.views-row').addClass('active');
  106. }
  107. });
  108. });
  109. // /////////////////
  110. //// ancre dans texte au click parragraphe correspondant arrive en dessous du header
  111. (function($, window) {
  112. var adjustAnchor = function() {
  113. var $anchor = $('.block-entity-fieldnodefield-textes'),
  114. fixedElementHeight = 350;
  115. if ($anchor.length > 0) {
  116. $('html, body').stop().animate({scrollTop: $anchor.offset().top - fixedElementHeight}, 250);
  117. }
  118. };
  119. $(window).on('hashchange load', function() {
  120. adjustAnchor();
  121. });
  122. })(jQuery, window);
  123. // ///////////////////////////////
  124. // (function(document, history, location) {
  125. // var HISTORY_SUPPORT = !!(history && history.pushState);
  126. // var anchorScrolls = {
  127. // ANCHOR_REGEX: /^#[^ ]+$/,
  128. // OFFSET_HEIGHT_PX: 50,
  129. // /**
  130. // * Establish events, and fix initial scroll position if a hash is provided.
  131. // */
  132. // init: function() {
  133. // this.scrollToCurrent();
  134. // $(window).on('hashchange', $.proxy(this, 'scrollToCurrent'));
  135. // $('body').on('click', 'a', $.proxy(this, 'delegateAnchors'));
  136. // },
  137. // /**
  138. // * Return the offset amount to deduct from the normal scroll position.
  139. // * Modify as appropriate to allow for dynamic calculations
  140. // */
  141. // getFixedOffset: function() {
  142. // return this.OFFSET_HEIGHT_PX;
  143. // },
  144. // /**
  145. // * If the provided href is an anchor which resolves to an element on the
  146. // * page, scroll to it.
  147. // * @param {String} href
  148. // * @return {Boolean} - Was the href an anchor.
  149. // */
  150. // scrollIfAnchor: function(href, pushToHistory) {
  151. // var match, anchorOffset;
  152. // if(!this.ANCHOR_REGEX.test(href)) {
  153. // return false;
  154. // }
  155. // match = document.getElementById(href.slice(1));
  156. // if(match) {
  157. // anchorOffset = $(match).offset().top - this.getFixedOffset();
  158. // $('html, body').animate({ scrollTop: anchorOffset});
  159. // // Add the state to history as-per normal anchor links
  160. // if(HISTORY_SUPPORT && pushToHistory) {
  161. // history.pushState({}, document.title, location.pathname + href);
  162. // }
  163. // }
  164. // return !!match;
  165. // },
  166. // /**
  167. // * Attempt to scroll to the current location's hash.
  168. // */
  169. // scrollToCurrent: function(e) {
  170. // if(this.scrollIfAnchor(window.location.hash) && e) {
  171. // e.preventDefault();
  172. // }
  173. // },
  174. // /**
  175. // * If the click event's target was an anchor, fix the scroll position.
  176. // */
  177. // delegateAnchors: function(e) {
  178. // var elem = e.target;
  179. // if(this.scrollIfAnchor(elem.getAttribute('href'), true)) {
  180. // e.preventDefault();
  181. // }
  182. // }
  183. // };
  184. // $(document).ready($.proxy(anchorScrolls, 'init'));
  185. // })(window.document, window.history, window.location);