Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

57 righe
1.6 KiB

  1. import $ from 'jquery';
  2. class IHKTileGrid {
  3. constructor(section) {
  4. this.$dynamicIcon = $(section);
  5. this.iconSize();
  6. // Event-Listener für Resize
  7. $(window).on('resize', () => {
  8. this.iconSize();
  9. });
  10. }
  11. iconSize() {
  12. // Die Höhe des Parent-Elements (tile-outer) holen
  13. const $tileOuter = this.$dynamicIcon.closest('.tile-outer');
  14. // Prüfen ob das Element existiert und sichtbar ist
  15. if ($tileOuter.length && $tileOuter.is(':visible')) {
  16. const containerHeight = $tileOuter.outerHeight();
  17. // Nur setzen wenn containerHeight gültig ist
  18. if (containerHeight && containerHeight > 0) {
  19. this.$dynamicIcon.css('--icon-height', `${containerHeight}px`);
  20. console.log('Icon höhe gesetzt:', containerHeight, 'px für', this.$dynamicIcon);
  21. } else {
  22. console.warn('Ungültige Höhe:', containerHeight);
  23. // Fallback setzen
  24. this.$dynamicIcon.css('--icon-height', '100%');
  25. }
  26. } else {
  27. console.warn('Tile-outer nicht gefunden oder nicht sichtbar');
  28. // Fallback setzen
  29. this.$dynamicIcon.css('--icon-height', '100%');
  30. }
  31. }
  32. }
  33. export default IHKTileGrid;
  34. // Nur einmal initialisieren, aber mit besserer Timing-Sicherheit
  35. function initIcons() {
  36. $('.tile-grid .dynamic-icon').each((i, el) => {
  37. new IHKTileGrid(el);
  38. });
  39. }
  40. // Bei allen relevanten Events ausführen
  41. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', initIcons);
  42. // Beim Laden der Seite und kurz danach nochmal (für Storybook)
  43. $(document).ready(() => {
  44. initIcons();
  45. // Nach kurzer Verzögerung nochmal ausführen, falls DOM noch ändert
  46. setTimeout(initIcons, 500);
  47. });