app.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import domReady from '@roots/sage/client/dom-ready';
  2. import { customSearch } from './front/search.js';
  3. import { customTimeline } from './front/timeline.js';
  4. /**
  5. * Application entrypoint
  6. */
  7. domReady(async () => {
  8. window.addEventListener('load', function() {
  9. setTimeout(function() {
  10. window.scrollTo(0, 0);
  11. }, 0);
  12. });
  13. window.addEventListener('resize', function() {
  14. setTimeout(function() {
  15. window.scrollTo(0, 0);
  16. let editButtons = document.querySelectorAll(".edit-button");
  17. for (let editButton of editButtons) {
  18. let editContainer = editButton.parentElement;
  19. editContainer.style.height = `${editContainer.previousElementSibling.offsetHeight}px`;
  20. }
  21. }, 0);
  22. });
  23. // POUR LES LIENS D'EDITION/CONNEXION QUAND ON EST PAS CONNECTÉS
  24. let connectLinks = document.querySelectorAll('a.xoo-el-login-tgr');
  25. for (let connectLink of connectLinks) {
  26. if (connectLink.previousElementSibling) {
  27. let penImg = connectLink.previousElementSibling;
  28. connectLink.classList.add('edit-button');
  29. connectLink.innerText = '';
  30. connectLink.append(penImg);
  31. }
  32. }
  33. // CLEANER LE TABLEAU
  34. let minHeadTh = document.querySelector("#main table thead tr th:first-of-type");
  35. minHeadTh.style.width = `${100 / 8}%`;
  36. let otherHeadThs = document.querySelectorAll("#main table thead tr th:not(:first-of-type)");
  37. for (let otherHeadTh of otherHeadThs) {
  38. otherHeadTh.style.width = `${100 / 8 * 1.75}%`;
  39. }
  40. let minTableTds = document.querySelectorAll("#main table tbody tr td:first-of-type");
  41. for (let minTableTd of minTableTds) {
  42. if (minTableTd.parentNode.childElementCount != 1) {
  43. minTableTd.style.width = `${100 / 8}%`;
  44. }
  45. }
  46. let otherTableTds = document.querySelectorAll("#main table tbody tr td:not(:first-of-type)");
  47. for (let otherTableTd of otherTableTds) {
  48. otherTableTd.style.width = `${100 / 8 * 1.75}%`;
  49. }
  50. let editButtons = document.querySelectorAll(".edit-button");
  51. for (let editButton of editButtons) {
  52. let editContainer = editButton.parentElement;
  53. editContainer.style.height = `${editContainer.previousElementSibling.offsetHeight}px`;
  54. }
  55. // HEADER AU SCROLL
  56. let tableHead = document.querySelector("thead tr");
  57. let tHeadHeight = tableHead.offsetHeight;
  58. tableHead.style.maxHeight = `${tHeadHeight}px`;
  59. let headerHeight = document.querySelector("header").offsetHeight;
  60. let titleLarge = document.querySelector('.brand span:nth-of-type(2)');
  61. let titlesSmall = document.querySelectorAll('.brand span:not(.brand span:nth-of-type(2))');
  62. let titleContainer = document.querySelector('.brand');
  63. window.onscroll = () => {
  64. tableHead.style.minHeight = `${headerHeight + 72}px`;
  65. let scroll = window.scrollY;
  66. let headerNewHeight = tHeadHeight - scroll;
  67. if (headerNewHeight > 72) {
  68. tableHead.style.height = `${headerHeight + headerNewHeight}px`;
  69. titleContainer.style.lineHeight = "1.75rem";
  70. titleLarge.style.fontSize = '35px';
  71. for (let titleSmall of titlesSmall) {
  72. titleSmall.style.fontSize = '25px';
  73. }
  74. } else {
  75. tableHead.style.height = tableHead.style.minHeight;
  76. titleContainer.style.lineHeight = "1.4rem";
  77. titleLarge.style.fontSize = '24px';
  78. for (let titleSmall of titlesSmall) {
  79. titleSmall.style.fontSize = '17px';
  80. }
  81. }
  82. }
  83. // C'EST LA POUR LES PRIVACY POLICY
  84. // texte d'explication du login popup
  85. // et privacy policy
  86. let loginPopupText = document.getElementById('content_login_popup');
  87. let privacyText = document.getElementById('content_privacy').innerHTML;
  88. loginPopupText = loginPopupText.innerText;
  89. let loginPopupTextWrapper = document.getElementsByClassName('xoo-el-sidebar');
  90. if (loginPopupTextWrapper[0]) {
  91. loginPopupTextWrapper[0].innerHTML = `<div>Espace collaboratif du site</div>`;
  92. loginPopupTextWrapper[0].innerHTML += `<p style="padding-top: 15px;">${loginPopupText}</p>`;
  93. }
  94. let loginPopupHeader = document.querySelector('.xoo-el-sidebar div:first-of-type');
  95. if (loginPopupHeader !== null) {
  96. loginPopupHeader.setAttribute('style', 'background-color: white; width: 100%; font-weight: bold; padding: 20px 30px;');
  97. }
  98. let policyDropdown = document.createElement('div');
  99. policyDropdown.style.width = "100%";
  100. policyDropdown.style.cursor = "pointer";
  101. policyDropdown.style.fontWeight = "bold";
  102. policyDropdown.style.display = "flex";
  103. policyDropdown.style.justifyContent = "space-between";
  104. policyDropdown.style.backgroundColor = "white";
  105. policyDropdown.style.padding = "20px 30px";
  106. let policyDropdownTitle = document.createElement('p');
  107. policyDropdownTitle.style.padding = "0";
  108. let policyDropdownPlus = document.createElement('p');
  109. policyDropdownPlus.style.padding = "0";
  110. policyDropdownPlus.innerText = '+';
  111. policyDropdownTitle.innerText = "Politique de confidentialité";
  112. policyDropdown.appendChild(policyDropdownTitle);
  113. policyDropdown.appendChild(policyDropdownPlus);
  114. let privacyPolicyContent = document.createElement('div');
  115. privacyPolicyContent.innerHTML = privacyText;
  116. privacyPolicyContent.style.width = "100%";
  117. privacyPolicyContent.style.padding = "0px";
  118. let policyParagraphs = privacyPolicyContent.querySelectorAll('p, h2');
  119. for (let policyParagraph of policyParagraphs) {
  120. policyParagraph.style.padding = '0';
  121. policyParagraph.style.marginBottom = '15px';
  122. }
  123. privacyPolicyContent.style.height = "0px";
  124. privacyPolicyContent.style.overflow = "hidden";
  125. let policyOpen = false;
  126. policyDropdown.addEventListener('click', togglePolicy);
  127. if (loginPopupTextWrapper[0]) {
  128. loginPopupTextWrapper[0].appendChild(policyDropdown);
  129. loginPopupTextWrapper[0].style.overflowY = "scroll";
  130. loginPopupTextWrapper[0].appendChild(privacyPolicyContent);
  131. }
  132. const privacyLink = document.querySelector('.xoo-aff-checkbox_single a');
  133. if (privacyLink) {
  134. privacyLink.addEventListener('click', function (e) {
  135. e.preventDefault();
  136. togglePolicy();
  137. });
  138. }
  139. function togglePolicy() {
  140. if (policyOpen) {
  141. privacyPolicyContent.style.height = "0px";
  142. privacyPolicyContent.style.padding = "0px";
  143. policyOpen = false;
  144. } else {
  145. privacyPolicyContent.style.height = "auto";
  146. privacyPolicyContent.style.padding = "10px 20px";
  147. policyOpen = true;
  148. }
  149. }
  150. customTimeline();
  151. customSearch();
  152. // désactive le loading quand les éléments sont affichés correctement
  153. setTimeout(() => {
  154. let loadingEl = document.getElementById('loading');
  155. loadingEl.style.opacity = "0";
  156. setTimeout(() => {
  157. loadingEl.style.display = "none";
  158. }, 200);
  159. }, 100);
  160. });
  161. /**
  162. * @see {@link https://webpack.js.org/api/hot-module-replacement/}
  163. */
  164. if (import.meta.webpackHot) import.meta.webpackHot.accept(console.error);