@internetstiftelsen/styleguide 5.0.19 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/app.js +71 -0
  2. package/dist/assets/js/Events.js +43 -77
  3. package/dist/assets/js/RequestError.js +16 -31
  4. package/dist/assets/js/anchorScroll.js +22 -15
  5. package/dist/assets/js/charCounter.js +100 -142
  6. package/dist/assets/js/className.js +19 -20
  7. package/dist/assets/js/conditional.js +96 -152
  8. package/dist/assets/js/debounce.js +15 -22
  9. package/dist/assets/js/el.js +108 -159
  10. package/dist/assets/js/getCookieByName.js +13 -11
  11. package/dist/assets/js/hasCookieConsent.js +30 -40
  12. package/dist/assets/js/htmlTextLength.js +12 -10
  13. package/dist/assets/js/iconToggle.js +16 -20
  14. package/dist/assets/js/nodeAdded.js +40 -53
  15. package/dist/assets/js/objToQuery.js +25 -41
  16. package/dist/assets/js/offset.js +29 -25
  17. package/dist/assets/js/ot.js +10 -13
  18. package/dist/assets/js/parallax.js +23 -23
  19. package/dist/assets/js/queryToObj.js +16 -22
  20. package/dist/assets/js/readSpeakerHandling.js +26 -28
  21. package/dist/assets/js/request.js +43 -52
  22. package/dist/assets/js/responsivePosition.js +46 -74
  23. package/dist/assets/js/stringToNode.js +11 -10
  24. package/dist/assets/js/template.js +15 -21
  25. package/dist/assets/js/textToggle.js +19 -24
  26. package/dist/assets/js/track.js +14 -12
  27. package/dist/assets/js/uid.js +10 -6
  28. package/dist/assets/js/utmGenerator.js +27 -33
  29. package/dist/assets/js/validationMessage.js +18 -25
  30. package/dist/assets/js/youtube.js +134 -170
  31. package/dist/atoms/button/Button.js +42 -55
  32. package/dist/atoms/file/file.js +25 -29
  33. package/dist/atoms/file/filePreview.js +27 -31
  34. package/dist/atoms/grid-toggle/grid-toggle.js +6 -9
  35. package/dist/atoms/height-limiter/height-limiter.js +37 -50
  36. package/dist/atoms/password-toggle/password-toggle.js +9 -11
  37. package/dist/atoms/range/range.js +32 -39
  38. package/dist/atoms/textarea/rich-text.js +221 -251
  39. package/dist/atoms/tooltip/tooltip.js +13 -17
  40. package/dist/components.js +42 -77
  41. package/dist/focusTrap.js +66 -77
  42. package/dist/molecules/alert/alert.js +15 -20
  43. package/dist/molecules/context-menu/context-menu.js +11 -16
  44. package/dist/molecules/continue-video-guide/continue-video-guide.js +90 -101
  45. package/dist/molecules/cookie-disclaimer/cookie-disclaimer.js +24 -33
  46. package/dist/molecules/form/Form.js +242 -352
  47. package/dist/molecules/form/index.js +15 -14
  48. package/dist/molecules/glider/glider-course.js +62 -75
  49. package/dist/molecules/glider/glider-hero.js +88 -101
  50. package/dist/molecules/glider/glider.js +49 -45
  51. package/dist/molecules/modal/modal.js +256 -325
  52. package/dist/molecules/multi-select/multi-select.js +198 -304
  53. package/dist/molecules/natural-language-form/natural-language-form.js +32 -46
  54. package/dist/molecules/overview-navigation/overview-navigation.js +90 -141
  55. package/dist/molecules/share/share.js +15 -20
  56. package/dist/molecules/system-error/system-error.js +6 -9
  57. package/dist/organisms/accordion/accordion.js +44 -50
  58. package/dist/organisms/footer/footer.js +1 -1
  59. package/dist/organisms/haveibeenpwned/haveibeenpwned.js +17 -16
  60. package/dist/organisms/mailchimp/mailchimp.js +72 -89
  61. package/dist/organisms/map-box/map-box.js +3 -4
  62. package/dist/organisms/mega-menu/mega-menu.js +177 -212
  63. package/dist/organisms/podcast/podcast.js +192 -215
  64. package/dist/organisms/schedule/schedule-filter.js +9 -15
  65. package/dist/organisms/tabs/tabs.js +194 -253
  66. package/dist/organisms/timeline/openTimelineItem.js +38 -51
  67. package/dist/organisms/timeline/timeline.js +111 -128
  68. package/dist/organisms/video-guide/VideoGuidePlayback.js +210 -286
  69. package/dist/organisms/video-guide/VideoGuideSubtitles.js +57 -80
  70. package/dist/organisms/video-guide/VideoGuideTimeline.js +74 -108
  71. package/dist/organisms/video-guide/getCurrentCueIndex.js +11 -9
  72. package/dist/organisms/video-guide/video-guide.js +66 -103
  73. package/dist/utilities/tab-highlighting/tab-highlighting.js +14 -22
  74. package/dist/vendor/toggle/a11y.toggle-switcher.js +10 -16
  75. package/package.json +78 -99
  76. package/src/app.js +5 -5
  77. package/src/assets/js/anchorScroll.js +1 -1
  78. package/src/assets/js/offset.js +1 -1
  79. package/src/atoms/button/Button.js +1 -1
  80. package/src/atoms/icon/richtext-ordered-list.svg +1 -1
  81. package/src/atoms/icon/sprite.svg +6 -5
  82. package/src/molecules/glider/glider-course.js +0 -2
  83. package/src/molecules/glider/glider.js +2 -2
  84. package/src/organisms/accordion/accordion.js +1 -2
  85. package/src/organisms/timeline/timeline.js +2 -3
  86. package/dist/atoms/timeline/anchorScroll.js +0 -13
  87. package/dist/atoms/toggle-high-contrast/toggle-high-contrast.js +0 -12
  88. package/dist/molecules/glider/glider-single.js +0 -68
  89. package/dist/molecules/modal/modal-graph.js +0 -40
  90. package/dist/molecules/timeline-navigation/timeline-navigation.js +0 -34
  91. /package/src/atoms/icon/{heading-3.svg → richtext-heading-3.svg} +0 -0
  92. /package/src/molecules/alert/{_alert.scss → alert.scss} +0 -0
@@ -1,255 +1,196 @@
1
- 'use strict';
2
-
3
- window.a11yTabs = function tabsComponentIIFE(global, document) {
4
- var tabInstances = new WeakMap();
5
- var className = 'o-tab-list';
6
- var tablistElement = document.querySelector('.js-' + className);
7
- var updateURLFromHash = void 0;
8
-
9
- if (tablistElement) {
10
- updateURLFromHash = tablistElement.getAttribute('data-update-url');
11
- }
12
-
13
- /**
14
- * Instantiates the component
15
- * @constructor
16
- * @param {DOM Node} element
17
- */
18
- var TabComponent = function TabComponent(element, options) {
19
- if (!element || !element.nodeType) {
20
- return;
21
- }
22
-
23
- var namespace = getComputedStyle(tablistElement, ':before').content.replace(/["']/g, '');
24
-
25
- var defaults = {
26
- tabList: '.' + namespace + className,
27
- tabItem: '.' + namespace + className + '__item',
28
- tabLink: '.' + namespace + className + '__link',
29
- tabPanel: '.' + namespace + 'o-tab-panel'
30
- };
31
-
32
- this.options = Object.assign(defaults, options);
33
-
34
- this.element = element;
35
- this.tabList = element.querySelector(this.options.tabList);
36
- this.tabItems = [].slice.call(this.tabList.querySelectorAll(this.options.tabItem));
37
- this.tabLinks = [].slice.call(this.tabList.querySelectorAll(this.options.tabLink));
38
- this.tabPanels = [].slice.call(element.querySelectorAll(this.options.tabPanel));
39
-
40
- this.currentIndex = 0;
41
-
42
- this.tabList.setAttribute('role', 'tablist');
43
-
44
- this.tabItems.forEach(function (item, index) {
45
- item.setAttribute('role', 'presentation');
46
-
47
- if (index === 0) {
48
- item.setAttribute('data-tab-active', '');
49
- }
50
- });
51
-
52
- this.tabLinks.forEach(function (item, index) {
53
- item.setAttribute('role', 'tab');
54
-
55
- if (index > 0) {
56
- item.setAttribute('tabindex', '-1');
57
- } else {
58
- item.setAttribute('aria-selected', 'true');
59
- }
60
- });
61
-
62
- this.tabPanels.forEach(function (item, index) {
63
- item.setAttribute('role', 'tabpanel');
64
- item.setAttribute('aria-labelledby', 'tab' + index);
65
- item.setAttribute('tabindex', '-1');
66
-
67
- if (index > 0) {
68
- item.setAttribute('hidden', '');
69
- }
70
- });
71
-
72
- this.eventCallback = handleEvents.bind(this);
73
- this.tabList.addEventListener('click', this.eventCallback, false);
74
- this.tabList.addEventListener('keydown', this.eventCallback, false);
75
-
76
- tabInstances.set(this.element, this);
77
-
78
- // Select the correct tab based on URL hash
79
- if (updateURLFromHash) {
80
- this.selectTabFromHash();
81
- }
82
- };
83
-
84
- TabComponent.prototype = {
85
- /**
86
- * Event handler for all tab interactions
87
- * @param {number} index - Index of the tab being activiated
88
- * @param {string} direction -
89
- */
90
- handleTabInteraction: function handleTabInteraction(index, direction) {
91
- var currentIndex = this.currentIndex;
92
-
93
- var newIndex = index;
94
-
95
- // The click event does not pass in a direction. This is for keyboard support
96
- if (direction) {
97
- if (direction === 37) {
98
- newIndex = index - 1;
99
- } else {
100
- newIndex = index + 1;
101
- }
102
- }
103
-
104
- // Supports continuous tabbing when reaching beginning or end of tab list
105
- if (newIndex < 0) {
106
- newIndex = this.tabLinks.length - 1;
107
- } else if (newIndex === this.tabLinks.length) {
108
- newIndex = 0;
109
- }
110
-
111
- // update tabs
112
- this.tabLinks[currentIndex].setAttribute('tabindex', '-1');
113
- this.tabLinks[currentIndex].removeAttribute('aria-selected');
114
- this.tabItems[currentIndex].removeAttribute('data-tab-active');
115
-
116
- this.tabLinks[newIndex].setAttribute('aria-selected', 'true');
117
- this.tabItems[newIndex].setAttribute('data-tab-active', '');
118
- this.tabLinks[newIndex].removeAttribute('tabindex');
119
- this.tabLinks[newIndex].focus(); // Focus the newly selected tab
120
-
121
- // update tab panels
122
- this.tabPanels[currentIndex].setAttribute('hidden', '');
123
- this.tabPanels[newIndex].removeAttribute('hidden');
124
-
125
- // Update the browser's URL hash to reflect the current tab's ID
126
- var selectedTabId = this.tabLinks[newIndex].id;
127
-
128
- if (updateURLFromHash) {
129
- window.history.pushState(null, '', '#' + selectedTabId);
130
- }
131
-
132
- this.currentIndex = newIndex;
133
-
134
- return this;
135
- },
136
-
137
- /**
138
- * Set tab panel focus
139
- * @param {number} index - Tab panel index to receive focus
140
- */
141
- handleTabpanelFocus: function handleTabPanelFocus(index) {
142
- this.tabPanels[index].focus();
143
-
144
- return this;
145
- },
146
- /**
147
- * Selects a tab based on the URL hash
148
- */
149
- selectTabFromHash: function selectTabFromHash() {
150
- var hash = global.location.hash;
151
-
152
- if (hash) {
153
- var targetId = hash.substring(1); // Remove the '#' character
154
- var targetIndex = this.tabLinks.findIndex(function (link) {
155
- return link.id === targetId;
156
- });
157
- if (targetIndex !== -1) {
158
- this.handleTabInteraction(targetIndex);
159
- }
160
- }
161
- }
162
- };
163
-
164
- /**
165
- * Creates or returns existing component
166
- * @param {string} selector
167
- */
168
- function createTabComponent(selector, options) {
169
- var elements = document.querySelectorAll(selector);
170
- [].forEach.call(elements, function (element) {
171
- return tabInstances.get(element) || new TabComponent(element, options);
172
- });
173
- }
174
-
175
- /**
176
- * Destroys an existing component
177
- * @param {DOM Node} element
178
- */
179
- function destroyTabComponent(element) {
180
- if (!element || !element.nodeType) {
181
- return;
182
- }
183
-
184
- var component = tabInstances.get(element);
185
- component.tabList.removeAttribute('role', 'tablist');
186
-
187
- component.tabItems.forEach(function (item, index) {
188
- item.removeAttribute('role', 'presentation');
189
-
190
- if (index === 0) {
191
- item.removeAttribute('data-tab-active');
192
- }
193
- });
194
-
195
- component.tabLinks.forEach(function (item, index) {
196
- item.removeAttribute('role', 'tab');
197
- item.removeAttribute('id', 'tab' + index);
198
-
199
- if (index > 0) {
200
- item.removeAttribute('tabindex', '-1');
201
- } else {
202
- item.removeAttribute('aria-selected', 'true');
203
- }
204
- });
205
-
206
- component.tabPanels.forEach(function (item, index) {
207
- item.removeAttribute('role', 'tabpanel');
208
- item.removeAttribute('aria-labelledby', 'tab' + index);
209
- item.removeAttribute('tabindex', '-1');
210
-
211
- if (index > 0) {
212
- item.removeAttribute('hidden');
213
- }
214
- });
215
-
216
- component.tabList.removeEventListener('click', component.eventCallback);
217
- component.tabList.removeEventListener('keydown', component.eventCallback);
218
- tabInstances.delete(component.element);
219
- }
220
-
221
- /**
222
- * Handles all event listener callbacks
223
- * @param {event} event
224
- */
225
- function handleEvents(event) {
226
- if (event.type === 'click') {
227
- event.preventDefault();
228
- TabComponent.prototype.handleTabInteraction.call(this, this.tabLinks.indexOf(event.target));
229
- }
230
-
231
- if (event.type === 'keydown') {
232
- var index = this.tabLinks.indexOf(event.target);
233
-
234
- // Left and right arrows
235
- if (event.which === 37 || event.which === 39) {
236
- event.preventDefault();
237
- TabComponent.prototype.handleTabInteraction.call(this, index, event.which);
238
- }
239
-
240
- // Down arrow
241
- if (event.which === 40) {
242
- event.preventDefault();
243
- TabComponent.prototype.handleTabpanelFocus.call(this, index);
244
- }
245
- }
246
- }
247
-
248
- return {
249
- create: createTabComponent,
250
- destroy: destroyTabComponent
251
- };
1
+ "use strict";
2
+ window.a11yTabs = function tabsComponentIIFE(global, document1) {
3
+ const tabInstances = new WeakMap();
4
+ const className = 'o-tab-list';
5
+ const tablistElement = document1.querySelector(`.js-${className}`);
6
+ let updateURLFromHash;
7
+ if (tablistElement) {
8
+ updateURLFromHash = tablistElement.getAttribute('data-update-url');
9
+ }
10
+ /**
11
+ * Instantiates the component
12
+ * @constructor
13
+ * @param {DOM Node} element
14
+ */ const TabComponent = function TabComponent(element, options) {
15
+ if (!element || !element.nodeType) {
16
+ return;
17
+ }
18
+ const namespace = getComputedStyle(tablistElement, ':before').content.replace(/["']/g, '');
19
+ const defaults = {
20
+ tabList: `.${namespace}${className}`,
21
+ tabItem: `.${namespace}${className}__item`,
22
+ tabLink: `.${namespace}${className}__link`,
23
+ tabPanel: `.${namespace}o-tab-panel`
24
+ };
25
+ this.options = Object.assign(defaults, options);
26
+ this.element = element;
27
+ this.tabList = element.querySelector(this.options.tabList);
28
+ this.tabItems = [].slice.call(this.tabList.querySelectorAll(this.options.tabItem));
29
+ this.tabLinks = [].slice.call(this.tabList.querySelectorAll(this.options.tabLink));
30
+ this.tabPanels = [].slice.call(element.querySelectorAll(this.options.tabPanel));
31
+ this.currentIndex = 0;
32
+ this.tabList.setAttribute('role', 'tablist');
33
+ this.tabItems.forEach((item, index)=>{
34
+ item.setAttribute('role', 'presentation');
35
+ if (index === 0) {
36
+ item.setAttribute('data-tab-active', '');
37
+ }
38
+ });
39
+ this.tabLinks.forEach((item, index)=>{
40
+ item.setAttribute('role', 'tab');
41
+ if (index > 0) {
42
+ item.setAttribute('tabindex', '-1');
43
+ } else {
44
+ item.setAttribute('aria-selected', 'true');
45
+ }
46
+ });
47
+ this.tabPanels.forEach((item, index)=>{
48
+ item.setAttribute('role', 'tabpanel');
49
+ item.setAttribute('aria-labelledby', `tab${index}`);
50
+ item.setAttribute('tabindex', '-1');
51
+ if (index > 0) {
52
+ item.setAttribute('hidden', '');
53
+ }
54
+ });
55
+ this.eventCallback = handleEvents.bind(this);
56
+ this.tabList.addEventListener('click', this.eventCallback, false);
57
+ this.tabList.addEventListener('keydown', this.eventCallback, false);
58
+ tabInstances.set(this.element, this);
59
+ // Select the correct tab based on URL hash
60
+ if (updateURLFromHash) {
61
+ this.selectTabFromHash();
62
+ }
63
+ };
64
+ TabComponent.prototype = {
65
+ /**
66
+ * Event handler for all tab interactions
67
+ * @param {number} index - Index of the tab being activiated
68
+ * @param {string} direction -
69
+ */ handleTabInteraction: function handleTabInteraction(index, direction) {
70
+ const { currentIndex } = this;
71
+ let newIndex = index;
72
+ // The click event does not pass in a direction. This is for keyboard support
73
+ if (direction) {
74
+ if (direction === 37) {
75
+ newIndex = index - 1;
76
+ } else {
77
+ newIndex = index + 1;
78
+ }
79
+ }
80
+ // Supports continuous tabbing when reaching beginning or end of tab list
81
+ if (newIndex < 0) {
82
+ newIndex = this.tabLinks.length - 1;
83
+ } else if (newIndex === this.tabLinks.length) {
84
+ newIndex = 0;
85
+ }
86
+ // update tabs
87
+ this.tabLinks[currentIndex].setAttribute('tabindex', '-1');
88
+ this.tabLinks[currentIndex].removeAttribute('aria-selected');
89
+ this.tabItems[currentIndex].removeAttribute('data-tab-active');
90
+ this.tabLinks[newIndex].setAttribute('aria-selected', 'true');
91
+ this.tabItems[newIndex].setAttribute('data-tab-active', '');
92
+ this.tabLinks[newIndex].removeAttribute('tabindex');
93
+ this.tabLinks[newIndex].focus(); // Focus the newly selected tab
94
+ // update tab panels
95
+ this.tabPanels[currentIndex].setAttribute('hidden', '');
96
+ this.tabPanels[newIndex].removeAttribute('hidden');
97
+ // Update the browser's URL hash to reflect the current tab's ID
98
+ const selectedTabId = this.tabLinks[newIndex].id;
99
+ if (updateURLFromHash) {
100
+ window.history.pushState(null, '', `#${selectedTabId}`);
101
+ }
102
+ this.currentIndex = newIndex;
103
+ return this;
104
+ },
105
+ /**
106
+ * Set tab panel focus
107
+ * @param {number} index - Tab panel index to receive focus
108
+ */ handleTabpanelFocus: function handleTabPanelFocus(index) {
109
+ this.tabPanels[index].focus();
110
+ return this;
111
+ },
112
+ /**
113
+ * Selects a tab based on the URL hash
114
+ */ selectTabFromHash () {
115
+ const { hash } = global.location;
116
+ if (hash) {
117
+ const targetId = hash.substring(1); // Remove the '#' character
118
+ const targetIndex = this.tabLinks.findIndex((link)=>link.id === targetId);
119
+ if (targetIndex !== -1) {
120
+ this.handleTabInteraction(targetIndex);
121
+ }
122
+ }
123
+ }
124
+ };
125
+ /**
126
+ * Creates or returns existing component
127
+ * @param {string} selector
128
+ */ function createTabComponent(selector, options) {
129
+ const elements = document1.querySelectorAll(selector);
130
+ [].forEach.call(elements, (element)=>tabInstances.get(element) || new TabComponent(element, options));
131
+ }
132
+ /**
133
+ * Destroys an existing component
134
+ * @param {DOM Node} element
135
+ */ function destroyTabComponent(element) {
136
+ if (!element || !element.nodeType) {
137
+ return;
138
+ }
139
+ const component = tabInstances.get(element);
140
+ component.tabList.removeAttribute('role', 'tablist');
141
+ component.tabItems.forEach((item, index)=>{
142
+ item.removeAttribute('role', 'presentation');
143
+ if (index === 0) {
144
+ item.removeAttribute('data-tab-active');
145
+ }
146
+ });
147
+ component.tabLinks.forEach((item, index)=>{
148
+ item.removeAttribute('role', 'tab');
149
+ item.removeAttribute('id', `tab${index}`);
150
+ if (index > 0) {
151
+ item.removeAttribute('tabindex', '-1');
152
+ } else {
153
+ item.removeAttribute('aria-selected', 'true');
154
+ }
155
+ });
156
+ component.tabPanels.forEach((item, index)=>{
157
+ item.removeAttribute('role', 'tabpanel');
158
+ item.removeAttribute('aria-labelledby', `tab${index}`);
159
+ item.removeAttribute('tabindex', '-1');
160
+ if (index > 0) {
161
+ item.removeAttribute('hidden');
162
+ }
163
+ });
164
+ component.tabList.removeEventListener('click', component.eventCallback);
165
+ component.tabList.removeEventListener('keydown', component.eventCallback);
166
+ tabInstances.delete(component.element);
167
+ }
168
+ /**
169
+ * Handles all event listener callbacks
170
+ * @param {event} event
171
+ */ function handleEvents(event) {
172
+ if (event.type === 'click') {
173
+ event.preventDefault();
174
+ TabComponent.prototype.handleTabInteraction.call(this, this.tabLinks.indexOf(event.target));
175
+ }
176
+ if (event.type === 'keydown') {
177
+ const index = this.tabLinks.indexOf(event.target);
178
+ // Left and right arrows
179
+ if (event.which === 37 || event.which === 39) {
180
+ event.preventDefault();
181
+ TabComponent.prototype.handleTabInteraction.call(this, index, event.which);
182
+ }
183
+ // Down arrow
184
+ if (event.which === 40) {
185
+ event.preventDefault();
186
+ TabComponent.prototype.handleTabpanelFocus.call(this, index);
187
+ }
188
+ }
189
+ }
190
+ return {
191
+ create: createTabComponent,
192
+ destroy: destroyTabComponent
193
+ };
252
194
  }(window, document);
253
-
254
195
  // eslint-disable-next-line no-unused-vars,no-undef
255
- var tabComponent = a11yTabs.create('[data-tab-component]');
196
+ const tabComponent = a11yTabs.create('[data-tab-component]');
@@ -1,54 +1,41 @@
1
- 'use strict';
2
-
3
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
4
-
5
1
  // DUMMY TIMELINE ITEM OPEN/CLOSE
2
+ "use strict";
6
3
  function wrap(el, wrapper) {
7
- el.parentNode.insertBefore(wrapper, el);
8
- wrapper.classList.add('wrapper');
9
- wrapper.appendChild(el);
4
+ el.parentNode.insertBefore(wrapper, el);
5
+ wrapper.classList.add('wrapper');
6
+ wrapper.appendChild(el);
10
7
  }
11
-
12
- var timeLineItems = document.querySelectorAll('.js-timeline-item');
13
- var timeLineItemScrollPosition = 0;
14
-
15
- [].forEach.call(timeLineItems, function (timeLineItem) {
16
- var timeLineItemLink = timeLineItem.querySelector('a');
17
- var timeLineItemClose = timeLineItem.querySelector('.js-timeline-item-close');
18
- var timeLineItemBottomClose = timeLineItem.querySelector('.js-timeline-item-bottom-close');
19
-
20
- timeLineItemLink.addEventListener('click', function () {
21
- timeLineItemScrollPosition = window.pageYOffset;
22
- sessionStorage.setItem('scroll-position', timeLineItemScrollPosition);
23
-
24
- if (!timeLineItem.classList.contains('is-open')) {
25
- timeLineItem.classList.add('is-open');
26
- timeLineItem.closest('.row').classList.add('row-has-open-child');
27
-
28
- // Wrap open timeline item
29
- wrap(timeLineItem.querySelector('.wp-block-iis-timeline-post'), document.createElement('div'));
30
- }
31
- });
32
-
33
- timeLineItemClose.addEventListener('click', function () {
34
- timeLineItem.classList.remove('is-open');
35
- timeLineItem.closest('.row').classList.remove('row-has-open-child');
36
-
37
- // Destroy generated wrapper
38
- var wrapper = timeLineItemClose.nextElementSibling;
39
- wrapper.replaceWith.apply(wrapper, _toConsumableArray(wrapper.childNodes));
40
-
41
- var top = sessionStorage.getItem('scroll-position');
42
- if (top !== null) {
43
- window.scrollTo(0, parseInt(top, 10));
44
- }
45
- sessionStorage.removeItem('scroll-position');
46
-
47
- // Trigger scroll event to reveal timeline items not yet parallaxed into view
48
- window.dispatchEvent(new CustomEvent('scroll'));
49
- });
50
-
51
- timeLineItemBottomClose.addEventListener('click', function () {
52
- timeLineItemClose.click();
53
- });
54
- });
8
+ const timeLineItems = document.querySelectorAll('.js-timeline-item');
9
+ let timeLineItemScrollPosition = 0;
10
+ [].forEach.call(timeLineItems, (timeLineItem)=>{
11
+ const timeLineItemLink = timeLineItem.querySelector('a');
12
+ const timeLineItemClose = timeLineItem.querySelector('.js-timeline-item-close');
13
+ const timeLineItemBottomClose = timeLineItem.querySelector('.js-timeline-item-bottom-close');
14
+ timeLineItemLink.addEventListener('click', ()=>{
15
+ timeLineItemScrollPosition = window.pageYOffset;
16
+ sessionStorage.setItem('scroll-position', timeLineItemScrollPosition);
17
+ if (!timeLineItem.classList.contains('is-open')) {
18
+ timeLineItem.classList.add('is-open');
19
+ timeLineItem.closest('.row').classList.add('row-has-open-child');
20
+ // Wrap open timeline item
21
+ wrap(timeLineItem.querySelector('.wp-block-iis-timeline-post'), document.createElement('div'));
22
+ }
23
+ });
24
+ timeLineItemClose.addEventListener('click', ()=>{
25
+ timeLineItem.classList.remove('is-open');
26
+ timeLineItem.closest('.row').classList.remove('row-has-open-child');
27
+ // Destroy generated wrapper
28
+ const wrapper = timeLineItemClose.nextElementSibling;
29
+ wrapper.replaceWith(...wrapper.childNodes);
30
+ const top = sessionStorage.getItem('scroll-position');
31
+ if (top !== null) {
32
+ window.scrollTo(0, parseInt(top, 10));
33
+ }
34
+ sessionStorage.removeItem('scroll-position');
35
+ // Trigger scroll event to reveal timeline items not yet parallaxed into view
36
+ window.dispatchEvent(new CustomEvent('scroll'));
37
+ });
38
+ timeLineItemBottomClose.addEventListener('click', ()=>{
39
+ timeLineItemClose.click();
40
+ });
41
+ });