main.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. // for (let i = 0; i < questions.length; i++) {
  81. // const question = questions[i]
  82. // question.addEventListener("click", rotateFleche);
  83. // }
  84. // function rotateFleche(event) {
  85. // console.log(event, this);
  86. // // for (let i = 0; i < answers.length; i++) {
  87. // // answers[i].classList.remove('opened');
  88. // // }
  89. // }
  90. //////////////////////////////////////////
  91. // block collection reste bleu quand actif
  92. // idée: lorsque la div description du parent collection est en vue, appliquer
  93. // la classe .activ{background-color:$blue-dark}
  94. // OU if class
  95. // $(function() {
  96. // $('nav a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
  97. // });
  98. // jQuery(function($) {
  99. // $('nav a[href^="/' + ressources/bdd/"30".split("/")[1] + '"]').addClass('active');
  100. // });
  101. // jQuery(function($) {
  102. // var path = window.location.href; // because the 'href' property of the DOM element is the absolute path
  103. // console.log(path);
  104. // var nameCollection = document.querySelectorAll(".view-id-collections .view-content .views-row")
  105. // console.log(nameCollection);
  106. // $('.view-id-collections.view-content.views-row').each(function() {
  107. // if (this.href === path) {
  108. // console.log(this);
  109. // $(this).addClass('active');
  110. // }
  111. // });
  112. // });
  113. // jQuery(function($) {
  114. // var path = window.location.href; // because the 'href' property of the DOM element is the absolute path
  115. // console.log(path);
  116. // var nameCollection = document.querySelectorAll(".view-id-collections .view-content .views-row a")
  117. // console.log(nameCollection);
  118. // function inView() {
  119. // let lienPave = document.querySelectorAll(".view-id-collections .view-content .views-row a")
  120. // if (this.href === path) {
  121. // this.classList.add('active');
  122. // }
  123. // };
  124. // });
  125. jQuery(function($) {
  126. var path = window.location.href; // because the 'href' property of the DOM element is the absolute path
  127. console.log(path);
  128. $(".view-id-collections .view-content .views-row a").each(function() {
  129. if (this.href === path) {
  130. $(this).parent().closest('.views-row').addClass('active');
  131. }
  132. });
  133. });
  134. // const Autre = document.getElementsByClassName("");
  135. // const Historique = document.getElementsByClassName("");
  136. // var descriptionAutre = document.getElementsByClassName("js-view-dom-id-b65e57a8672654a3b2a59e71c9f5ccfb730d7879c2c0096e324b0ce29b2a3b74").value
  137. // console.log(descriptionAutre);
  138. // // const descriptionHistorique = document.getElementsByClassName("js-view-dom-id-5c891f37126eb689016ea6da376ca1a15cc90c3dbcb394d063fb43dc16ec5250");
  139. // var nameCollection = document.querySelectorAll(".path-ressources .basededonnees .layout-content .region-content #block-contenudelapageprincipale .layout--onecol .block-region-content .block-views-blockcollections-block-1 .view-id-collections .view-content .views-row a").value
  140. // console.log(nameCollection);
  141. // // var descriptionCollection = document.getElementsByClassName("");
  142. // // let nameCollection = { Autre: "Autres contributions sur la qualité du logement", Historique: "Histoire des expérimentations du logement depuis les années 1950 en Europe"};
  143. // var Autre = "Autres contributions sur la qualité du logement"
  144. // var Historique = "Histoire des expérimentations du logement depuis les années 1950 en Europe"
  145. // console.log(Autre, Historique);
  146. // function getValue(){
  147. // for (const nameCollection = Autre ){}
  148. // if (nameCollection === Autre){
  149. // return "Autres contributions sur la qualité du logement";
  150. // }
  151. // }
  152. // function blueBackground(){
  153. // // console.log('nameCollection')
  154. // // var descriptionCollection = document.getElementsByClassName("");
  155. // // if (descriptionCollection === descriptionAutre)
  156. // // nameCollection.addClass('blue');
  157. // if (getvalue === "Autres contributions sur la qualité du logement")
  158. // nameCollection.addClass('blue');
  159. // }
  160. // let inView = addEventListener("inView", blueBackground);
  161. // console.log(inView)
  162. // function blueBackground(event){
  163. // console.log(event, this);
  164. // }
  165. //
  166. // /////////////////
  167. //// ancre dans texte
  168. // document.querySelector('.paragraph--view-mode--textes-toc').click( function() {
  169. // var page = this.attr('href');
  170. // var speed = 750; // gérer la vitesse de défliement
  171. // // Ici on retranche la hauteur du bandeau (201px dans ta feuille de styles)
  172. // document.querySelector('html, body').animate( { scrollTop: page.offset().top - 201 }, speed );
  173. // return false;
  174. // });
  175. /// sticky header on scroll
  176. // // When the user scrolls the page, execute myFunction
  177. // window.onscroll = function() {stickyHeader()};
  178. // console.log(Event);
  179. // // Get the header
  180. // var header = document.getElementById("header-top");
  181. // // Get the offset position of the navbar
  182. // var sticky = header.offsetTop;
  183. // // Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
  184. // function stickyHeader() {
  185. // if (window.pageYOffset > sticky) {
  186. // header.classList.add("sticky");
  187. // } else {
  188. // header.classList.remove("sticky");
  189. // }
  190. // }
  191. ///////////////////
  192. // document.addEventListener('click', function(e) {
  193. // if (e.target.classList.contains('rect_white_left') {
  194. // e.target.parentNode.nextElementSibling.classList.toggle('opened');}
  195. // }
  196. // fonction pour attribuer la class du parents
  197. // var fields = document.getElementsByClassName("field--name-field-titre");
  198. // var paragraphs = document.getElementsByClassName("paragraph--type--texte");
  199. // for (let i = 0; i < fields.length; i++) {
  200. // const field = fields[i]
  201. // }
  202. // function giveIdParent(){
  203. // document.field.classList="paragraphs";
  204. // }
  205. // Function mouseOut ()
  206. // {
  207. // document.getelementbyid("flashdiv").classname="flash-I";
  208. // }
  209. // open external link in new window
  210. // $(".ext").each(
  211. // function(i,e){
  212. // window.open(e, '_blank');
  213. // }
  214. // );
  215. // var target = document.getElementsByClassName("ext");
  216. // document.addEventListener("click", function(e) {
  217. // if (e.target == true )
  218. // {
  219. // e.target.setAttribute("target", "_blank");
  220. // }
  221. // });
  222. // add id to field
  223. // Add data-extlink attribute.
  224. // $links_to_process.attr('data-extlink', '');
  225. // var i;
  226. // var length = $links_to_process.length;
  227. // for (i = 0; i < length; i++) {
  228. // var $link = $($links_to_process[i]);
  229. // if (drupalSettings.data.extlink.extUseFontAwesome) {
  230. // if (class_name === drupalSettings.data.extlink.mailtoClass) {
  231. // $link[icon_placement]('<span class="fa-' + class_name + ' extlink"><span class="' + drupalSettings.data.extlink.extFaMailtoClasses + '" aria-label="' + drupalSettings.data.extlink.mailtoLabel + '"></span></span>');
  232. // }
  233. // else {
  234. // $link[icon_placement]('<span class="fa-' + class_name + ' extlink"><span class="' + drupalSettings.data.extlink.extFaLinkClasses + '" aria-label="' + drupalSettings.data.extlink.extLabel + '"></span></span>');
  235. // }
  236. // }
  237. // else {
  238. // if (class_name === drupalSettings.data.extlink.mailtoClass) {
  239. // $link[icon_placement]('<svg focusable="false" class="' + class_name + '" role="img" aria-label="' + drupalSettings.data.extlink.mailtoLabel + '" xmlns="http://www.w3.org/2000/svg" viewBox="0 10 70 20"><metadata><sfw xmlns="http://ns.adobe.com/SaveForWeb/1.0/"><sliceSourceBounds y="-8160" x="-8165" width="16389" height="16384" bottomLeftOrigin="true"/><optimizationSettings><targetSettings targetSettingsID="0" fileFormat="PNG24Format"><PNG24Format transparency="true" filtered="false" interlaced="false" noMatteColor="false" matteColor="#FFFFFF"/></targetSettings></optimizationSettings></sfw></metadata><title>' + drupalSettings.data.extlink.mailtoLabel + '</title><path d="M56 14H8c-1.1 0-2 0.9-2 2v32c0 1.1 0.9 2 2 2h48c1.1 0 2-0.9 2-2V16C58 14.9 57.1 14 56 14zM50.5 18L32 33.4 13.5 18H50.5zM10 46V20.3l20.7 17.3C31.1 37.8 31.5 38 32 38s0.9-0.2 1.3-0.5L54 20.3V46H10z"/></svg>');
  240. // }
  241. // else {
  242. // $link[icon_placement]('<svg focusable="false" class="' + class_name + '" role="img" aria-label="' + drupalSettings.data.extlink.extLabel + '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 40"><metadata><sfw xmlns="http://ns.adobe.com/SaveForWeb/1.0/"><sliceSourceBounds y="-8160" x="-8165" width="16389" height="16384" bottomLeftOrigin="true"/><optimizationSettings><targetSettings targetSettingsID="0" fileFormat="PNG24Format"><PNG24Format transparency="true" filtered="false" interlaced="false" noMatteColor="false" matteColor="#FFFFFF"/></targetSettings></optimizationSettings></sfw></metadata><title>' + drupalSettings.data.extlink.extLabel + '</title><path d="M48 26c-1.1 0-2 0.9-2 2v26H10V18h26c1.1 0 2-0.9 2-2s-0.9-2-2-2H8c-1.1 0-2 0.9-2 2v40c0 1.1 0.9 2 2 2h40c1.1 0 2-0.9 2-2V28C50 26.9 49.1 26 48 26z"/><path d="M56 6H44c-1.1 0-2 0.9-2 2s0.9 2 2 2h7.2L30.6 30.6c-0.8 0.8-0.8 2 0 2.8C31 33.8 31.5 34 32 34s1-0.2 1.4-0.6L54 12.8V20c0 1.1 0.9 2 2 2s2-0.9 2-2V8C58 6.9 57.1 6 56 6z"/></svg>');
  243. // }
  244. // }
  245. // }
  246. // };