margins.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // afficher les éléments en marge
  2. if (debug) console.log('start margins');
  3. (function() {
  4. let topLeftBoxes = document.querySelectorAll('.pagedjs_margin-left-top');
  5. for (let topLeftBox of topLeftBoxes) {
  6. let contentDiv = topLeftBox.firstElementChild;
  7. let textToPut = document.createElement('p');
  8. let atelierGras;
  9. let currentPage = contentDiv.closest('.pagedjs_page');
  10. if (currentPage.id != "page-1") {
  11. let previousPage = currentPage.previousElementSibling;
  12. while (previousPage) {
  13. if (previousPage.firstElementChild.classList.contains('atelier_cover_page')) {
  14. textToPut.innerText = previousPage.querySelector('h3').innerText;
  15. let words = textToPut.innerText.split(' ');
  16. let num = parseInt(words[0], 10);
  17. if (!isNaN(num)) {
  18. atelierGras = document.createElement('span');
  19. atelierGras.style.fontWeight = "bold";
  20. atelierGras.innerText = `Atelier ${num} `;
  21. textToPut.innerText = textToPut.innerText.substring(1);
  22. }
  23. break;
  24. }
  25. previousPage = previousPage.previousElementSibling;
  26. }
  27. }
  28. if (atelierGras) {
  29. textToPut.prepend(atelierGras);
  30. }
  31. contentDiv.append(textToPut);
  32. contentDiv.style.marginTop = contentDiv.offsetWidth / 2 - contentDiv.offsetHeight / 2 + "px";
  33. }
  34. let bottomLeftBoxes = document.querySelectorAll('.pagedjs_margin-left-bottom');
  35. for (let bottomLeftBox of bottomLeftBoxes) {
  36. let contentDiv = bottomLeftBox.firstElementChild;
  37. let textToPut = document.createElement('p');
  38. let partieGras;
  39. let currentPage = contentDiv.closest('.pagedjs_page');
  40. if (currentPage.id != "page-1") {
  41. let previousPage = currentPage.previousElementSibling;
  42. while (previousPage) {
  43. if (previousPage.firstElementChild.classList.contains('partie_cover_page')) {
  44. textToPut.innerText = previousPage.querySelector('h2').innerText;
  45. partieGras = document.createElement('span');
  46. partieGras.style.fontWeight = "bold";
  47. partieGras.innerText = previousPage.querySelector('.partie_count').innerHTML.replace("<br>", " ") + " ";
  48. break;
  49. }
  50. previousPage = previousPage.previousElementSibling;
  51. }
  52. }
  53. if (!textToPut.innerText) {
  54. textToPut.innerText = "Introduction";
  55. }
  56. if (partieGras) {
  57. textToPut.prepend(partieGras);
  58. }
  59. contentDiv.append(textToPut);
  60. contentDiv.style.marginBottom = contentDiv.offsetWidth / 2 - contentDiv.offsetHeight / 2 + "px";
  61. }
  62. })();
  63. if (debug) console.log('end margins');