layout.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. // fonction s'éxecute après le rendu de pagedJS
  2. // cf https://pagedjs.org/documentation/10-handlers-hooks-and-custom-javascript/
  3. class setMarginTexts extends Paged.Handler {
  4. constructor(chunker, polisher, caller) {
  5. super(chunker, polisher, caller);
  6. }
  7. afterPreview(pages) {
  8. // cleaner pour que les paragraphes tombent sur la marge haute
  9. for(let i = 0; i < labeurs.length; i++) {
  10. if (labeurs[i] == labeurs[i].parentNode.firstElementChild
  11. && !labeurs[i].firstElementChild?.hasAttribute("data-split-from")) {
  12. if (labeurs[i].firstElementChild) {
  13. labeurs[i].firstElementChild.style.marginTop = "0px";
  14. }
  15. }
  16. }
  17. // pareil pour les titres temps
  18. for (let i = 0; i < moments.length; i++) {
  19. if (moments[i].previousElementSibling?.tagName === "P"
  20. && moments[i].previousElementSibling == moments[i].parentNode.firstElementChild) {
  21. moments[i].parentNode.removeChild(moments[i].parentNode.firstElementChild);
  22. }
  23. }
  24. // enlever les paragraphes vides
  25. let paragraphes = document.querySelectorAll("p");
  26. for (let i = 0; i < paragraphes.length; i++) {
  27. if (paragraphes[i].innerHTML == "") {
  28. paragraphes[i].remove();
  29. }
  30. }
  31. // images collées en bas
  32. let bottomImgs = document.querySelectorAll('.bottomimg, .tripleimgs_bottom, .tripleimgs2_bottom');
  33. for (let i = 0; i < bottomImgs.length; i++) {
  34. let page = bottomImgs[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  35. bottomImgs[i].style.transform = 'translateY(' + (page.getBoundingClientRect().bottom - bottomImgs[i].lastElementChild.getBoundingClientRect().bottom) + 'px)';
  36. }
  37. // éléments justifiés pas nécessaires
  38. let justifiedSplitEl = document.querySelectorAll("[data-align-last-split-element='justify']");
  39. for (let i = 0; i < justifiedSplitEl.length; i++) {
  40. for (let j = 0; j < justifiedSplitEl[i].childNodes.length; j++) {
  41. let elStyle = justifiedSplitEl[i].childNodes[j].style;
  42. if (elStyle != undefined) {
  43. elStyle.textAlignLast = "left";
  44. }
  45. }
  46. }
  47. // images fullspread
  48. let fullspreadEl = document.querySelectorAll('.imgfullspreadleft, .imgfullspreadright, .imgfullspreadright_bleedtop, .imgfullspreadright_bleed');
  49. for (let i = 0; i < fullspreadEl.length; i++) {
  50. let imgSrc = fullspreadEl[i].firstElementChild.getAttribute('src');
  51. let nextPage = fullspreadEl[i].closest('.pagedjs_page').nextElementSibling.querySelectorAll('.pagedjs_page_content');
  52. let imgOverflowEl = document.createElement('div');
  53. if (fullspreadEl[i].classList.contains('imgfullspreadleft')) {
  54. imgOverflowEl.setAttribute('class', 'imgfullspreadleft-right');
  55. } else if (fullspreadEl[i].classList.contains('imgfullspreadright')) {
  56. imgOverflowEl.setAttribute('class', 'imgfullspreadright-right');
  57. } else if (fullspreadEl[i].classList.contains('imgfullspreadright_bleedtop')) {
  58. imgOverflowEl.setAttribute('class', 'imgfullspreadright_bleedtop-right');
  59. } else if (fullspreadEl[i].classList.contains('imgfullspreadright_bleed')) {
  60. imgOverflowEl.setAttribute('class', 'imgfullspreadright_bleed-right');
  61. }
  62. let imgOverflow = document.createElement('img');
  63. imgOverflow.src = imgSrc;
  64. imgOverflowEl.append(imgOverflow);
  65. nextPage[0].append(imgOverflowEl);
  66. if (fullspreadEl[i].classList.contains('imgfullspreadright')
  67. || fullspreadEl[i].classList.contains('imgfullspreadright_bleedtop')
  68. || fullspreadEl[i].classList.contains('imgfullspreadright_bleed')) {
  69. let imgMargin = imgOverflowEl.getBoundingClientRect().right - fullspreadEl[i].firstElementChild.getBoundingClientRect().right;
  70. fullspreadEl[i].firstElementChild.style.marginLeft = imgMargin + 'px';
  71. }
  72. }
  73. // fullpage img page gauche
  74. let fullPageImg = document.getElementsByClassName('fullpageimage');
  75. for (let i = 0; i < fullPageImg.length; i++) {
  76. if (fullPageImg[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  77. .classList.contains('pagedjs_left_page')) {
  78. fullPageImg[i].style.marginLeft = '-22mm';
  79. }
  80. }
  81. // encarts bleed
  82. let encarts = document.querySelectorAll('.latour, .lampe');
  83. for (let i = 0; i < encarts.length; i++) {
  84. if (encarts[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  85. .classList.contains('pagedjs_right_page')) {
  86. encarts[i].style.marginRight = '-22mm';
  87. encarts[i].style.paddingRight = '22mm';
  88. }
  89. if (encarts[i].hasAttribute('data-split-original')) {
  90. let plainColor = document.createElement('div');
  91. let plainHeight = encarts[i]
  92. .parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  93. .getBoundingClientRect().bottom - encarts[i].getBoundingClientRect().bottom;
  94. plainColor.setAttribute('class', 'encart-split');
  95. if (encarts[i]
  96. .parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  97. .classList.contains('pagedjs_right_page')) {
  98. plainColor.style.width = "149mm";
  99. } else {
  100. plainColor.style.width = "129mm";
  101. }
  102. plainColor.style.height = plainHeight + "px";
  103. encarts[i].parentNode.append(plainColor);
  104. } else if (encarts[i].hasAttribute('data-split-from')) {
  105. let plainColor = document.createElement('div');
  106. plainColor.setAttribute('class', 'encart-split');
  107. if (encarts[i]
  108. .parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  109. .classList.contains('pagedjs_right_page')) {
  110. plainColor.style.width = "149mm";
  111. } else {
  112. plainColor.style.width = "129mm";
  113. }
  114. plainColor.style.height = "22mm";
  115. plainColor.style.top = "-22mm";
  116. encarts[i].parentNode.prepend(plainColor);
  117. }
  118. if (encarts[i].previousElementSibling === null) {
  119. encarts[i].style.marginTop = '0';
  120. if (encarts[i].hasAttribute('data-split-original')) {
  121. encarts[i].parentElement.style.height = '214mm';
  122. encarts[i].style.paddingBottom = '0 !important';
  123. encarts[i].style.height = "100%";
  124. encarts[i].nextElementSibling.style.height = '22mm';
  125. encarts[i].nextElementSibling.style.bottom = '-22mm';
  126. encarts[i].nextElementSibling.style.right = '-28.5mm';
  127. }
  128. }
  129. }
  130. // TITRES ATELIERS
  131. let h3s = document.querySelectorAll('h3');
  132. for (let h3 of h3s) {
  133. if (h3.nextSibling?.firstChild.tagName == "IMG") {
  134. h3.style.position = "absolute";
  135. h3.style.top = "40%";
  136. h3.nextSibling.style.position = "absolute";
  137. h3.nextSibling.style.top = "5%";
  138. }
  139. if (h3.closest('.pagedjs_page').nextElementSibling?.querySelector('.has-children ')?.firstChild.firstChild.firstChild.tagName == "IMG") {
  140. let coverImg = h3.closest('.pagedjs_page').nextElementSibling.querySelector('.has-children ').firstChild.childNodes[0];
  141. coverImg.style.position = "absolute";
  142. coverImg.style.top = "-22mm";
  143. coverImg.style.left = "96mm";
  144. coverImg.style.height = "220mm";
  145. coverImg.style.width = "53mm";
  146. coverImg.style.overflow = "hidden";
  147. coverImg.firstChild.style.height = "100%";
  148. coverImg.firstChild.style.width = "auto";
  149. h3.parentElement.append(coverImg);
  150. let nextImg = document.createElement('img');
  151. nextImg.setAttribute('src', coverImg.firstChild.getAttribute('src'));
  152. h3.closest('.pagedjs_page').nextElementSibling.querySelector('.has-children ').append(nextImg);
  153. nextImg.parentElement.style.position = "absolute";
  154. nextImg.parentElement.style.top = "-22mm";
  155. nextImg.parentElement.style.left = "-8mm";
  156. nextImg.parentElement.style.height = "220mm";
  157. nextImg.parentElement.style.width = "171mm";
  158. nextImg.parentElement.style.overflow = "hidden";
  159. nextImg.style.height = "100%";
  160. nextImg.style.width = "auto";
  161. nextImg.style.marginLeft = "-53mm";
  162. }
  163. h3.closest('.pagedjs_pagebox').querySelector('.pagedjs_margin-left').innerHTML = '';
  164. h3.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement
  165. .classList.add('atelier_cover_page');
  166. }
  167. let h4s = document.querySelectorAll('h4');
  168. // SET COLORS
  169. let colors = [
  170. '#5595a1',
  171. '#5f9796',
  172. '#65998d',
  173. '#6f9b80',
  174. '#799e75',
  175. '#83a16b',
  176. '#8ba460',
  177. '#95a358',
  178. '#9ca151',
  179. '#a59d4a',
  180. '#af9944',
  181. '#b8963d',
  182. '#b8963d',
  183. '#b8963d'
  184. ]
  185. // TITRES PARTIES
  186. let h2s = document.querySelectorAll('h2');
  187. for (let i = 0; i < h2s.length; i++) {
  188. if (i != 0) {
  189. let parentSheet = h2s[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
  190. parentSheet.style.backgroundColor = colors[i];
  191. parentSheet.querySelector('.pagedjs_margin-left').innerHTML = '';
  192. parentSheet.parentElement.classList.add('partie_cover_page');
  193. let nextPage = parentSheet.parentElement.nextElementSibling?.firstElementChild;
  194. if (nextPage) {
  195. nextPage.style.backgroundColor = colors[i];
  196. }
  197. let partieCount = document.createElement('div');
  198. partieCount.classList.add('partie_count');
  199. let romanCount;
  200. switch (i) {
  201. case 1 : romanCount = 'I'; break;
  202. case 2 : romanCount = 'II'; break;
  203. case 3 : romanCount = 'III'; break;
  204. case 4 : romanCount = 'IV'; break;
  205. case 5 : romanCount = 'V'; break;
  206. case 6 : romanCount = 'VI'; break;
  207. case 7 : romanCount = 'VII'; break;
  208. case 8 : romanCount = 'VIII'; break;
  209. case 9 : romanCount = 'IX'; break;
  210. case 10 : romanCount = 'X'; break;
  211. }
  212. partieCount.innerHTML = 'Partie<br>' + romanCount;
  213. h2s[i].parentElement.prepend(partieCount);
  214. h2s[i].nextElementSibling?.remove();
  215. h2s[i].parentElement.parentElement.parentElement.parentElement.style.display = 'flex';
  216. h2s[i].parentElement.parentElement.parentElement.parentElement.style.alignItems = 'center';
  217. }
  218. }
  219. // afficher correctement les éléments en marge
  220. let topLeftBoxes = document.querySelectorAll('.pagedjs_margin-left-top');
  221. for (let topLeftBox of topLeftBoxes) {
  222. let contentDiv = topLeftBox.firstElementChild;
  223. let textToPut;
  224. let currentPage = contentDiv.parentElement.parentElement.parentElement.parentElement.parentElement;
  225. if(currentPage.id != "page-1") {
  226. let previousPage = currentPage.previousElementSibling;
  227. while (previousPage) {
  228. if (previousPage.classList.contains('atelier_cover_page')) {
  229. textToPut = previousPage.querySelector('h3').innerText;
  230. break;
  231. }
  232. previousPage = previousPage.previousElementSibling;
  233. }
  234. }
  235. contentDiv.append(textToPut);
  236. contentDiv.style.marginTop = contentDiv.offsetWidth / 2 - contentDiv.offsetHeight / 2 + "px";
  237. }
  238. let bottomLeftBoxes = document.querySelectorAll('.pagedjs_margin-left-bottom');
  239. for (let bottomLeftBox of bottomLeftBoxes) {
  240. let contentDiv = bottomLeftBox.firstElementChild;
  241. let textToPut;
  242. let currentPage = contentDiv.parentElement.parentElement.parentElement.parentElement.parentElement;
  243. if(currentPage.id != "page-1") {
  244. let previousPage = currentPage.previousElementSibling;
  245. while (previousPage) {
  246. if (previousPage.classList.contains('partie_cover_page')) {
  247. textToPut = previousPage.querySelector('h2').innerText;
  248. break;
  249. }
  250. previousPage = previousPage.previousElementSibling;
  251. }
  252. }
  253. contentDiv.append(textToPut);
  254. contentDiv.style.marginBottom = contentDiv.offsetWidth / 2 - contentDiv.offsetHeight / 2 + "px";
  255. }
  256. // set all colors
  257. let allPages = document.querySelectorAll('.pagedjs_page');
  258. let partieColor = '';
  259. let bgColor = 'rgb(250, 250, 250)';
  260. for (let page of allPages) {
  261. if (page.classList.contains('partie_cover_page')) {
  262. partieColor = page.firstElementChild.style.backgroundColor;
  263. }
  264. let pageCounter = page.querySelector('.pagedjs_margin-left-middle')
  265. if (pageCounter) {
  266. pageCounter.style.color = partieColor;
  267. }
  268. let atelierTitle = page.querySelector('h3');
  269. if (atelierTitle) {
  270. atelierTitle.style.color = partieColor;
  271. }
  272. let bibliographie = page.querySelector('.bibliographie');
  273. if (bibliographie) {
  274. bibliographie.style.color = partieColor;
  275. // set bg et sprays
  276. let bibliographiePage = bibliographie.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
  277. bibliographiePage.style.backgroundColor = bgColor;
  278. bibliographiePage.parentElement.nextElementSibling.firstElementChild.style.backgroundColor = bgColor;
  279. let sprayImg = document.createElement('img');
  280. sprayImg.setAttribute('src', '/user/themes/carnet-atterrissage/assets/sprays/spary_couleurs-page001.png');
  281. sprayImg.style.height = "242mm";
  282. sprayImg.style.width = "60mm";
  283. sprayImg.style.position = "absolute";
  284. sprayImg.style.top = "-22mm";
  285. sprayImg.style.right = "-20mm";
  286. sprayImg.style.mixBlendMode = "multiply";
  287. bibliographiePage.parentElement.nextElementSibling.querySelector('.pagedjs_page_content').prepend(sprayImg);
  288. }
  289. let h4 = page.querySelector('h4');
  290. if (h4 && h4?.nextElementSibling?.classList.contains('bibliographie')) {
  291. h4.style.color = partieColor;
  292. }
  293. let links = page.querySelectorAll('a');
  294. for (let link of links) {
  295. link.style.color = partieColor;
  296. }
  297. let lightColor = partieColor.slice(0, -1) + ', 0.1)';
  298. let encarts = page.querySelectorAll('.lampe, .latour, .encart-split');
  299. for (let encart of encarts) {
  300. encart.style.backgroundColor = lightColor;
  301. }
  302. }
  303. // all links open in a new tab
  304. let links = document.querySelectorAll('a');
  305. for (let link of links) {
  306. link.setAttribute('target', '_blank');
  307. }
  308. // loading
  309. document.querySelector('body').style.opacity = "1";
  310. document.querySelector('body').style.overflow = "scroll";
  311. }
  312. }
  313. Paged.registerHandlers(setMarginTexts);