layout.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. // afficher correctement les éléments en marge
  9. let topLeftBoxes = document.getElementsByClassName('pagedjs_margin-left-top');
  10. for (let i = 0; i < topLeftBoxes.length; i++) {
  11. topLeftBoxes[i].childNodes[0].style.marginTop = topLeftBoxes[i].childNodes[0].offsetWidth / 2 - topLeftBoxes[i].childNodes[0].offsetHeight / 2 + "px";
  12. }
  13. let bottomLeftBoxes = document.getElementsByClassName('pagedjs_margin-left-bottom');
  14. for (let i = 0; i < bottomLeftBoxes.length; i++) {
  15. bottomLeftBoxes[i].childNodes[0].style.marginBottom = bottomLeftBoxes[i].childNodes[0].offsetWidth / 2 - bottomLeftBoxes[i].childNodes[0].offsetHeight / 2 + "px";
  16. }
  17. // cleaner pour que les paragraphes tombent sur la marge haute
  18. for(let i = 0; i < labeurs.length; i++) {
  19. if (labeurs[i] == labeurs[i].parentNode.firstElementChild
  20. && !labeurs[i].firstElementChild?.hasAttribute("data-split-from")) {
  21. if (labeurs[i].firstElementChild) {
  22. labeurs[i].firstElementChild.style.marginTop = "0px";
  23. }
  24. }
  25. }
  26. // pareil pour les titres temps
  27. for (let i = 0; i < moments.length; i++) {
  28. if (moments[i].previousElementSibling?.tagName === "P"
  29. && moments[i].previousElementSibling == moments[i].parentNode.firstElementChild) {
  30. moments[i].parentNode.removeChild(moments[i].parentNode.firstElementChild);
  31. }
  32. }
  33. // enlever les paragraphes vides
  34. let paragraphes = document.querySelectorAll("p");
  35. for (let i = 0; i < paragraphes.length; i++) {
  36. if (paragraphes[i].innerHTML == "") {
  37. paragraphes[i].remove();
  38. }
  39. }
  40. // images collées en bas
  41. let bottomImgs = document.querySelectorAll('.bottomimg, .tripleimgs_bottom, .tripleimgs2_bottom');
  42. for (let i = 0; i < bottomImgs.length; i++) {
  43. let page = bottomImgs[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  44. bottomImgs[i].style.transform = 'translateY(' + (page.getBoundingClientRect().bottom - bottomImgs[i].lastElementChild.getBoundingClientRect().bottom) + 'px)';
  45. }
  46. // éléments justifiés pas nécessaires
  47. let justifiedSplitEl = document.querySelectorAll("[data-align-last-split-element='justify']");
  48. for (let i = 0; i < justifiedSplitEl.length; i++) {
  49. for (let j = 0; j < justifiedSplitEl[i].childNodes.length; j++) {
  50. let elStyle = justifiedSplitEl[i].childNodes[j].style;
  51. if (elStyle != undefined) {
  52. elStyle.textAlignLast = "left";
  53. }
  54. }
  55. }
  56. // images fullspread
  57. let fullspreadEl = document.querySelectorAll('.imgfullspreadleft, .imgfullspreadright, .imgfullspreadright_bleedtop, .imgfullspreadright_bleed');
  58. for (let i = 0; i < fullspreadEl.length; i++) {
  59. let imgSrc = fullspreadEl[i].firstElementChild.getAttribute('src');
  60. let nextPage = fullspreadEl[i].closest('.pagedjs_page').nextElementSibling.querySelectorAll('.pagedjs_page_content');
  61. let imgOverflowEl = document.createElement('div');
  62. if (fullspreadEl[i].classList.contains('imgfullspreadleft')) {
  63. imgOverflowEl.setAttribute('class', 'imgfullspreadleft-right');
  64. } else if (fullspreadEl[i].classList.contains('imgfullspreadright')) {
  65. imgOverflowEl.setAttribute('class', 'imgfullspreadright-right');
  66. } else if (fullspreadEl[i].classList.contains('imgfullspreadright_bleedtop')) {
  67. imgOverflowEl.setAttribute('class', 'imgfullspreadright_bleedtop-right');
  68. } else if (fullspreadEl[i].classList.contains('imgfullspreadright_bleed')) {
  69. imgOverflowEl.setAttribute('class', 'imgfullspreadright_bleed-right');
  70. }
  71. let imgOverflow = document.createElement('img');
  72. imgOverflow.src = imgSrc;
  73. imgOverflowEl.append(imgOverflow);
  74. nextPage[0].append(imgOverflowEl);
  75. if (fullspreadEl[i].classList.contains('imgfullspreadright')
  76. || fullspreadEl[i].classList.contains('imgfullspreadright_bleedtop')
  77. || fullspreadEl[i].classList.contains('imgfullspreadright_bleed')) {
  78. let imgMargin = imgOverflowEl.getBoundingClientRect().right - fullspreadEl[i].firstElementChild.getBoundingClientRect().right;
  79. fullspreadEl[i].firstElementChild.style.marginLeft = imgMargin + 'px';
  80. }
  81. }
  82. // fullpage img page gauche
  83. let fullPageImg = document.getElementsByClassName('fullpageimage');
  84. for (let i = 0; i < fullPageImg.length; i++) {
  85. if (fullPageImg[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  86. .classList.contains('pagedjs_left_page')) {
  87. fullPageImg[i].style.marginLeft = '-22mm';
  88. }
  89. }
  90. // encarts bleed
  91. let encarts = document.querySelectorAll('.latour, .lampe')
  92. for (let i = 0; i < encarts.length; i++) {
  93. if (encarts[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  94. .classList.contains('pagedjs_right_page')) {
  95. encarts[i].style.marginRight = '-22mm';
  96. encarts[i].style.paddingRight = '22mm';
  97. }
  98. if (encarts[i].hasAttribute('data-split-original')) {
  99. let plainColor = document.createElement('div');
  100. let plainHeight = encarts[i]
  101. .parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  102. .getBoundingClientRect().bottom - encarts[i].getBoundingClientRect().bottom;
  103. plainColor.setAttribute('class', 'encart-split');
  104. if (encarts[i]
  105. .parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  106. .classList.contains('pagedjs_right_page')) {
  107. plainColor.style.width = "149mm";
  108. } else {
  109. plainColor.style.width = "129mm";
  110. }
  111. plainColor.style.height = plainHeight + "px";
  112. encarts[i].parentNode.append(plainColor);
  113. } else if (encarts[i].hasAttribute('data-split-from')) {
  114. let plainColor = document.createElement('div');
  115. plainColor.setAttribute('class', 'encart-split');
  116. if (encarts[i]
  117. .parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  118. .classList.contains('pagedjs_right_page')) {
  119. plainColor.style.width = "149mm";
  120. } else {
  121. plainColor.style.width = "129mm";
  122. }
  123. plainColor.style.height = "22mm";
  124. plainColor.style.top = "-22mm";
  125. encarts[i].parentNode.prepend(plainColor);
  126. }
  127. }
  128. // TITRES
  129. let h3s = document.querySelectorAll('h3');
  130. for (let h3 of h3s) {
  131. if (h3.nextSibling.firstChild.tagName == "IMG") {
  132. h3.style.position = "absolute";
  133. h3.style.top = "40%";
  134. h3.nextSibling.style.position = "absolute";
  135. h3.nextSibling.style.top = "5%";
  136. }
  137. if (h3.closest('.pagedjs_page').nextElementSibling.querySelector('.has-children ')?.firstChild.firstChild.firstChild.tagName == "IMG") {
  138. let coverImg = h3.closest('.pagedjs_page').nextElementSibling.querySelector('.has-children ').firstChild.childNodes[0];
  139. coverImg.style.position = "absolute";
  140. coverImg.style.top = "-22mm";
  141. coverImg.style.left = "96mm";
  142. coverImg.style.height = "220mm";
  143. coverImg.style.width = "53mm";
  144. coverImg.style.overflow = "hidden";
  145. coverImg.firstChild.style.height = "100%";
  146. coverImg.firstChild.style.width = "auto";
  147. h3.parentElement.append(coverImg);
  148. let nextImg = document.createElement('img');
  149. nextImg.setAttribute('src', coverImg.firstChild.getAttribute('src'));
  150. h3.closest('.pagedjs_page').nextElementSibling.querySelector('.has-children ').append(nextImg);
  151. nextImg.parentElement.style.position = "absolute";
  152. nextImg.parentElement.style.top = "-22mm";
  153. nextImg.parentElement.style.left = "-8mm";
  154. nextImg.parentElement.style.height = "220mm";
  155. nextImg.parentElement.style.width = "171mm";
  156. nextImg.parentElement.style.overflow = "hidden";
  157. nextImg.style.height = "100%";
  158. nextImg.style.width = "auto";
  159. nextImg.style.marginLeft = "-53mm";
  160. }
  161. h3.closest('.pagedjs_pagebox').querySelector('.pagedjs_margin-left').innerHTML = '';
  162. }
  163. let h4s = document.querySelectorAll('h4');
  164. for (let h4 of h4s) {
  165. if (h4.nextElementSibling?.classList.contains('bibliographie')) {
  166. h4.style.color = "#d98a29";
  167. }
  168. }
  169. // loading
  170. document.querySelector('body').style.opacity = "1";
  171. document.querySelector('body').style.overflow = "scroll";
  172. }
  173. }
  174. Paged.registerHandlers(setMarginTexts);