app.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. import domReady from '@roots/sage/client/dom-ready';
  2. /**
  3. * Application entrypoint
  4. */
  5. domReady(async () => {
  6. // pour régler tous les pb au refresh quand la page est déjà scrollée
  7. window.scrollTo(0, 0);
  8. // CLEANER LE TABLEAU
  9. let minHeadTh = document.querySelector("#main table thead tr th:first-of-type");
  10. minHeadTh.style.width = `${100 / 8}%`;
  11. let otherHeadThs = document.querySelectorAll("#main table thead tr th:not(:first-of-type)");
  12. for (let otherHeadTh of otherHeadThs) {
  13. otherHeadTh.style.width = `${100 / 8 * 1.75}%`;
  14. }
  15. let minTableTds = document.querySelectorAll("#main table tbody tr td:first-of-type");
  16. for (let minTableTd of minTableTds) {
  17. if (minTableTd.parentNode.childElementCount != 1) {
  18. minTableTd.style.width = `${100 / 8}%`;
  19. }
  20. }
  21. let otherTableTds = document.querySelectorAll("#main table tbody tr td:not(:first-of-type)");
  22. for (let otherTableTd of otherTableTds) {
  23. otherTableTd.style.width = `${100 / 8 * 1.75}%`;
  24. }
  25. // HEADER AU SCROLL
  26. let tableHead = document.querySelector("thead tr");
  27. let tHeadHeight = tableHead.offsetHeight;
  28. tableHead.style.maxHeight = `${tHeadHeight}px`;
  29. let headerHeight = document.querySelector("header").offsetHeight;
  30. window.onscroll = () => {
  31. tableHead.style.minHeight = `${headerHeight + 72}px`;
  32. let scroll = window.scrollY;
  33. let headerNewHeight = tHeadHeight - scroll;
  34. if (headerNewHeight > 72) {
  35. tableHead.style.height = `${headerHeight + headerNewHeight}px`;
  36. } else {
  37. tableHead.style.height = tableHead.style.minHeight;
  38. }
  39. }
  40. // italiques -> A FAIRE SUR LE CSV AVANT D'IMPORTER CA RALENTIT DE OUF LE CHARGEMENT
  41. /* let tbody = document.querySelector('body main table tbody');
  42. let tbodyContent = tbody.innerHTML;
  43. let asteriskCounter = 0;
  44. for (let i = 0; i < tbodyContent.length; i++) {
  45. if (tbodyContent[i] == "*") {
  46. if (asteriskCounter % 2 == 0) {
  47. tbodyContent = tbodyContent.substring(0, i) + '<span class="font-caslon italic">' + tbodyContent.substring(i + 1);
  48. } else {
  49. tbodyContent = tbodyContent.substring(0, i) + '</span>' + tbodyContent.substring(i + 1);
  50. }
  51. asteriskCounter++;
  52. }
  53. }
  54. tbody.innerHTML = tbodyContent;
  55. */
  56. // titres de parties dans le tableau
  57. let mainpartTitless = document.querySelectorAll('.isMainPart');
  58. for (let mainpartTitles of mainpartTitless) {
  59. if (mainpartTitles.nextElementSibling.classList.contains('isSubPart')) {
  60. mainpartTitles.firstElementChild.firstElementChild.style.height = "1.5rem";
  61. mainpartTitles.firstElementChild.style.marginBottom = "-0.25rem";
  62. mainpartTitles.style.borderBottom = "0";
  63. mainpartTitles.style.paddingBottom = "0";
  64. mainpartTitles.nextElementSibling.style.paddingTop = "0";
  65. }
  66. }
  67. // couleurs titres
  68. let colors = [
  69. {'red' : 'cf0118'},
  70. {'blue1': '0101c4'},
  71. {'blue2': '01049e'},
  72. {'blue3': '010678'},
  73. {'blue4': '010952'},
  74. {'blue5': '00113c'},
  75. {'yellow1': 'ade719'},
  76. {'yellow2': '8cc700'},
  77. {'yellow3': '74af00'},
  78. {'yellow4': '5c9900'},
  79. {'yellow5': '377600'},
  80. {'pink1': 'cf0118'},
  81. {'pink2': 'a10418'}
  82. ];
  83. let titles = document.querySelectorAll('.isMainPart, .isSubPart');
  84. let partTitles = [];
  85. for (let title of titles) {
  86. if (!title.nextElementSibling.classList.contains('isSubPart')) {
  87. partTitles.push(title);
  88. }
  89. }
  90. for (let i = 0; i < partTitles.length; i++) {
  91. if (partTitles[i].previousElementSibling?.classList.contains('isMainPart')) {
  92. partTitles[i].previousElementSibling.firstElementChild.firstElementChild.style.backgroundColor = "#" + Object.values(colors[i])[0];
  93. }
  94. partTitles[i].firstElementChild.firstElementChild.style.backgroundColor = "#" + Object.values(colors[i])[0];
  95. }
  96. // set parts rectangles
  97. function convertToSeconds(timeStr) {
  98. let [hourStr, minStr] = timeStr.split('h');
  99. if (!minStr) {
  100. minStr = hourStr;
  101. hourStr = '0';
  102. }
  103. minStr = minStr.replace('’', ':');
  104. minStr = minStr.replace("'", ':');
  105. const [min, sec] = minStr.split(':');
  106. return parseInt(hourStr) * 3600 + parseInt(min) * 60 + parseInt(sec);
  107. }
  108. let partTimesNodes = document.querySelectorAll('body #app main tbody tr:not(.isContentPart) + tr:not(.isSubPart) td:first-of-type');
  109. let partTimes = Array.from(partTimesNodes);
  110. for (let i = 0; i < partTimes.length; i++) {
  111. partTimes[i] = convertToSeconds(partTimes[i].innerText);
  112. }
  113. let lastTime = document.querySelectorAll('body #app main tbody tr:last-of-type td:first-of-type');
  114. partTimes.push(convertToSeconds(lastTime[0].innerText));
  115. let partDurations = [];
  116. for (let i = 0; i < partTimes.length - 1; i++) {
  117. partDurations.push(partTimes[i + 1] - partTimes[i]);
  118. }
  119. let totalTime = convertToSeconds(lastTime[0].innerText);
  120. let tlContainer, tlContainerHeight;
  121. var bodyHeight = document.querySelector('body').offsetHeight;
  122. let partBlockHeights = [];
  123. let activePartIndex = 0;
  124. function getAllHeights() {
  125. partBlockHeights = [];
  126. tlContainer = document.querySelector('#timeline_container');
  127. tlContainer.style.height = `calc(100vh - ${document.querySelector('header').offsetHeight}px - ${document.querySelector('footer').offsetHeight}px - 60px)`;
  128. tlContainer.style.top = `${document.querySelector('header').offsetHeight + 30}px`;
  129. tlContainerHeight = tlContainer.offsetHeight;
  130. for (let partDuration of partDurations) {
  131. partBlockHeights.push(partDuration / totalTime * tlContainerHeight);
  132. }
  133. }
  134. getAllHeights();
  135. function drawFriseRects() {
  136. for (let i = 0; i < partBlockHeights.length; i++) {
  137. let partDiv = document.createElement('div');
  138. partDiv.style.width = "22px";
  139. partDiv.style.height = partBlockHeights[i] + "px";
  140. partDiv.style.backgroundColor = "#" + Object.values(colors[i])[0];
  141. partDiv.style.borderBottom = "solid 1px #010d19";
  142. partDiv.style.borderTop = "solid 1px #010d19";
  143. partDiv.style.transition = "width 0.3s ease-out";
  144. partDiv.style.cursor = "pointer";
  145. tlContainer.prepend(partDiv);
  146. tlContainer.children[0].addEventListener("mouseenter", function() {
  147. let el = tlContainer.children[tlContainer.children.length - 1 - i];
  148. if (Array.from(el.parentNode.children).length - Array.from(el.parentNode.children).indexOf(el) - 1 != activePartIndex) {
  149. el.style.width = "32px";
  150. toggleTitleHover(i, 'show');
  151. }
  152. });
  153. tlContainer.children[0].addEventListener("mouseleave", function() {
  154. let el = tlContainer.children[tlContainer.children.length - 1 - i];
  155. if (Array.from(el.parentNode.children).length - Array.from(el.parentNode.children).indexOf(el) - 1 != activePartIndex) {
  156. el.style.width = "22px";
  157. }
  158. toggleTitleHover(i, 'hide');
  159. });
  160. tlContainer.children[0].addEventListener("click", function() {
  161. titresFrise[i].el.scrollIntoView({ behavior: 'smooth', block: 'center' });
  162. });
  163. }
  164. }
  165. drawFriseRects();
  166. window.addEventListener('resize', () => {
  167. bodyHeight = document.querySelector('body').offsetHeight;
  168. while(tlContainer.lastChild) {
  169. tlContainer.removeChild(tlContainer.lastChild);
  170. }
  171. getAllHeights();
  172. drawFriseRects();
  173. });
  174. // titres parties frise
  175. let titreFriseEl = document.createElement('div');
  176. let elements = Array.from(document.querySelectorAll('.isMainPart, .isSubPart'));
  177. let mainWithoutSubAfter = [];
  178. let mainWithSubAfter = [];
  179. let subWithoutMainBefore = [];
  180. let lastMain = null;
  181. for (let i = 0; i < elements.length; i++) {
  182. let current = elements[i];
  183. let next = elements[i + 1];
  184. if (current.classList.contains('isMainPart')) {
  185. lastMain = current;
  186. if (next && next.classList.contains('isSubPart')) {
  187. mainWithSubAfter.push({ index: i, main: current.innerText, sub: next.innerText, el: elements[i] });
  188. } else {
  189. mainWithoutSubAfter.push({ index: i, main: current.innerText, sub: "", el: elements[i] });
  190. }
  191. }
  192. if (current.classList.contains('isSubPart')) {
  193. let prevMain = lastMain && lastMain.classList.contains('isMainPart') ? lastMain.innerText : "";
  194. subWithoutMainBefore.push({ index: i, main: prevMain, sub: current.innerText, el: elements[i] });
  195. }
  196. }
  197. let titresFrise = [...mainWithoutSubAfter, ...mainWithSubAfter, ...subWithoutMainBefore];
  198. titresFrise.sort((a, b) => a.index - b.index);
  199. for (let i = titresFrise.length - 1; i > 0; i--) {
  200. let current = titresFrise[i];
  201. let next = titresFrise[i - 1];
  202. if (current.main === next.main && current.sub === next.sub) {
  203. titresFrise.splice(i, 1);
  204. }
  205. }
  206. titreFriseEl.setAttribute('id', 'titres_frise');
  207. titreFriseEl.innerHTML = `<p class="uppercase">${getCurrentTime(titresFrise[0].el)}</p><p>${titresFrise[0].main}</p><p class="font-authentic-60">${titresFrise[0].sub}</p>`;
  208. titreFriseEl.style.fontSize = "0.9em";
  209. titreFriseEl.style.zIndex = '0';
  210. titreFriseEl.style.position = "fixed";
  211. titreFriseEl.style.left = "60px";
  212. titreFriseEl.style.width = "10vw";
  213. titreFriseEl.style.lineHeight = "1.2";
  214. titreFriseEl.style.top = `${document.querySelector('#timeline_container').getBoundingClientRect().top - 8}px`;
  215. let main = document.querySelector('#main');
  216. main.prepend(titreFriseEl);
  217. // make the cursor move on scroll
  218. let cursor = document.querySelector('#cursor');
  219. let isCursorGrabbed = false;
  220. cursor.style.top = `${document.querySelector('#timeline_container').getBoundingClientRect().top}px`;
  221. let cursorPrevTranslateAmount = +cursor.style.transform.slice(0, -3).slice(11);
  222. document.addEventListener("scroll", (event) => {
  223. if (!isCursorGrabbed) {
  224. scrollMovement();
  225. }
  226. });
  227. // make the cursor draggable
  228. let prevMousePos = 0;
  229. cursor.addEventListener("mousedown", (event) => {
  230. if (!isCursorGrabbed) {
  231. event.preventDefault();
  232. isCursorGrabbed = true;
  233. prevMousePos = event.clientY;
  234. }
  235. });
  236. window.addEventListener("mousemove", (event) => {
  237. if (isCursorGrabbed) {
  238. event.preventDefault();
  239. let newPos = cursorPrevTranslateAmount + (event.clientY - prevMousePos);
  240. if (event.clientY < tlContainerHeight + tlContainer.offsetTop && event.clientY > tlContainer.offsetTop) {
  241. cursor.style.transform = `translateY(${newPos}px)`;
  242. window.scrollBy(0, (event.clientY - prevMousePos) * (bodyHeight / tlContainerHeight));
  243. cursorPrevTranslateAmount = +cursor.style.transform.slice(0, -3).slice(11);
  244. } else if (event.clientY <= tlContainer.offsetTop) {
  245. cursor.style.transform = "translateY(0px)";
  246. window.scroll(0, 0);
  247. cursorPrevTranslateAmount = 0;
  248. } else if (event.clientY >= tlContainerHeight + tlContainer.offsetTop) {
  249. cursor.style.transform = `translateY(${tlContainerHeight}px)`;
  250. window.scroll(0, bodyHeight);
  251. cursorPrevTranslateAmount = +cursor.style.transform.slice(0, -3).slice(11);
  252. }
  253. prevMousePos = event.clientY;
  254. }
  255. });
  256. window.addEventListener("mouseup", (event) => {
  257. if (isCursorGrabbed) {
  258. isCursorGrabbed = false;
  259. }
  260. });
  261. function getSteps() {
  262. let partRects = document.querySelectorAll('#timeline_container div');
  263. let tlElSteps = [];
  264. let total = 0;
  265. for (let i = 0; i < partRects.length; i++) {
  266. total = total + partRects[i].clientHeight;
  267. if (i === 0) total = total - partRects[0].clientHeight;
  268. tlElSteps.push(total);
  269. }
  270. let titles = document.querySelectorAll('.isMainPart, .isSubPart');
  271. let scrollSteps = [];
  272. for (let title of titles) {
  273. let nextLine = title.nextElementSibling;
  274. if (!nextLine?.classList.contains('isSubPart')) {
  275. scrollSteps.push(title.offsetTop);
  276. }
  277. }
  278. return({
  279. 'tlElSteps':tlElSteps,
  280. 'scrollSteps':scrollSteps
  281. });
  282. }
  283. function drawFixedTitles() {
  284. let tlContainer = document.querySelector('#timeline_container');
  285. let fixedTitlesContainer = document.createElement('div');
  286. fixedTitlesContainer.setAttribute('id', 'fixedTitlesContainer');
  287. main.prepend(fixedTitlesContainer);
  288. let index = 0;
  289. for (let titreFrise of titresFrise) {
  290. let titreFixedEl = document.createElement('div');
  291. titreFixedEl.style.position = 'fixed';
  292. titreFixedEl.style.zIndex = 1;
  293. titreFixedEl.style.display = 'none';
  294. titreFixedEl.style.opacity = '0';
  295. titreFixedEl.style.transition = 'opacity 0.3s ease-out';
  296. titreFixedEl.style.width = '10vw';
  297. titreFixedEl.style.top = `${tlContainer.children[index].getBoundingClientRect().top - 8}px`;
  298. titreFixedEl.style.left = '60px';
  299. titreFixedEl.style.fontSize = '0.9em';
  300. titreFixedEl.style.lineHeight = '1.2';
  301. let titreFixedElContent = document.createElement('p');
  302. titreFixedElContent.innerHTML = `<p>${titresFrise[titresFrise.length - index - 1].main}</p><p class="font-authentic-60">${titresFrise[titresFrise.length - index - 1].sub}</p>`;
  303. titreFixedElContent.style.backgroundColor = '#010d19';
  304. titreFixedEl.append(titreFixedElContent);
  305. let topGradient = document.createElement('div');
  306. topGradient.style.height = '10px';
  307. topGradient.style.width = '100%';
  308. topGradient.style.background = 'linear-gradient(to bottom, transparent, #010d19)';
  309. titreFixedEl.prepend(topGradient);
  310. let bottomGradient = document.createElement('div');
  311. bottomGradient.style.height = '10px';
  312. bottomGradient.style.width = '100%';
  313. bottomGradient.style.background = 'linear-gradient(to top, transparent, #010d19)';
  314. titreFixedEl.append(bottomGradient);
  315. fixedTitlesContainer.prepend(titreFixedEl);
  316. index++;
  317. }
  318. }
  319. drawFixedTitles();
  320. function toggleTitleHover(elIndex, state) {
  321. let fixedTitlesContainer = document.querySelector('#fixedTitlesContainer');
  322. let el = fixedTitlesContainer.children[elIndex];
  323. if (state === 'show') {
  324. el.style.display = 'block';
  325. setTimeout(() => {
  326. el.style.opacity = '1';
  327. }, 1);
  328. } else if (state === 'hide') {
  329. el.style.opacity = '0';
  330. setTimeout(() => {
  331. el.style.display = 'none';
  332. }, 300);
  333. }
  334. }
  335. function cursorMovement() {
  336. }
  337. let titres = document.querySelector('#titres_frise');
  338. let prevPartIndex = 0;
  339. let partRects = document.querySelectorAll('#timeline_container div');
  340. partRects = Array.from(partRects);
  341. partRects = partRects.reverse();
  342. partRects[0].style.width = '32px';
  343. function scrollMovement() {
  344. let currentScroll = window.scrollY;
  345. let cursorTopValue = 0;
  346. let tlPartHeight, tlPartBottom;
  347. for (let i = 0; i < getSteps().scrollSteps.length; i++) {
  348. if ((currentScroll >= getSteps().scrollSteps[i] && currentScroll <= getSteps().scrollSteps[i + 1]) ||
  349. (currentScroll >= getSteps().scrollSteps[i] && i === getSteps().scrollSteps.length - 1)) {
  350. // titres et temps
  351. titres.firstElementChild.innerText = getCurrentTime(titresFrise[i].el);
  352. let mainEl = titres.children[1];
  353. let subEl = titres.lastElementChild;
  354. if (mainEl.innerText != titresFrise[i].main || subEl.innerText != titresFrise[i].sub) {
  355. mainEl.innerText = titresFrise[i].main;
  356. subEl.innerText = titresFrise[i].sub;
  357. partRects[prevPartIndex].style.width = '22px';
  358. partRects[i].style.width = '32px';
  359. }
  360. activePartIndex = i;
  361. prevPartIndex = i;
  362. // curseur
  363. for (let j = 0; j < partRects.length; j++) {
  364. tlPartHeight = partRects[j].getBoundingClientRect().height
  365. tlPartBottom = partRects[j].getBoundingClientRect().top - tlContainer.getBoundingClientRect().top;
  366. cursorTopValue = tlPartBottom;
  367. // get the amount of the current scrollpart scrolled
  368. if (j === i) break;
  369. }
  370. let currentScrollPartBottom = getSteps().scrollSteps[i - 1] ? getSteps().scrollSteps[i - 1] : 0;
  371. let currentScrollPartHeight;
  372. if (getSteps().scrollSteps[i + 1]) {
  373. currentScrollPartHeight = getSteps().scrollSteps[i + 1] - currentScrollPartBottom;
  374. } else {
  375. currentScrollPartHeight = document.querySelector('body').scrollHeight - currentScrollPartBottom;
  376. }
  377. let currentScrollSincePartBottom = currentScroll - currentScrollPartBottom;
  378. let scrollPartProportion = currentScrollSincePartBottom / currentScrollPartHeight;
  379. cursorTopValue = cursorTopValue + tlPartHeight * (tlPartHeight / tlPartHeight * (scrollPartProportion - 0.3));
  380. if (cursorTopValue > 0) {
  381. cursor.style.transform = `translateY(${cursorTopValue}px)`;
  382. titres.style.transform = `translateY(${cursorTopValue}px)`;
  383. } else {
  384. cursor.style.transform = `translateY(0px)`;
  385. titres.style.transform = `translateY(0px)`;
  386. }
  387. break;
  388. }
  389. }
  390. }
  391. function getCurrentTime(titleEl) {
  392. let nextRow = titleEl.nextElementSibling;
  393. while(nextRow) {
  394. if (nextRow.offsetTop > window.scrollY &&
  395. nextRow.classList.contains('isContentPart')) {
  396. return(nextRow.firstElementChild.innerText);
  397. }
  398. nextRow = nextRow.nextElementSibling;
  399. }
  400. }
  401. });
  402. /**
  403. * @see {@link https://webpack.js.org/api/hot-module-replacement/}
  404. */
  405. if (import.meta.webpackHot) import.meta.webpackHot.accept(console.error);