addInsertIcons.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // créer header icons pour encarts
  2. if (debug) console.log('start addInsertIcons');
  3. (function() {
  4. let encarts = document.querySelectorAll('.latour, .latour_nohead, .lampe, .lampe_nohead');
  5. for(let encart of encarts) {
  6. let headContent = encart.firstChild
  7. let headerEl = document.createElement('div');
  8. headerEl.setAttribute('class', 'encart-header')
  9. let iconImg = document.createElement('img');
  10. let imgFile = encart.classList.contains('latour') || encart.classList.contains('latour_nohead') ? 'map' : 'lampe';
  11. iconImg.setAttribute('src', `/user/themes/carnet-atterrissage/assets/${ imgFile }.png`);
  12. if (encart.classList.contains('latour_nohead') || encart.classList.contains('lampe_nohead')) {
  13. headerEl.style.flexDirection = 'column';
  14. headerEl.style.alignItems = 'flex-start';
  15. headerEl.style.fontWeight = 'normal';
  16. encart.style.paddingTop = '5mm';
  17. encart.style.paddingBottom = '5mm';
  18. iconImg.style.marginBottom = '2mm';
  19. iconImg.style.margin = '0';
  20. iconImg.style.marginBottom = '2.5mm';
  21. }
  22. headerEl.append(iconImg);
  23. headerEl.append(headContent);
  24. encart.firstChild?.remove();
  25. encart.prepend(headerEl);
  26. if (encart.querySelector('.encart-header').nextElementSibling == null) {
  27. encart.querySelector('.encart-header').style.marginBottom = '0';
  28. }
  29. }
  30. })();
  31. if (debug) console.log('end addInsertIcons');