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.
 
 
 
 

112 righe
3.4 KiB

  1. import './teasers.scss';
  2. import $ from 'jquery';
  3. import {createElement} from "../../_global/scripts/helpers";
  4. import {createTeaser} from "../../components/teaser/TeaserComponent";
  5. import {teasersData} from "./TeasersData";
  6. import Masonry from "../../_global/scripts/masonry";
  7. import {createTeaserSocial} from "../../components/teaser-social/TeaserSocialComponent";
  8. import {linkListData} from "../../components/linklist/LinkListData";
  9. export const createTeasersSection = ({
  10. type = 'regular',
  11. background = null,
  12. headline = '',
  13. teasers = teasersData,
  14. showReadingTime = false,
  15. hideKicker = false,
  16. maxItems = -1,
  17. includeChart = false,
  18. includeSocial = false,
  19. includeLinklist = false,
  20. }) => {
  21. const baseTeaser = {
  22. type: 'regular',
  23. kicker: 'Fachkräfte',
  24. headline: 'Anteil der Frauen im Bereich Engineering steigt',
  25. copy: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita, no sea takimata sanctus est.',
  26. imageSrc: './dummy/placeholder-3-2.svg',
  27. copyright: '@ shutterstock.com',
  28. showReadingTime: false,
  29. link: '#',
  30. imageSize: 'large',
  31. };
  32. switch (type) {
  33. case 'regular':
  34. maxItems = maxItems === -1 ? 3 : maxItems;
  35. break;
  36. case 'text':
  37. maxItems = maxItems === -1 ? 3 : maxItems;
  38. break;
  39. case 'hero':
  40. maxItems = maxItems === -1 ? 2 : maxItems;
  41. break;
  42. case 'fullwidth':
  43. maxItems = 1;
  44. break;
  45. case 'magazine':
  46. maxItems = teasers.length;
  47. break;
  48. }
  49. const section = createElement('section', type === 'magazine' ? ['teasers', 'magazine-style'] : ['teasers']);
  50. if (type !== 'magazine') {
  51. section.dataset.items = maxItems > 3 ? '3' : maxItems.toString();
  52. }
  53. if (background && background.length > 0) {
  54. section.dataset.background = background;
  55. }
  56. const container = createElement('div', ['container'], null, section);
  57. if (headline && headline.length > 0) {
  58. createElement('h2', [], headline, container);
  59. }
  60. const row = createElement('div', ['row'], null, container);
  61. function getType(index) {
  62. if (includeChart && index === maxItems - 1) {
  63. return 'chart';
  64. }
  65. return type === 'magazine' ? 'regular' : type;
  66. }
  67. if (includeSocial) {
  68. maxItems -= 1;
  69. }
  70. teasers.map((teaserData, index) => {
  71. if (index >= maxItems) {
  72. return;
  73. }
  74. const col = createElement('div', ['col'], null, row);
  75. const teaser = createTeaser({
  76. ...baseTeaser,
  77. ...teaserData,
  78. type: getType(index),
  79. showReadingTime: type === 'magazine' || type === 'fullwidth' ? true : showReadingTime,
  80. kicker: hideKicker ? null : teaserData.kicker,
  81. linklistData: includeLinklist && index === maxItems - 1 ? linkListData : null,
  82. })
  83. col.appendChild(teaser);
  84. })
  85. if (includeSocial) {
  86. const col = createElement('div', ['col'], null, row);
  87. col.appendChild(createTeaserSocial({kicker: hideKicker ? null : 'Ihre IHK bei Twitter'}));
  88. }
  89. if (type === 'magazine') {
  90. $(document).ready(() => {
  91. const btnText = window.ihk.translations.loadMoreArticles;
  92. section.dataset.type = 'masonry';
  93. new Masonry($(row), btnText, [
  94. {minWidth: 0, batchSize: 2},
  95. {minWidth: 567, batchSize: 3},
  96. {minWidth: 1000, batchSize: 6}
  97. ])
  98. })
  99. }
  100. return section;
  101. }