index.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <!doctype html>
  2. <html <?php language_attributes(); ?>>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <?php wp_head(); ?>
  7. </head>
  8. <body <?php body_class(); ?>>
  9. <?php wp_body_open(); ?>
  10. <?php do_action('get_header'); ?>
  11. <div id="app" class="banner bg-jlg-dark-blue text-jlg-white font-authentic flex w-full flex-col justify-center items-center">
  12. <?php echo view(app('sage.view'), app('sage.data'))->render(); ?>
  13. </div>
  14. <script>
  15. document.addEventListener('DOMContentLoaded', function () {
  16. // CLEANER LE TABLEAU
  17. let minHeadTh = document.querySelector("#main table thead tr th:first-of-type");
  18. minHeadTh.style.width = `${100 / 8}%`;
  19. let otherHeadThs = document.querySelectorAll("#main table thead tr th:not(:first-of-type)");
  20. for (let otherHeadTh of otherHeadThs) {
  21. otherHeadTh.style.width = `${100 / 8 * 1.75}%`;
  22. }
  23. let minTableTds = document.querySelectorAll("#main table tbody tr td:first-of-type");
  24. for (let minTableTd of minTableTds) {
  25. if (minTableTd.parentNode.childElementCount != 1) {
  26. minTableTd.style.width = `${100 / 8}%`;
  27. }
  28. }
  29. let otherTableTds = document.querySelectorAll("#main table tbody tr td:not(:first-of-type)");
  30. for (let otherTableTd of otherTableTds) {
  31. otherTableTd.style.width = `${100 / 8 * 1.75}%`;
  32. }
  33. // HEADER AU SCROLL
  34. let tableHead = document.querySelector("thead tr");
  35. let tHeadHeight = tableHead.offsetHeight;
  36. window.onscroll = () => {
  37. tableHead.style.minHeight = `${document.querySelector("header").offsetHeight + 72}px`;
  38. let scroll = window.pageYOffset;
  39. let headerNewHeight = tHeadHeight - scroll;
  40. tableHead.style.height = `${headerNewHeight}px`;
  41. }
  42. // italiques -> A FAIRE SUR LE CSV AVANT D'IMPORTER CA RALENTIT DE OUF LE CHARGEMENT
  43. let tbody = document.querySelectorAll('tbody');
  44. let tbodyContent = tbody[0].innerHTML;
  45. let asteriskCounter = 0;
  46. for (let i = 0; i < tbodyContent.length; i++) {
  47. if (tbodyContent[i] == "*") {
  48. if (asteriskCounter % 2 == 0) {
  49. tbodyContent = tbodyContent.substring(0, i) + '<span class="font-caslon italic">' + tbodyContent.substring(i + 1);
  50. } else {
  51. tbodyContent = tbodyContent.substring(0, i) + '</span>' + tbodyContent.substring(i + 1);
  52. }
  53. asteriskCounter++;
  54. }
  55. }
  56. tbody[0].innerHTML = tbodyContent;
  57. // titres de parties
  58. let mainpartTitless = document.querySelectorAll('.isMainPart');
  59. for (let mainpartTitles of mainpartTitless) {
  60. if (mainpartTitles.nextElementSibling.classList.contains('isSubPart')) {
  61. mainpartTitles.firstElementChild.firstElementChild.style.height = "1.5rem";
  62. mainpartTitles.firstElementChild.style.marginBottom = "-0.25rem";
  63. mainpartTitles.style.borderBottom = "0";
  64. mainpartTitles.style.paddingBottom = "0";
  65. mainpartTitles.nextElementSibling.style.paddingTop = "0";
  66. }
  67. }
  68. // couleurs titres
  69. let colors = [
  70. {'red' : 'e4000c'},
  71. {'blue1': '5dfffd'},
  72. {'blue2': '0fe5f9'},
  73. {'blue3': '11c1f8'},
  74. {'blue4': '0779f1'},
  75. {'blue5': '040bcb'},
  76. {'yellow1': 'ffe113'},
  77. {'yellow2': 'f4ff1b'},
  78. {'yellow3': 'e2ff0c'},
  79. {'yellow4': '93fe0b'},
  80. {'yellow5': '17fe0b'},
  81. {'pink1': 'e70060'},
  82. {'pink2': 'f03cf3'}
  83. ];
  84. let titles = document.querySelectorAll('.isMainPart, .isSubPart');
  85. let partTitles = [];
  86. for (let title of titles) {
  87. if (!title.nextElementSibling.classList.contains('isSubPart')) {
  88. partTitles.push(title);
  89. }
  90. }
  91. for (let i = 0; i < partTitles.length; i++) {
  92. if (partTitles[i].previousElementSibling?.classList.contains('isMainPart')) {
  93. partTitles[i].previousElementSibling.firstElementChild.firstElementChild.style.backgroundColor = "#" + Object.values(colors[i])[0];
  94. }
  95. partTitles[i].firstElementChild.firstElementChild.style.backgroundColor = "#" + Object.values(colors[i])[0];
  96. }
  97. // scroll with cursor
  98. // display parts rectangle on timeline
  99. let tlContainer, tlContainerHeight, bodyHeight;
  100. let partsHeight = [];
  101. let prevHeight = 0;
  102. let partBlockHeights = [];
  103. let activePartIndex;
  104. function getAllHeights() {
  105. tlContainer = document.querySelector('#timeline_container');
  106. tlContainerHeight = tlContainer.offsetHeight;
  107. bodyHeight = document.querySelector('tbody').offsetHeight;
  108. let lastTitle = document.querySelectorAll('.isMainPart');
  109. lastTitle = lastTitle[lastTitle.length - 1];
  110. for (let i = 0; i < partTitles.length; i++) {
  111. let elTopFromParentTop = partTitles[i].offsetTop - document.querySelector('tbody').offsetTop;
  112. let partSize = elTopFromParentTop - prevHeight;
  113. prevHeight = elTopFromParentTop;
  114. if (i != 0) {
  115. partsHeight.push(partSize);
  116. }
  117. }
  118. partsHeight.push(bodyHeight - lastTitle.offsetTop);
  119. const partsHeightSum = partsHeight.reduce((partialSum, a) => partialSum + a, 0);
  120. for (let partHeight of partsHeight) {
  121. partBlockHeights.push(partHeight / bodyHeight * tlContainerHeight);
  122. }
  123. }
  124. getAllHeights();
  125. function drawFriseRects() {
  126. for (let i = 0; i < partBlockHeights.length; i++) {
  127. let partDiv = document.createElement('div');
  128. partDiv.style.width = "32px";
  129. partDiv.style.height = partBlockHeights[i] + "px";
  130. partDiv.style.backgroundColor = "#" + Object.values(colors[i])[0];
  131. partDiv.style.borderBottom = "solid 1.5px #010d19";
  132. partDiv.style.opacity = "0.6";
  133. partDiv.style.transition = "opacity 0.3s ease-out";
  134. partDiv.style.cursor = "pointer";
  135. tlContainer.prepend(partDiv);
  136. tlContainer.children[0].addEventListener("mouseenter", function() {
  137. let el = tlContainer.children[tlContainer.children.length - 1 - i];
  138. el.style.opacity = "1";
  139. });
  140. tlContainer.children[0].addEventListener("mouseleave", function() {
  141. let el = tlContainer.children[tlContainer.children.length - 1 - i];
  142. if (Array.from(el.parentNode.children).indexOf(el) != activePartIndex) {
  143. el.style.opacity = "0.7";
  144. }
  145. });
  146. }
  147. }
  148. drawFriseRects();
  149. window.addEventListener("resize", (event) => {
  150. getAllHeights();
  151. tlContainer.innerHTML = '';
  152. drawFriseRects();
  153. });
  154. // make the cursor move on scroll
  155. let scrollValue, cursorTop;
  156. let cursor = document.querySelector('#cursor');
  157. cursor.style.transform = `translateY(${window.scrollY / bodyHeight * tlContainerHeight}px)`;
  158. getActivePart();
  159. document.addEventListener("scroll", (event) => {
  160. scrollValue = window.scrollY;
  161. let diffSize = scrollValue / bodyHeight * tlContainerHeight;
  162. cursor.style.transform = `translateY(${diffSize}px)`;
  163. cursorTop = cursorTop + diffSize;
  164. getActivePart();
  165. });
  166. // make the cursor draggable
  167. let isCursorGrabbed = false;
  168. let cursorPrevTranslateAmount = +cursor.style.transform.slice(0, -3).slice(11);
  169. let prevCursorPos = 0;
  170. cursor.addEventListener("mousedown", (event) => {
  171. if (!isCursorGrabbed) {
  172. event.preventDefault();
  173. isCursorGrabbed = true;
  174. prevCursorPos = event.clientY;
  175. }
  176. });
  177. window.addEventListener("mousemove", (event) => {
  178. if (isCursorGrabbed) {
  179. event.preventDefault();
  180. let newPos = cursorPrevTranslateAmount + (event.clientY - prevCursorPos);
  181. if (event.clientY < tlContainerHeight + tlContainer.offsetTop && event.clientY > tlContainer.offsetTop) {
  182. cursor.style.transform = `translateY(${newPos}px)`;
  183. window.scrollBy(0, (event.clientY - prevCursorPos) * (bodyHeight / tlContainerHeight));
  184. cursorPrevTranslateAmount = +cursor.style.transform.slice(0, -3).slice(11);
  185. getActivePart();
  186. } else if (event.clientY <= tlContainer.offsetTop) {
  187. cursor.style.transform = "translateY(0px)";
  188. window.scroll(0, 0);
  189. cursorPrevTranslateAmount = 0;
  190. } else if (event.clientY >= tlContainerHeight + tlContainer.offsetTop) {
  191. cursor.style.transform = `translateY(${tlContainerHeight}px)`;
  192. window.scroll(0, bodyHeight);
  193. cursorPrevTranslateAmount = +cursor.style.transform.slice(0, -3).slice(11);
  194. }
  195. prevCursorPos = event.clientY;
  196. }
  197. });
  198. window.addEventListener("mouseup", (event) => {
  199. if (isCursorGrabbed) {
  200. isCursorGrabbed = false;
  201. }
  202. });
  203. // lighten active part rectangle
  204. function getActivePart() {
  205. let partRects = tlContainer.children;
  206. let cursorYPos = cursor.getBoundingClientRect().top + cursor.clientHeight / 2;
  207. if (cursorYPos >= Object.values(partRects)[0].getBoundingClientRect().bottom) {
  208. for (let partRect of partRects) {
  209. partRect.style.opacity = 0.6;
  210. }
  211. Object.values(partRects)[0].style.opacity = 1;
  212. } else {
  213. for (let i = 0; i < partRects.length; i++) {
  214. if (cursorYPos >= partRects[i].getBoundingClientRect().top && cursorYPos < partRects[i].getBoundingClientRect().top + partRects[i].clientHeight) {
  215. partRects[i].style.opacity = 1;
  216. activePartIndex = i;
  217. } else {
  218. partRects[i].style.opacity = 0.6;
  219. }
  220. }
  221. }
  222. }
  223. // TODO
  224. // ajouter le titre collé au curseur et le temps total en bas
  225. // smoothscroll au clic sur une partie
  226. }, false);
  227. </script>
  228. <?php do_action('get_footer'); ?>
  229. <?php wp_footer(); ?>
  230. </body>
  231. </html>