You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

87 rivejä
3.7 KiB

  1. import './timeline.scss';
  2. import '../slider/slider.scss';
  3. import $ from 'jquery';
  4. import {createElement, createImage} from "../../_global/scripts/helpers";
  5. import {TimelineData} from "./TimelineData";
  6. import {createTabs} from "../../atoms/tabs/TabsComponent";
  7. import IHKTimeline from "./timeline";
  8. export const createTimeline = ({
  9. single = false,
  10. data = TimelineData,
  11. }) => {
  12. const wrapper = createElement('div', ['timelines','variant-subtle-primary']);
  13. const tabsWrapper = createElement('div', ['timeline-tabs'], null, wrapper);
  14. const timelineWrapper = createElement('section', ['timeline'], null, wrapper);
  15. createElement('div', ['item-slider'], null, timelineWrapper);
  16. const years = createElement('div', ['years','variant-solid'], null, timelineWrapper);
  17. const container = createElement('div', ['container'], null, years);
  18. const yearsWrapper = createElement('div', ['years-wrapper'], null, container);
  19. const tabsData = [];
  20. if (single) {
  21. data = [data[0]];
  22. }
  23. data.map((section) => {
  24. tabsData.push({
  25. label: section.tab,
  26. link: '#' + section.id,
  27. })
  28. const anchorItem = createElement('div', ['year-item', 'anchor'], null, yearsWrapper);
  29. createElement('p', ['year'], section.nav, anchorItem);
  30. const anchorUl = createElement('ul', ['items'], null, anchorItem);
  31. const anchorLi = createElement('li', [], null, anchorUl);
  32. createElement('p', ['title'], null, anchorLi);
  33. const anchorSlide = createElement('div', ['slide'], null, anchorLi);
  34. const anchorContainer = createElement('div', ['container'], null, anchorSlide);
  35. const anchorTextBox = createElement('div', ['text-box'], null, anchorContainer);
  36. createElement('p', ['year'], section.title, anchorTextBox);
  37. anchorSlide.id = section.id;
  38. section.years.map((year) => {
  39. const yearItem = createElement('div', ['year-item'], null, yearsWrapper);
  40. createElement('p', ['year'], year.year, yearItem);
  41. const yearUl = createElement('ul', ['items'], null, yearItem);
  42. year.items.map((item) => {
  43. const itemLi = createElement('li', [], null, yearUl);
  44. createElement('p', ['title'], item.title, itemLi);
  45. const itemSlide = createElement('div', item.image ? ['slide', 'has-image'] : ['slide'], null, itemLi);
  46. const itemContainer = createElement('div', ['container'], null, itemSlide);
  47. if (item.image) {
  48. const imageBox = createElement('div', ['image-box', item.image.size], null, itemContainer);
  49. createImage(item.image.src, item.image.width, item.image.height, item.image.alt, [], imageBox);
  50. if (item.image.caption || item.image.copyright) {
  51. const caption = createElement('div', ['caption'], null, imageBox);
  52. if (item.image.caption) {
  53. createElement('span', [], item.image.caption, caption);
  54. }
  55. if (item.image.copyright) {
  56. const copyright = createElement('span', ['copyright'], item.image.copyright, caption);
  57. copyright.setAttribute("aria-hidden", "true");
  58. createElement('span', ['sr-only'], item.image.copyright, caption);
  59. }
  60. }
  61. }
  62. const itemTextBox = createElement('div', ['text-box'], null, itemContainer);
  63. createElement('p', ['year'], year.year, itemTextBox);
  64. if (item.subhead) {
  65. createElement('p', ['subhead'], item.subhead, itemTextBox);
  66. }
  67. if (item.copy) {
  68. createElement('p', [], item.copy, itemTextBox);
  69. }
  70. });
  71. })
  72. });
  73. if (single || data.length === 1) {
  74. tabsWrapper.remove();
  75. } else {
  76. tabsWrapper.appendChild(createTabs({size: 'small', color: 'white', data: tabsData}));
  77. }
  78. new IHKTimeline($(timelineWrapper));
  79. return wrapper;
  80. }