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.
 
 
 
 

86 rivejä
3.5 KiB

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