main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. console.log('salut');
  2. /// fusion cellules dans tableau
  3. /// va chercher les p avec class .rowspan pour leur attribuer l'attribut rowspan
  4. var cellRowspans = document.querySelectorAll('p.rowspan');
  5. for (let cellRowspan of cellRowspans){
  6. let cellRowSpanParent = cellRowspan.parentElement;
  7. console.log(cellRowSpanParent);
  8. cellRowSpanParent.setAttribute('rowspan', '4');
  9. }
  10. var displayNones = document.querySelectorAll('p.cell-display-none'); // on va chercher tous les éléments p.cell-display-none
  11. for (let displayNone of displayNones){ /// on déclare 1 élément dans l'array
  12. let displayNoneParent = displayNone.parentElement; /// on va chercher le parent de l'élément dans l'array
  13. displayNoneParent.classList.add('display-none'); /// on ajout la class au parent
  14. console.log(displayNoneParent);
  15. }
  16. /// attribution d'une class en fonction de book-depth-5
  17. // var depths = document.getElementsByClassName('book-depth-5');
  18. // console.log(depths);
  19. // for (let depth of depths){
  20. // let depthSiblingTitle = depth.previousSibling('.block-page-title-block');
  21. // depthSiblingTitle.classList.add('book-depth-5');
  22. // console.log(depthSiblingTitle);
  23. // }
  24. // const article = document.querySelector('article[class*="book-depth"]');
  25. // console.log(article);
  26. // const div = document.querySelector('#block-pagetitle-2');
  27. // console.log(div);
  28. // div.classList.add(article.classList);
  29. // const article = document.querySelector('article.book-depth-*');
  30. // console.log(article);
  31. // const div = document.querySelector('#block-pagetitle-2');
  32. // div.classList.add(article.classList);
  33. ///////////////////
  34. // document.addEventListener('DOMContentLoaded', function () {
  35. // // Get the depth of the page within the book (You need to replace this logic with your own)
  36. // var depth = 5; // For example, you can set the depth dynamically based on your criteria
  37. // // Select the article element
  38. // var article = document.querySelector('article');
  39. // // Remove the existing depth class (if any)
  40. // article.classList.remove('book-depth-4', 'book-depth-5', 'book-depth-6', 'book-depth-7', 'book-depth-8', 'book-depth-9');
  41. // // Add the new depth class
  42. // article.classList.add('book-depth-' + depth);
  43. // // Select the block-pagetitle-2 element
  44. // var blockPagetitle2 = document.getElementById('block-pagetitle-2');
  45. // // Remove the existing depth class (if any)
  46. // blockPagetitle2.classList.remove('book-depth-4', 'book-depth-5', 'book-depth-6', 'book-depth-7', 'book-depth-8', 'book-depth-9');
  47. // // Add the new depth class to block-pagetitle-2
  48. // blockPagetitle2.classList.add('book-depth-' + depth);
  49. // });
  50. ///////////////////
  51. document.addEventListener('DOMContentLoaded', function () {
  52. // Select the article element
  53. var article = document.querySelector('article');
  54. console.log(article);
  55. // Get the current depth class from the article
  56. var depthClass = getDepthClass(article);
  57. console.log(depthClass);
  58. // Apply the depth class to block-pagetitle-2
  59. var blockPagetitle2 = document.getElementById('block-pagetitle-2');
  60. blockPagetitle2.classList.add(depthClass);
  61. // Optional: Remove the depth class from article if needed
  62. article.classList.remove(depthClass);
  63. // Function to extract the depth class from the article
  64. function getDepthClass(element) {
  65. var classes = element.classList;
  66. for (var i = 0; i < classes.length; i++) {
  67. if (classes[i].startsWith('book-depth-')) {
  68. return classes[i];
  69. }
  70. }
  71. return '';
  72. }
  73. });