Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

114 rader
3.6 KiB

  1. import './ihk-switch.scss';
  2. import $ from 'jquery';
  3. import {createElement} from "../../_global/scripts/helpers";
  4. import IHKSwitch from "./ihk-switch";
  5. import {createButton} from "../../atoms/button/ButtonComponent";
  6. import {createInputText} from "../../atoms/input-text/InputTextComponent";
  7. import {createSearchButton} from "../../atoms/search-button/SearchButtonComponent";
  8. const Cookies = require('js-cookie');
  9. export const createIhkSwitch = ({
  10. currentIHK = 'Musterstadt',
  11. myIHK = 'Hamburg',
  12. zip = false,
  13. zipPlaceholder = 'z.B. 20146 Hamburg'
  14. }) => {
  15. const wrap = createElement('div', ['ihk-switch']);
  16. const step1 = createElement('div', ['step'], null, wrap);
  17. if (!zip) {
  18. const step2 = createElement('div', ['step'], null, wrap);
  19. const step3 = createElement('div', ['step'], null, wrap);
  20. const p1 = 'Sie befinden sich auf der Seite der <strong class="current-ihk" data-ihknr="118">' + currentIHK + '</strong>. Möchten Sie diese Seite in einem Cookie als Ihre Heimat-IHK setzen?';
  21. const p2 = 'Sie befinden sich auf der Seite der <strong class="current-ihk" data-ihknr="118">' + currentIHK + '</strong>. Bisher ist die <strong><span class="my-ihk">' + myIHK + '</span></strong> als Ihre Heimat-IHK hinterlegt. Wollen Sie die Seite der <strong class="current-ihk" data-ihknr="118">' + currentIHK + '</strong> in einem Cookie als Ihre neue Heimat-IHK setzen?';
  22. const p3 = 'Sie werden zum Angebot der <strong class="large my-ihk">' + myIHK + '</strong> weitergeleitet.';
  23. const closer = createElement('button', ['closer'], null, wrap);
  24. closer.ariaLabel = 'Schließen';
  25. wrap.appendChild(closer);
  26. step1.dataset.step = 'form';
  27. createElement('p', [], p1, step1);
  28. step1.appendChild(buildButtons());
  29. step2.dataset.step = 'switch';
  30. createElement('p', [], p2, step2);
  31. step2.appendChild(buildButtons());
  32. step3.dataset.step = 'success';
  33. createElement('p', [], p3, step3);
  34. window.sessionStorage.removeItem('my-ihk-ignore');
  35. Cookies.remove('my-ihk', {expires: 365});
  36. } else {
  37. const p1 = 'Geben Sie Ihre Postleitzahl ein, um zu dem Angebot Ihrer IHK zu gelangen:';
  38. const closer = createElement('button', ['closer'], null, wrap);
  39. closer.ariaLabel = 'Schließen';
  40. wrap.appendChild(closer);
  41. step1.dataset.step = 'zip';
  42. createElement('p', [], p1, step1);
  43. const inputWrapper = createElement('div', ['input-wrapper'], null, step1);
  44. inputWrapper.appendChild(createInputText({
  45. placeholder: zipPlaceholder,
  46. isRequired: true,
  47. id: 'switch-zip',
  48. name: 'switch-zip',
  49. }));
  50. inputWrapper.appendChild(createButton({
  51. label: '',
  52. link: '#',
  53. iconPosition: 'icon-inline',
  54. icon: 'lokalisierung',
  55. }));
  56. step1.appendChild(buildOKButton());
  57. }
  58. $(document).ready(() => {
  59. new IHKSwitch($(wrap));
  60. })
  61. return wrap;
  62. }
  63. const buildButtons = () => {
  64. const buttons = createElement('div', ['buttons']);
  65. const yes = createButton({
  66. elementType: 'button',
  67. label: 'Ja',
  68. color: 'primary-extra-light',
  69. })
  70. const no = createButton({
  71. elementType: 'button',
  72. label: 'Nein',
  73. color: 'primary-extra-light',
  74. })
  75. yes.classList.add('stay-here');
  76. no.classList.add('set-session-cookie');
  77. buttons.appendChild(yes);
  78. buttons.appendChild(no);
  79. return buttons;
  80. }
  81. const buildOKButton = () => {
  82. const buttons = createElement('div', ['buttons', 'align-right']);
  83. const ok = createButton({
  84. elementType: 'button',
  85. label: 'OK',
  86. color: 'secondary',
  87. icon: 'check',
  88. iconPosition: 'icon-right'
  89. })
  90. ok.classList.add('stay-here');
  91. buttons.appendChild(ok);
  92. return buttons;
  93. }