app.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. import domReady from '@roots/sage/client/dom-ready';
  2. /**
  3. * Application entrypoint
  4. */
  5. domReady(async () => {
  6. window.addEventListener('load', function() {
  7. setTimeout(function() {
  8. window.scrollTo(0, 0);
  9. }, 0);
  10. });
  11. window.addEventListener('resize', function() {
  12. setTimeout(function() {
  13. window.scrollTo(0, 0);
  14. }, 0);
  15. });
  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. let editButtons = document.querySelectorAll(".edit-button");
  34. for (let editButton of editButtons) {
  35. let editContainer = editButton.parentElement;
  36. editContainer.style.height = `${editContainer.previousElementSibling.offsetHeight}px`;
  37. }
  38. // HEADER AU SCROLL
  39. let tableHead = document.querySelector("thead tr");
  40. let tHeadHeight = tableHead.offsetHeight;
  41. tableHead.style.maxHeight = `${tHeadHeight}px`;
  42. let headerHeight = document.querySelector("header").offsetHeight;
  43. window.onscroll = () => {
  44. tableHead.style.minHeight = `${headerHeight + 72}px`;
  45. let scroll = window.scrollY;
  46. let headerNewHeight = tHeadHeight - scroll;
  47. if (headerNewHeight > 72) {
  48. tableHead.style.height = `${headerHeight + headerNewHeight}px`;
  49. } else {
  50. tableHead.style.height = tableHead.style.minHeight;
  51. }
  52. }
  53. // C'EST LA POUR LES PRIVACY POLICY
  54. // texte d'explication du login popup
  55. // et privacy policy
  56. let loginPopupText = document.getElementById('content_login_popup');
  57. let privacyText = document.getElementById('content_privacy').innerHTML;
  58. loginPopupText = loginPopupText.innerText;
  59. let loginPopupTextWrapper = document.getElementsByClassName('xoo-el-sidebar');
  60. if (loginPopupTextWrapper[0]) {
  61. loginPopupTextWrapper[0].innerHTML = `<p>${loginPopupText}</p>`;
  62. }
  63. let policyDropdown = document.createElement('div');
  64. policyDropdown.style.width = "100%";
  65. policyDropdown.style.cursor = "pointer";
  66. policyDropdown.style.fontWeight = "bold";
  67. policyDropdown.style.display = "flex";
  68. policyDropdown.style.justifyContent = "space-between";
  69. policyDropdown.style.backgroundColor = "white";
  70. policyDropdown.style.padding = "20px 30px";
  71. let policyDropdownTitle = document.createElement('p');
  72. policyDropdownTitle.style.padding = "0";
  73. let policyDropdownPlus = document.createElement('p');
  74. policyDropdownPlus.style.padding = "0";
  75. policyDropdownPlus.innerText = '+';
  76. policyDropdownTitle.innerText = "Politique de confidentialité";
  77. policyDropdown.appendChild(policyDropdownTitle);
  78. policyDropdown.appendChild(policyDropdownPlus);
  79. let privacyPolicyContent = document.createElement('div');
  80. privacyPolicyContent.innerHTML = privacyText;
  81. privacyPolicyContent.style.width = "100%";
  82. privacyPolicyContent.style.padding = "0px";
  83. let policyParagraphs = privacyPolicyContent.querySelectorAll('p, h2');
  84. for (let policyParagraph of policyParagraphs) {
  85. policyParagraph.style.padding = '0';
  86. policyParagraph.style.marginBottom = '15px';
  87. }
  88. privacyPolicyContent.style.height = "0px";
  89. privacyPolicyContent.style.overflow = "hidden";
  90. let policyOpen = false;
  91. policyDropdown.addEventListener('click', togglePolicy);
  92. if (loginPopupTextWrapper[0]) {
  93. loginPopupTextWrapper[0].appendChild(policyDropdown);
  94. loginPopupTextWrapper[0].style.overflowY = "scroll";
  95. loginPopupTextWrapper[0].appendChild(privacyPolicyContent);
  96. }
  97. function togglePolicy() {
  98. if (policyOpen) {
  99. privacyPolicyContent.style.height = "0px";
  100. privacyPolicyContent.style.padding = "0px";
  101. policyOpen = false;
  102. } else {
  103. privacyPolicyContent.style.height = "auto";
  104. privacyPolicyContent.style.padding = "10px 20px";
  105. policyOpen = true;
  106. }
  107. }
  108. // titres de parties dans le tableau
  109. let mainpartTitless = document.querySelectorAll('.isMainPart');
  110. for (let mainpartTitles of mainpartTitless) {
  111. if (mainpartTitles.nextElementSibling.classList.contains('isSubPart')) {
  112. mainpartTitles.firstElementChild.firstElementChild.style.height = "1.5rem";
  113. mainpartTitles.firstElementChild.style.marginBottom = "-0.25rem";
  114. mainpartTitles.style.borderBottom = "0";
  115. mainpartTitles.style.paddingBottom = "0";
  116. mainpartTitles.nextElementSibling.style.paddingTop = "0";
  117. }
  118. }
  119. // couleurs titres
  120. let colors = [
  121. {'red' : 'cf0118'},
  122. {'blue1': '0101c4'},
  123. {'blue2': '01049e'},
  124. {'blue3': '010678'},
  125. {'blue4': '010952'},
  126. {'blue5': '00113c'},
  127. {'yellow1': 'ade719'},
  128. {'yellow2': '8cc700'},
  129. {'yellow3': '74af00'},
  130. {'yellow4': '5c9900'},
  131. {'yellow5': '377600'},
  132. {'pink1': 'cf0118'},
  133. {'pink2': 'a10418'}
  134. ];
  135. let titles = document.querySelectorAll('.isMainPart, .isSubPart');
  136. let partTitles = [];
  137. for (let title of titles) {
  138. if (!title.nextElementSibling.classList.contains('isSubPart')) {
  139. partTitles.push(title);
  140. }
  141. }
  142. for (let i = 0; i < partTitles.length; i++) {
  143. if (partTitles[i].previousElementSibling?.classList.contains('isMainPart')) {
  144. partTitles[i].previousElementSibling.firstElementChild.firstElementChild.style.backgroundColor = "#" + Object.values(colors[i])[0];
  145. }
  146. partTitles[i].firstElementChild.firstElementChild.style.backgroundColor = "#" + Object.values(colors[i])[0];
  147. }
  148. // set parts rectangles
  149. function convertToSeconds(timeStr) {
  150. let [hourStr, minStr] = timeStr.split('h');
  151. if (!minStr) {
  152. minStr = hourStr;
  153. hourStr = '0';
  154. }
  155. minStr = minStr.replace('’', ':');
  156. minStr = minStr.replace("'", ':');
  157. const [min, sec] = minStr.split(':');
  158. return parseInt(hourStr) * 3600 + parseInt(min) * 60 + parseInt(sec);
  159. }
  160. let partTimesNodes = document.querySelectorAll('body #app main tbody tr:not(.isContentPart) + tr:not(.isSubPart) td:first-of-type');
  161. let partTimes = Array.from(partTimesNodes);
  162. for (let i = 0; i < partTimes.length; i++) {
  163. partTimes[i] = convertToSeconds(partTimes[i].innerText);
  164. }
  165. let lastTime = document.querySelectorAll('body #app main tbody tr:last-of-type td:first-of-type');
  166. partTimes.push(convertToSeconds(lastTime[0].innerText));
  167. let partDurations = [];
  168. for (let i = 0; i < partTimes.length - 1; i++) {
  169. partDurations.push(partTimes[i + 1] - partTimes[i]);
  170. }
  171. let totalTime = convertToSeconds(lastTime[0].innerText);
  172. let tlContainer, tlContainerHeight;
  173. let partBlockHeights = [];
  174. let activePartIndex = 0;
  175. function getAllHeights() {
  176. partBlockHeights = [];
  177. tlContainer = document.querySelector('#timeline_container');
  178. let header = document.querySelector('header'), footer = document.querySelector('footer');
  179. tlContainer.style.height = `calc(100vh - ${header.offsetHeight}px - ${footer.offsetHeight}px - 60px)`;
  180. tlContainer.style.top = `${document.querySelector('header').offsetHeight + 30}px`;
  181. tlContainerHeight = tlContainer.offsetHeight;
  182. for (let partDuration of partDurations) {
  183. partBlockHeights.push(partDuration / totalTime * tlContainerHeight);
  184. }
  185. }
  186. getAllHeights();
  187. function drawFriseRects() {
  188. for (let i = 0; i < partBlockHeights.length; i++) {
  189. let partDiv = document.createElement('div');
  190. partDiv.style.width = "22px";
  191. partDiv.style.height = partBlockHeights[i] + "px";
  192. partDiv.style.backgroundColor = "#" + Object.values(colors[i])[0];
  193. partDiv.style.borderBottom = "solid 1px #010d19";
  194. partDiv.style.borderTop = "solid 1px #010d19";
  195. partDiv.style.transition = "width 0.3s ease-out";
  196. partDiv.style.cursor = "pointer";
  197. tlContainer.prepend(partDiv);
  198. tlContainer.children[0].addEventListener("mouseenter", function() {
  199. let el = tlContainer.children[tlContainer.children.length - 1 - i];
  200. if (Array.from(el.parentNode.children).length - Array.from(el.parentNode.children).indexOf(el) - 1 != activePartIndex) {
  201. el.style.width = "32px";
  202. toggleTitleHover(i, 'show');
  203. }
  204. });
  205. tlContainer.children[0].addEventListener("mouseleave", function() {
  206. let el = tlContainer.children[tlContainer.children.length - 1 - i];
  207. if (Array.from(el.parentNode.children).length - Array.from(el.parentNode.children).indexOf(el) - 1 != activePartIndex) {
  208. el.style.width = "22px";
  209. }
  210. toggleTitleHover(i, 'hide');
  211. });
  212. tlContainer.children[0].addEventListener("click", function() {
  213. isScrollingFromGrab = false;
  214. titresFrise[i].el.scrollIntoView({ behavior: 'smooth', block: 'center' });
  215. });
  216. }
  217. }
  218. drawFriseRects();
  219. window.addEventListener('resize', () => {
  220. while(tlContainer.lastChild) {
  221. tlContainer.removeChild(tlContainer.lastChild);
  222. }
  223. getAllHeights();
  224. drawFriseRects();
  225. });
  226. // titres parties frise
  227. let titreFriseEl = document.createElement('div');
  228. let elements = Array.from(document.querySelectorAll('.isMainPart, .isSubPart'));
  229. let mainWithoutSubAfter = [];
  230. let mainWithSubAfter = [];
  231. let subWithoutMainBefore = [];
  232. let lastMain = null;
  233. let grabbing = false;
  234. for (let i = 0; i < elements.length; i++) {
  235. let current = elements[i];
  236. let next = elements[i + 1];
  237. if (current.classList.contains('isMainPart')) {
  238. lastMain = current;
  239. if (next && next.classList.contains('isSubPart')) {
  240. mainWithSubAfter.push({ index: i, main: current.innerText, sub: next.innerText, el: elements[i] });
  241. } else {
  242. mainWithoutSubAfter.push({ index: i, main: current.innerText, sub: "", el: elements[i] });
  243. }
  244. }
  245. if (current.classList.contains('isSubPart')) {
  246. let prevMain = lastMain && lastMain.classList.contains('isMainPart') ? lastMain.innerText : "";
  247. subWithoutMainBefore.push({ index: i, main: prevMain, sub: current.innerText, el: elements[i] });
  248. }
  249. }
  250. let titresFrise = [...mainWithoutSubAfter, ...mainWithSubAfter, ...subWithoutMainBefore];
  251. titresFrise.sort((a, b) => a.index - b.index);
  252. for (let i = titresFrise.length - 1; i > 0; i--) {
  253. let current = titresFrise[i];
  254. let next = titresFrise[i - 1];
  255. if (current.main === next.main && current.sub === next.sub) {
  256. titresFrise.splice(i, 1);
  257. }
  258. }
  259. titreFriseEl.setAttribute('id', 'titres_frise');
  260. titreFriseEl.innerHTML = `
  261. <p class="uppercase">${getCurrentTime(titresFrise[0].el)}</p>
  262. <p>${titresFrise[0].main}</p>
  263. <p class="font-authentic-60">${titresFrise[0].sub}</p>
  264. `;
  265. titreFriseEl.style.fontSize = '0.9em';
  266. titreFriseEl.style.zIndex = '0';
  267. titreFriseEl.style.position = 'fixed';
  268. titreFriseEl.style.left = '60px';
  269. titreFriseEl.style.width = '10vw';
  270. titreFriseEl.style.lineHeight = '1.2';
  271. titreFriseEl.style.marginTop = '-8px';
  272. titreFriseEl.style.top = `${document.querySelector('#timeline_container').getBoundingClientRect().top}px`;
  273. let main = document.querySelector('#main');
  274. main.prepend(titreFriseEl);
  275. // création et togle des titres au survol des div de la timeline
  276. function drawFixedTitles() {
  277. let tlContainer = document.querySelector('#timeline_container');
  278. let fixedTitlesContainer = document.createElement('div');
  279. fixedTitlesContainer.setAttribute('id', 'fixedTitlesContainer');
  280. main.prepend(fixedTitlesContainer);
  281. for (let index = 0; index < titresFrise.length; index++) {
  282. let titreFixedEl = document.createElement('div');
  283. titreFixedEl.style.position = 'fixed';
  284. titreFixedEl.style.zIndex = 1;
  285. titreFixedEl.style.display = 'none';
  286. titreFixedEl.style.opacity = '0';
  287. titreFixedEl.style.transition = 'opacity 0.3s ease-out';
  288. titreFixedEl.style.width = '10vw';
  289. titreFixedEl.style.top = `${tlContainer.children[index].getBoundingClientRect().top - 8}px`;
  290. titreFixedEl.style.left = '60px';
  291. titreFixedEl.style.fontSize = '0.9em';
  292. titreFixedEl.style.lineHeight = '1.2';
  293. let titreFixedElContent = document.createElement('p');
  294. titreFixedElContent.innerHTML = `
  295. <p>${titresFrise[titresFrise.length - index - 1].main}</p>
  296. <p class="font-authentic-60">${titresFrise[titresFrise.length - index - 1].sub}</p>
  297. `;
  298. titreFixedElContent.style.backgroundColor = '#010d19';
  299. titreFixedEl.append(titreFixedElContent);
  300. let topGradient = document.createElement('div');
  301. topGradient.style.height = '10px';
  302. topGradient.style.width = '100%';
  303. topGradient.style.background = 'linear-gradient(to bottom, transparent, #010d19)';
  304. titreFixedEl.prepend(topGradient);
  305. let bottomGradient = document.createElement('div');
  306. bottomGradient.style.height = '10px';
  307. bottomGradient.style.width = '100%';
  308. bottomGradient.style.background = 'linear-gradient(to top, transparent, #010d19)';
  309. titreFixedEl.append(bottomGradient);
  310. fixedTitlesContainer.prepend(titreFixedEl);
  311. }
  312. }
  313. drawFixedTitles();
  314. function toggleTitleHover(elIndex, state) {
  315. let fixedTitlesContainer = document.querySelector('#fixedTitlesContainer');
  316. let el = fixedTitlesContainer.children[elIndex];
  317. if (state === 'show') {
  318. el.style.display = 'block';
  319. setTimeout(() => {
  320. el.style.opacity = '1';
  321. }, 1);
  322. } else if (state === 'hide') {
  323. el.style.opacity = '0';
  324. setTimeout(() => {
  325. el.style.display = 'none';
  326. }, 300);
  327. }
  328. }
  329. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  330. // ICI IL Y A LE GRAB DU CURSEUR DE LA TL
  331. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  332. // make the cursor move on scroll
  333. let cursor = document.querySelector('#cursor');
  334. cursor.style.top = `${document.querySelector('#timeline_container').getBoundingClientRect().top}px`;
  335. cursor.style.cursor = 'grab';
  336. let titres = document.querySelector('#titres_frise');
  337. titres.style.cursor = 'grab';
  338. let partRects = document.querySelectorAll('#timeline_container div');
  339. partRects = Array.from(partRects);
  340. partRects = partRects.reverse();
  341. partRects[0].style.width = '32px';
  342. document.addEventListener("scroll", () => {
  343. if (!grabbing) {
  344. displayCurrentPartTitle(getCurrentPartFromScroll());
  345. moveCursorFromScroll(getCurrentPartFromScroll());
  346. }
  347. });
  348. function makeElementDraggable(element, relatedEl) {
  349. let offsetY;
  350. element.addEventListener('mousedown', (e) => {
  351. let elTransformY;
  352. if (!element.style.transform) {
  353. elTransformY = 0;
  354. } else {
  355. elTransformY = +element.style.transform.split('(')[1].split('p')[0];
  356. }
  357. e.preventDefault();
  358. grabbing = true;
  359. offsetY = e.clientY - elTransformY;
  360. element.style.cursor = 'grabbing';
  361. });
  362. document.addEventListener('mousemove', (e) => {
  363. if (grabbing) {
  364. if (e.clientY < tlContainerHeight + tlContainer.offsetTop && e.clientY > tlContainer.offsetTop) {
  365. const y = e.clientY - offsetY;
  366. element.style.transform = `translateY(${y}px)`;
  367. relatedEl.style.transform = `translateY(${y}px)`;
  368. if (!isNaN(y)) displayCurrentPartTitle(getCurrentPartFromCursor(y));
  369. } else if (e.clientY < tlContainer.offsetTop + 10) {
  370. element.style.transform = `translateY(0px)`;
  371. relatedEl.style.transform = `translateY(0px)`;
  372. } else if (e.clientY >= tlContainerHeight + tlContainer.offsetTop) {
  373. element.style.transform = `translateY(${tlContainerHeight}px)`;
  374. relatedEl.style.transform = `translateY(${tlContainerHeight}px)`;
  375. }
  376. }
  377. });
  378. document.addEventListener('mouseup', () => {
  379. if (grabbing) scrollOnGrab(element);
  380. element.style.cursor = 'grab';
  381. grabbing = false;
  382. });
  383. }
  384. makeElementDraggable(cursor, titres);
  385. makeElementDraggable(titres, cursor);
  386. // get heights of parts dans le tableau et dans la timeline
  387. function getSteps() {
  388. let tlElSteps = [];
  389. for (let i = 0; i < partRects.length; i++) {
  390. tlElSteps.push(partRects[i].offsetTop);
  391. }
  392. let titles = document.querySelectorAll('.isMainPart, .isSubPart');
  393. let scrollSteps = [];
  394. for (let title of titles) {
  395. let nextLine = title.nextElementSibling;
  396. if (!nextLine?.classList.contains('isSubPart')) {
  397. scrollSteps.push(title.offsetTop);
  398. }
  399. }
  400. return({
  401. 'tlElSteps':tlElSteps,
  402. 'scrollSteps':scrollSteps
  403. });
  404. }
  405. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  406. // ICI IL Y A LE SCROLL DU GRAB
  407. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  408. let isScrollingFromGrab = false;
  409. function scrollOnGrab(el) {
  410. let scrollValue =
  411. ((getSteps().scrollSteps[getCursorPositionInTimelinePart(el).stepAfterMouseUp] - getSteps().scrollSteps[getCursorPositionInTimelinePart(el).stepAfterMouseUp - 1]) * getCursorPositionInTimelinePart(el).proportionInPart)
  412. + getSteps().scrollSteps[getCursorPositionInTimelinePart(el).stepAfterMouseUp];
  413. isScrollingFromGrab = true;
  414. window.scrollTo({ top: scrollValue, behavior: 'smooth' });
  415. setTimeout(() => {
  416. isScrollingFromGrab = false;
  417. }, 2000);
  418. }
  419. function getCursorPositionInTimelinePart(el) {
  420. let elTransformY;
  421. if (!el.style.transform) {
  422. elTransformY = 0;
  423. } else {
  424. elTransformY = +el.style.transform.split('(')[1].split('p')[0];
  425. }
  426. let tlPartHeight, tlPartBottom, tlPartTop, proportionInPart, stepAfterMouseUp;
  427. for (let j = 0; j < partRects.length; j++) {
  428. if (j === getCurrentPartFromCursor(elTransformY)) {
  429. tlPartHeight = partRects[j].getBoundingClientRect().height;
  430. tlPartBottom = partRects[j].getBoundingClientRect().top - tlContainer.getBoundingClientRect().top;
  431. tlPartTop = tlPartBottom - tlPartHeight;
  432. proportionInPart = ((tlPartHeight - (elTransformY - tlPartTop)) / tlPartHeight) * -1;
  433. if (proportionInPart > 0 && proportionInPart < 1) {
  434. stepAfterMouseUp = j;
  435. return {stepAfterMouseUp, proportionInPart};
  436. } else {
  437. stepAfterMouseUp = j;
  438. proportionInPart = 0;
  439. return {stepAfterMouseUp, proportionInPart};
  440. }
  441. }
  442. }
  443. }
  444. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  445. // ICI IL Y A LE RAPPORT SCROLL / TIMELINE
  446. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  447. function moveCursorFromScroll(currentPartIndex) {
  448. if (!isScrollingFromGrab) {
  449. let currentScroll = window.scrollY;
  450. let cursorTopValue = 0;
  451. let tlPartHeight, tlPartBottom;
  452. for (let j = 0; j < partRects.length; j++) {
  453. tlPartHeight = partRects[j].getBoundingClientRect().height
  454. tlPartBottom = partRects[j].getBoundingClientRect().top - tlContainer.getBoundingClientRect().top;
  455. cursorTopValue = tlPartBottom;
  456. // get the amount of the current scrollpart scrolled
  457. if (j === currentPartIndex) break;
  458. }
  459. let currentScrollPartBottom = getSteps().scrollSteps[currentPartIndex - 1] ? getSteps().scrollSteps[currentPartIndex - 1] : 0;
  460. let currentScrollPartHeight;
  461. if (getSteps().scrollSteps[currentPartIndex + 1]) {
  462. currentScrollPartHeight = getSteps().scrollSteps[currentPartIndex + 1] - currentScrollPartBottom;
  463. } else {
  464. currentScrollPartHeight = document.querySelector('body').scrollHeight - currentScrollPartBottom;
  465. }
  466. let currentScrollSincePartBottom = currentScroll - currentScrollPartBottom;
  467. let scrollPartProportion = currentScrollSincePartBottom / currentScrollPartHeight;
  468. cursorTopValue = cursorTopValue + tlPartHeight * (tlPartHeight / tlPartHeight * (scrollPartProportion - 0.3));
  469. if (cursorTopValue > 0) {
  470. cursor.style.transform = `translateY(${cursorTopValue}px)`;
  471. titres.style.transform = `translateY(${cursorTopValue}px)`;
  472. } else {
  473. cursor.style.transform = `translateY(0px)`;
  474. titres.style.transform = `translateY(0px)`;
  475. }
  476. }
  477. }
  478. let prevPartIndex = 0;
  479. let lastCallTimestamp = 0;
  480. function displayCurrentPartTitle(currentPartIndex) {
  481. if (isNaN(currentPartIndex)) currentPartIndex = 0;
  482. const currentTime = performance.now();
  483. if (currentTime - lastCallTimestamp >= 400) {
  484. lastCallTimestamp = currentTime;
  485. titres.firstElementChild.innerText = getCurrentTime(titresFrise[currentPartIndex]?.el); // ICI POUR METTRE LE TEMPS BIEN
  486. }
  487. let mainEl = titres.children[1];
  488. let subEl = titres.lastElementChild;
  489. if (mainEl.innerText != titresFrise[currentPartIndex]?.main || subEl.innerText != titresFrise[currentPartIndex]?.sub) {
  490. mainEl.innerText = titresFrise[currentPartIndex]?.main;
  491. subEl.innerText = titresFrise[currentPartIndex]?.sub;
  492. partRects[prevPartIndex].style.width = '22px';
  493. partRects[currentPartIndex].style.width = '32px';
  494. }
  495. activePartIndex = currentPartIndex;
  496. prevPartIndex = currentPartIndex;
  497. }
  498. function getCurrentPartFromScroll() {
  499. let currentScroll = window.scrollY;
  500. for (let i = 0; i < getSteps().scrollSteps.length; i++) {
  501. if (
  502. (currentScroll + window.innerHeight / 2 >= getSteps().scrollSteps[i]
  503. && currentScroll + window.innerHeight / 2 <= getSteps().scrollSteps[i + 1]) ||
  504. (currentScroll + window.innerHeight / 2 >= getSteps().scrollSteps[i]
  505. && i === getSteps().scrollSteps.length - 1)
  506. ) {
  507. return(i);
  508. }
  509. }
  510. }
  511. function getCurrentPartFromCursor(cursorTransformY) {
  512. for (let i = 0; i < getSteps().tlElSteps.length; i++) {
  513. if (cursorTransformY >= getSteps().tlElSteps[i] && cursorTransformY < getSteps().tlElSteps[i + 1]) {
  514. return(i);
  515. } else if (cursorTransformY > getSteps().tlElSteps[getSteps().tlElSteps.length - 1]) {
  516. return(getSteps().tlElSteps.length - 1);
  517. }
  518. }
  519. }
  520. ///////////////////////////////////////
  521. // ICI LE GETCURRENTTIME !!!!!!!!!!!!!!
  522. ///////////////////////////////////////
  523. function getCurrentTime(titleEl) {
  524. let nextRow = titleEl?.nextElementSibling;
  525. if (!grabbing) {
  526. while(nextRow) {
  527. if (nextRow.offsetTop > window.scrollY &&
  528. nextRow.classList.contains('isContentPart')) {
  529. return(nextRow.firstElementChild.innerText);
  530. }
  531. nextRow = nextRow.nextElementSibling;
  532. }
  533. } else {
  534. let cursor = document.querySelector('#cursor');
  535. let allRowsUnder = [];
  536. nextRow = nextRow.nextElementSibling.nextElementSibling;
  537. while(nextRow) {
  538. if (nextRow.classList.contains('isMainPart') || nextRow.classList.contains('isSubPart')) {
  539. break;
  540. }
  541. allRowsUnder.push(nextRow);
  542. nextRow = nextRow.nextElementSibling;
  543. }
  544. return allRowsUnder[Math.floor(allRowsUnder.length * getCursorPositionInTimelinePart(cursor).proportionInPart)].firstElementChild.innerText;
  545. }
  546. }
  547. // désactive le loading quand les éléments sont affichés correctement
  548. setTimeout(() => {
  549. let loadingEl = document.getElementById('loading');
  550. loadingEl.style.opacity = "0";
  551. setTimeout(() => {
  552. loadingEl.style.display = "none";
  553. }, 200);
  554. }, 100);
  555. // recherche
  556. let searchableContent = document.querySelectorAll('tr td:not(:first-of-type):not(:last-of-type)');
  557. let searchInput = document.querySelector('input[type="search"]');
  558. let searchResults = document.querySelector('#search_results');
  559. let isResultOpen = false;
  560. let resultAmount = 0;
  561. let resultAmountText = document.querySelector('#result_amount');
  562. let hilightedWords;
  563. let typingTimer;
  564. let currentSelectedWord = 0;
  565. let downArrow = document.querySelector('#search_results div div img:first-of-type');
  566. let upArrow = document.querySelector('#search_results div div img:last-of-type');
  567. let thereAreResults = false;
  568. let inputIsActive = false;
  569. searchInput.addEventListener('focus', () => { inputIsActive = true; toggleSearchResults(); });
  570. searchInput.addEventListener('blur', () => { inputIsActive = false; });
  571. searchInput.addEventListener('keydown', function(e) {
  572. triggerSearch();
  573. });
  574. function triggerSearch() {
  575. setTimeout(() => {
  576. hilightedWords = [];
  577. removeHighlightTags();
  578. resultAmount = 0;
  579. let input = searchInput.value.toLowerCase();
  580. if (searchInput.value.length >= 3) {
  581. thereAreResults = true;
  582. clearTimeout(typingTimer);
  583. typingTimer = setTimeout(function() {
  584. searchInContent(input);
  585. /* if (!isResultOpen) {
  586. toggleSearchResults();
  587. }
  588. */
  589. let currentScroll = window.scrollY;
  590. if (hilightedWords.length != 0) {
  591. searchResults.querySelector('div p:first-of-type').style.display = "block";
  592. searchResults.querySelector('div p:last-of-type').style.display = "none";
  593. for (let i = 0; i < hilightedWords.length; i++) {
  594. let wordBoundingTop = hilightedWords[i].getBoundingClientRect().top;
  595. if (hilightedWords.length <= 1) {
  596. let scrollValue = (wordBoundingTop + currentScroll) - window.innerHeight / 2;
  597. window.scrollTo({ top: scrollValue, behavior: 'smooth' });
  598. currentSelectedWord = 1;
  599. resultAmountText.innerText = currentSelectedWord + "/" + resultAmountText.innerText;
  600. upArrow.classList.add('disabled');
  601. downArrow.classList.add('disabled');
  602. } else {
  603. if (currentScroll < hilightedWords[i].getBoundingClientRect().top && i === 0) {
  604. let scrollValue = (wordBoundingTop + currentScroll) - window.innerHeight / 2;
  605. window.scrollTo({ top: scrollValue, behavior: 'smooth' });
  606. currentSelectedWord = 1;
  607. resultAmountText.innerText = currentSelectedWord + "/" + resultAmountText.innerText;
  608. upArrow.classList.add('disabled');
  609. downArrow.classList.remove('disabled');
  610. break;
  611. } else if (
  612. currentScroll < wordBoundingTop + currentScroll && currentScroll > hilightedWords[i - 1]?.getBoundingClientRect().top + currentScroll
  613. ) {
  614. let scrollValue = (wordBoundingTop + currentScroll) - window.innerHeight / 2;
  615. window.scrollTo({ top: scrollValue, behavior: 'smooth' });
  616. currentSelectedWord = i + 1;
  617. resultAmountText.innerText = currentSelectedWord + "/" + resultAmountText.innerText;
  618. upArrow.classList.remove('disabled');
  619. downArrow.classList.remove('disabled');
  620. break;
  621. } else if (currentScroll > wordBoundingTop && i === hilightedWords.length - 1) {
  622. let scrollValue = (wordBoundingTop + currentScroll) - window.innerHeight / 2;
  623. window.scrollTo({ top: scrollValue, behavior: 'smooth' });
  624. currentSelectedWord = hilightedWords.length;
  625. resultAmountText.innerText = currentSelectedWord + "/" + resultAmountText.innerText;
  626. upArrow.classList.remove('disabled');
  627. downArrow.classList.add('disabled');
  628. break;
  629. }
  630. }
  631. }
  632. } else {
  633. searchResults.querySelector('div p:first-of-type').style.display = "none";
  634. searchResults.querySelector('div p:last-of-type').style.display = "block";
  635. upArrow.classList.add('disabled');
  636. downArrow.classList.add('disabled');
  637. }
  638. }, 800);
  639. } else {
  640. removeHighlightTags();
  641. thereAreResults = false;
  642. searchResults.querySelector('div p:first-of-type').style.display = "none";
  643. searchResults.querySelector('div p:last-of-type').style.display = "block";
  644. upArrow.classList.add('disabled');
  645. downArrow.classList.add('disabled');
  646. /* if (isResultOpen) {
  647. toggleSearchResults();
  648. }
  649. */ }
  650. }, 10);
  651. }
  652. function searchInContent(input) {
  653. for (let content of searchableContent) {
  654. if (content.innerText != '') {
  655. for (let textEl of content.children) {
  656. if (textEl.innerText !== '') {
  657. if (textEl.innerHTML.toLowerCase().includes(input)) {
  658. let splitContent = textEl.innerHTML.toLowerCase().split(input);
  659. let processedText = '';
  660. for (let i = 0; i < splitContent.length; i++) {
  661. if (splitContent[0] !== '' || splitContent[splitContent.length - 1] !== '') {
  662. if (i === 0) {
  663. processedText += textEl.innerHTML.substring(0, splitContent[i].length);
  664. } else {
  665. let amountOfTextToConcatenate = 0;
  666. for (let j = 0; j <= i - 1; j ++) {
  667. amountOfTextToConcatenate += splitContent[j].length + input.length;
  668. }
  669. processedText +=
  670. '<span class="highlight">' +
  671. textEl.innerHTML.substring(amountOfTextToConcatenate - input.length, amountOfTextToConcatenate) +
  672. '</span>' +
  673. textEl.innerHTML.substring(
  674. amountOfTextToConcatenate, amountOfTextToConcatenate + splitContent[i].length
  675. );
  676. }
  677. } else if (splitContent[splitContent.length - 1] === '' && splitContent[0] === '') {
  678. processedText = '<span class="highlight">' + textEl.innerHTML.substring(splitContent[i - 1].length, splitContent[i - 1].length + input.length) + '</span>';
  679. }
  680. }
  681. textEl.innerHTML = processedText;
  682. hilightedWords = document.querySelectorAll('.highlight');
  683. resultAmount = hilightedWords.length;
  684. }
  685. }
  686. }
  687. }
  688. }
  689. resultAmountText.innerText = resultAmount;
  690. }
  691. function removeHighlightTags() {
  692. for (let content of searchableContent) {
  693. if (content.innerHTML.includes('<span class="highlight">')) {
  694. content.innerHTML = content.innerHTML.replace(/<span class="highlight">|<\/span>/g, '');
  695. }
  696. }
  697. }
  698. function toggleSearchResults() {
  699. if (thereAreResults || inputIsActive) {
  700. searchResults.style.display = "block";
  701. searchResults.style.opacity = 1;
  702. searchResults.style.maxHeight = "1000px";
  703. isResultOpen = true;
  704. } else {
  705. searchResults.style.opacity = 0;
  706. searchResults.style.maxHeight = "0px";
  707. isResultOpen = false;
  708. setTimeout(() => {
  709. searchResults.style.display = "none";
  710. }, 300);
  711. }
  712. }
  713. upArrow.addEventListener('click', function (el) {
  714. if (!el.target.classList.contains('disabled')) {
  715. let currentScroll = window.scrollY;
  716. currentSelectedWord--;
  717. let wordBoundingTop = hilightedWords[currentSelectedWord - 1].getBoundingClientRect().top;
  718. let scrollValue = (wordBoundingTop + currentScroll) - window.innerHeight / 2;
  719. window.scrollTo({ top: scrollValue, behavior: 'smooth' });
  720. resultAmountText.innerText = currentSelectedWord + "/" + resultAmountText.innerText.split('/')[1];
  721. if (currentSelectedWord === 1) {
  722. upArrow.classList.add('disabled');
  723. downArrow.classList.remove('disabled');
  724. } else {
  725. upArrow.classList.remove('disabled');
  726. downArrow.classList.remove('disabled');
  727. }
  728. }
  729. });
  730. downArrow.addEventListener('click', function (el) {
  731. if (!el.target.classList.contains('disabled')) {
  732. let currentScroll = window.scrollY;
  733. currentSelectedWord++;
  734. let wordBoundingTop = hilightedWords[currentSelectedWord - 1].getBoundingClientRect().top;
  735. let scrollValue = (wordBoundingTop + currentScroll) - window.innerHeight / 2;
  736. window.scrollTo({ top: scrollValue, behavior: 'smooth' });
  737. resultAmountText.innerText = currentSelectedWord + "/" + resultAmountText.innerText.split('/')[1];
  738. if (currentSelectedWord === hilightedWords.length) {
  739. downArrow.classList.add('disabled');
  740. upArrow.classList.remove('disabled');
  741. } else {
  742. downArrow.classList.remove('disabled');
  743. upArrow.classList.remove('disabled');
  744. }
  745. }
  746. });
  747. let tagsDiv = document.querySelector('#search_results > div:last-of-type');
  748. window.addEventListener('click', function (el) {
  749. if (!searchResults.contains(el.target) && isResultOpen && el.target != searchInput && el.target != tagsDiv) {
  750. toggleSearchResults();
  751. }
  752. });
  753. let searchWordList = document.querySelector('#content_search_tag');
  754. searchWordList = searchWordList.innerText.substring(1, searchWordList.innerText.length - 1).split(', ');
  755. for (let tag of searchWordList) {
  756. let tagWrapper = document.createElement('p');
  757. tagWrapper.innerText = tag;
  758. tagWrapper.addEventListener('click', function () {
  759. searchInput.value = tag;
  760. triggerSearch();
  761. });
  762. tagsDiv.appendChild(tagWrapper);
  763. }
  764. });
  765. /**
  766. * @see {@link https://webpack.js.org/api/hot-module-replacement/}
  767. */
  768. if (import.meta.webpackHot) import.meta.webpackHot.accept(console.error);