main.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. // masquer bouton proposer une ressource pour collection 50 ans
  111. // jQuery(function($) {
  112. // var path = window.location.href; // because the 'href' property of the DOM element is the absolute path
  113. // console.log(path);
  114. // $ (function bouton() {
  115. // if (path.indexOf("/ressources/bdd/29") > -1) {
  116. // (".block-block-content82917d0c-5004-4bfb-af66-ce334782d82d").addClass('.notdisplaid');
  117. // }
  118. // });
  119. // });
  120. // jQuery(function($) {
  121. // var path = window.location.href; // because the 'href' property of the DOM element is the absolute path
  122. // console.log(path);
  123. // $(".block-block-content82917d0c-5004-4bfb-af66-ce334782d82d").each(function() {
  124. // if (this.href === path) {
  125. // $(this).parent().closest('.field--name-field-lien').addClass('notdisplaid');
  126. // }
  127. // });
  128. // });
  129. // /////////////////
  130. //// ancre dans texte au click parragraphe correspondant arrive en dessous du header
  131. (function($, window) {
  132. var adjustAnchor = function() {
  133. var $anchor = $('.block-entity-fieldnodefield-textes'),
  134. fixedElementHeight = 350;
  135. if ($anchor.length > 0) {
  136. $('html, body').stop().animate({scrollTop: $anchor.offset().top - fixedElementHeight}, 250);
  137. }
  138. };
  139. $(window).on('hashchange load', function() {
  140. adjustAnchor();
  141. });
  142. })(jQuery, window);
  143. // ///////////////////////////////
  144. // (function(document, history, location) {
  145. // var HISTORY_SUPPORT = !!(history && history.pushState);
  146. // var anchorScrolls = {
  147. // ANCHOR_REGEX: /^#[^ ]+$/,
  148. // OFFSET_HEIGHT_PX: 50,
  149. // /**
  150. // * Establish events, and fix initial scroll position if a hash is provided.
  151. // */
  152. // init: function() {
  153. // this.scrollToCurrent();
  154. // $(window).on('hashchange', $.proxy(this, 'scrollToCurrent'));
  155. // $('body').on('click', 'a', $.proxy(this, 'delegateAnchors'));
  156. // },
  157. // /**
  158. // * Return the offset amount to deduct from the normal scroll position.
  159. // * Modify as appropriate to allow for dynamic calculations
  160. // */
  161. // getFixedOffset: function() {
  162. // return this.OFFSET_HEIGHT_PX;
  163. // },
  164. // /**
  165. // * If the provided href is an anchor which resolves to an element on the
  166. // * page, scroll to it.
  167. // * @param {String} href
  168. // * @return {Boolean} - Was the href an anchor.
  169. // */
  170. // scrollIfAnchor: function(href, pushToHistory) {
  171. // var match, anchorOffset;
  172. // if(!this.ANCHOR_REGEX.test(href)) {
  173. // return false;
  174. // }
  175. // match = document.getElementById(href.slice(1));
  176. // if(match) {
  177. // anchorOffset = $(match).offset().top - this.getFixedOffset();
  178. // $('html, body').animate({ scrollTop: anchorOffset});
  179. // // Add the state to history as-per normal anchor links
  180. // if(HISTORY_SUPPORT && pushToHistory) {
  181. // history.pushState({}, document.title, location.pathname + href);
  182. // }
  183. // }
  184. // return !!match;
  185. // },
  186. // /**
  187. // * Attempt to scroll to the current location's hash.
  188. // */
  189. // scrollToCurrent: function(e) {
  190. // if(this.scrollIfAnchor(window.location.hash) && e) {
  191. // e.preventDefault();
  192. // }
  193. // },
  194. // /**
  195. // * If the click event's target was an anchor, fix the scroll position.
  196. // */
  197. // delegateAnchors: function(e) {
  198. // var elem = e.target;
  199. // if(this.scrollIfAnchor(elem.getAttribute('href'), true)) {
  200. // e.preventDefault();
  201. // }
  202. // }
  203. // };
  204. // $(document).ready($.proxy(anchorScrolls, 'init'));
  205. // })(window.document, window.history, window.location);