nsw-design-system 3.5.0 → 3.5.2

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.
package/dist/js/main.js CHANGED
@@ -1,144 +1,38 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
3
  typeof define === 'function' && define.amd ? define('NSW', ['exports'], factory) :
4
- (global = global || self, factory(global.NSW = {}));
5
- }(this, (function (exports) { 'use strict';
6
-
7
- function _classCallCheck(instance, Constructor) {
8
- if (!(instance instanceof Constructor)) {
9
- throw new TypeError("Cannot call a class as a function");
10
- }
11
- }
12
-
13
- function _defineProperties(target, props) {
14
- for (var i = 0; i < props.length; i++) {
15
- var descriptor = props[i];
16
- descriptor.enumerable = descriptor.enumerable || false;
17
- descriptor.configurable = true;
18
- if ("value" in descriptor) descriptor.writable = true;
19
- Object.defineProperty(target, descriptor.key, descriptor);
20
- }
21
- }
22
-
23
- function _createClass(Constructor, protoProps, staticProps) {
24
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
- if (staticProps) _defineProperties(Constructor, staticProps);
26
- return Constructor;
27
- }
28
-
29
- function _slicedToArray(arr, i) {
30
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
31
- }
32
-
33
- function _toConsumableArray(arr) {
34
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
35
- }
36
-
37
- function _arrayWithoutHoles(arr) {
38
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
39
- }
40
-
41
- function _arrayWithHoles(arr) {
42
- if (Array.isArray(arr)) return arr;
43
- }
44
-
45
- function _iterableToArray(iter) {
46
- if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
47
- }
48
-
49
- function _iterableToArrayLimit(arr, i) {
50
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
51
- var _arr = [];
52
- var _n = true;
53
- var _d = false;
54
- var _e = undefined;
55
-
56
- try {
57
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
58
- _arr.push(_s.value);
59
-
60
- if (i && _arr.length === i) break;
61
- }
62
- } catch (err) {
63
- _d = true;
64
- _e = err;
65
- } finally {
66
- try {
67
- if (!_n && _i["return"] != null) _i["return"]();
68
- } finally {
69
- if (_d) throw _e;
70
- }
71
- }
72
-
73
- return _arr;
74
- }
75
-
76
- function _unsupportedIterableToArray(o, minLen) {
77
- if (!o) return;
78
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
79
- var n = Object.prototype.toString.call(o).slice(8, -1);
80
- if (n === "Object" && o.constructor) n = o.constructor.name;
81
- if (n === "Map" || n === "Set") return Array.from(n);
82
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
83
- }
84
-
85
- function _arrayLikeToArray(arr, len) {
86
- if (len == null || len > arr.length) len = arr.length;
87
-
88
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
89
-
90
- return arr2;
91
- }
92
-
93
- function _nonIterableSpread() {
94
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
95
- }
96
-
97
- function _nonIterableRest() {
98
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
99
- }
100
-
101
- var SiteSearch = /*#__PURE__*/function () {
102
- function SiteSearch(element) {
103
- _classCallCheck(this, SiteSearch);
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.NSW = {}));
5
+ })(this, (function (exports) { 'use strict';
104
6
 
7
+ class SiteSearch {
8
+ constructor(element) {
105
9
  this.triggerButton = element;
106
10
  this.originalButton = document.querySelector('.js-open-search');
107
11
  this.targetElement = document.getElementById(this.triggerButton.getAttribute('aria-controls'));
108
12
  this.searchInput = this.targetElement.querySelector('.js-search-input');
109
13
  this.pressed = this.triggerButton.getAttribute('aria-expanded') === 'true';
110
14
  }
111
-
112
- _createClass(SiteSearch, [{
113
- key: "init",
114
- value: function init() {
115
- this.controls();
116
- }
117
- }, {
118
- key: "controls",
119
- value: function controls() {
120
- this.triggerButton.addEventListener('click', this.showHide.bind(this), false);
121
- }
122
- }, {
123
- key: "showHide",
124
- value: function showHide() {
125
- if (this.pressed) {
126
- this.targetElement.hidden = true;
127
- this.originalButton.hidden = false;
128
- this.originalButton.focus();
129
- } else {
130
- this.targetElement.hidden = false;
131
- this.originalButton.hidden = true;
132
- this.searchInput.focus();
133
- }
15
+ init() {
16
+ this.controls();
17
+ }
18
+ controls() {
19
+ this.triggerButton.addEventListener('click', this.showHide.bind(this), false);
20
+ }
21
+ showHide() {
22
+ if (this.pressed) {
23
+ this.targetElement.hidden = true;
24
+ this.originalButton.hidden = false;
25
+ this.originalButton.focus();
26
+ } else {
27
+ this.targetElement.hidden = false;
28
+ this.originalButton.hidden = true;
29
+ this.searchInput.focus();
134
30
  }
135
- }]);
136
-
137
- return SiteSearch;
138
- }();
31
+ }
32
+ }
139
33
 
140
- var focusObjectGenerator = function focusObjectGenerator(arr) {
141
- var focusableElements = {
34
+ const focusObjectGenerator = arr => {
35
+ const focusableElements = {
142
36
  all: arr,
143
37
  first: arr[0],
144
38
  last: arr[arr.length - 1],
@@ -146,25 +40,20 @@
146
40
  };
147
41
  return focusableElements;
148
42
  };
149
- var getFocusableElementBySelector = function getFocusableElementBySelector(id, selectorArr) {
150
- var _ref;
151
-
152
- var elements = [];
153
-
154
- for (var i = 0; i < selectorArr.length; i += 1) {
155
- elements.push([].slice.call(document.querySelectorAll("#".concat(id, " ").concat(selectorArr[i]))));
43
+ const getFocusableElementBySelector = (id, selectorArr) => {
44
+ const elements = [];
45
+ for (let i = 0; i < selectorArr.length; i += 1) {
46
+ elements.push([].slice.call(document.querySelectorAll(`#${id} ${selectorArr[i]}`)));
156
47
  }
157
-
158
- var mergedElementArr = (_ref = []).concat.apply(_ref, elements);
159
-
48
+ const mergedElementArr = [].concat(...elements);
160
49
  return focusObjectGenerator(mergedElementArr);
161
50
  };
162
- var trapTabKey = function trapTabKey(event, focusObject) {
163
- var _document = document,
164
- activeElement = _document.activeElement;
165
- var focusableElement = focusObject;
51
+ const trapTabKey = (event, focusObject) => {
52
+ const {
53
+ activeElement
54
+ } = document;
55
+ const focusableElement = focusObject;
166
56
  if (event.keyCode !== 9) return false;
167
-
168
57
  if (focusableElement.length === 1) {
169
58
  event.preventDefault();
170
59
  } else if (event.shiftKey && activeElement === focusableElement.first) {
@@ -174,33 +63,26 @@
174
63
  focusableElement.first.focus();
175
64
  event.preventDefault();
176
65
  }
177
-
178
66
  return true;
179
67
  };
180
- var whichTransitionEvent = function whichTransitionEvent() {
181
- var el = document.createElement('fakeelement');
182
- var transitions = {
68
+ const whichTransitionEvent = () => {
69
+ const el = document.createElement('fakeelement');
70
+ const transitions = {
183
71
  transition: 'transitionend',
184
72
  OTransition: 'oTransitionEnd',
185
73
  MozTransition: 'transitionend',
186
74
  WebkitTransition: 'webkitTransitionEnd'
187
75
  };
188
- var found = Object.keys(transitions).filter(function (key) {
189
- return el.style[key] !== undefined;
190
- });
76
+ const found = Object.keys(transitions).filter(key => el.style[key] !== undefined);
191
77
  return transitions[found[0]];
192
78
  };
193
- var uniqueId = function uniqueId(prefix) {
194
- var prefixValue = prefix === undefined ? 'nsw' : prefix;
195
- return "".concat(prefixValue, "-").concat(Math.random().toString(36).substr(2, 16));
79
+ const uniqueId = prefix => {
80
+ const prefixValue = prefix === undefined ? 'nsw' : prefix;
81
+ return `${prefixValue}-${Math.random().toString(36).substr(2, 16)}`;
196
82
  };
197
83
 
198
- var Navigation = /*#__PURE__*/function () {
199
- function Navigation() {
200
- var _this = this;
201
-
202
- _classCallCheck(this, Navigation);
203
-
84
+ class Navigation {
85
+ constructor() {
204
86
  this.openNavButton = document.querySelector('.js-open-nav');
205
87
  this.closeNavButtons = document.querySelectorAll('.js-close-nav');
206
88
  this.openSubNavButtons = document.querySelectorAll('.js-open-sub-nav');
@@ -208,370 +90,273 @@
208
90
  this.mainNavElement = document.getElementById('main-nav');
209
91
  this.isMegaMenuElement = !!document.querySelector('.js-mega-menu');
210
92
  this.transitionEvent = whichTransitionEvent();
211
-
212
- this.mobileToggleMainNavEvent = function (e) {
213
- return _this.mobileToggleMainNav(e);
214
- };
215
-
216
- this.mobileToggleSubNavEvent = function () {
217
- return _this.closeSubNav();
218
- };
219
-
220
- this.mobileShowMainTransitionEndEvent = function (e) {
221
- return _this.mobileShowMainNav(e);
222
- };
223
-
224
- this.mobileHideMainTransitionEndEvent = function (e) {
225
- return _this.mobileHideMainNav(e);
226
- };
227
-
228
- this.showSubNavTransitionEndEvent = function (e) {
229
- return _this.showSubNav(e);
230
- };
231
-
232
- this.mobileTrapTabKeyEvent = function (e) {
233
- return _this.mobileMainNavTrapTabs(e);
234
- };
235
-
236
- this.mobileSubNavTrapTabKeyEvent = function (e) {
237
- return _this.trapkeyEventStuff(e);
238
- };
239
-
240
- this.desktopButtonClickEvent = function (e) {
241
- return _this.buttonClickDesktop(e);
242
- };
243
-
244
- this.desktopButtonKeydownEvent = function (e) {
245
- return _this.buttonKeydownDesktop(e);
246
- };
247
-
248
- this.checkFocusEvent = function (e) {
249
- return _this.checkIfContainsFocus(e);
250
- };
251
-
252
- this.escapeCloseEvent = function (e) {
253
- return _this.escapeClose(e);
254
- };
255
-
93
+ this.mobileToggleMainNavEvent = e => this.mobileToggleMainNav(e);
94
+ this.mobileToggleSubNavEvent = () => this.closeSubNav();
95
+ this.mobileShowMainTransitionEndEvent = e => this.mobileShowMainNav(e);
96
+ this.mobileHideMainTransitionEndEvent = e => this.mobileHideMainNav(e);
97
+ this.showSubNavTransitionEndEvent = e => this.showSubNav(e);
98
+ this.mobileTrapTabKeyEvent = e => this.mobileMainNavTrapTabs(e);
99
+ this.mobileSubNavTrapTabKeyEvent = e => this.trapkeyEventStuff(e);
100
+ this.desktopButtonClickEvent = e => this.buttonClickDesktop(e);
101
+ this.desktopButtonKeydownEvent = e => this.buttonKeydownDesktop(e);
102
+ this.checkFocusEvent = e => this.checkIfContainsFocus(e);
103
+ this.escapeCloseEvent = e => this.escapeClose(e);
256
104
  this.openSubNavElements = [];
257
105
  this.breakpoint = window.matchMedia('(min-width: 62em)');
258
106
  this.body = document.body;
259
107
  }
260
-
261
- _createClass(Navigation, [{
262
- key: "init",
263
- value: function init() {
264
- var _this2 = this;
265
-
266
- if (this.mainNavElement) {
267
- this.setUpMobileControls();
268
- this.responsiveCheck(this.breakpoint);
269
- this.breakpoint.addListener(function (e) {
270
- return _this2.responsiveCheck(e);
271
- });
272
- }
108
+ init() {
109
+ if (this.mainNavElement) {
110
+ this.setUpMobileControls();
111
+ this.responsiveCheck(this.breakpoint);
112
+ this.breakpoint.addListener(e => this.responsiveCheck(e));
273
113
  }
274
- }, {
275
- key: "responsiveCheck",
276
- value: function responsiveCheck(e) {
277
- var megaMenuListItems = [];
278
-
279
- if (e.matches) {
280
- megaMenuListItems = [].slice.call(this.mainNavElement.querySelectorAll('ul > li'));
281
- this.body.classList.remove('main-nav-active');
282
- } else {
283
- megaMenuListItems = [].slice.call(this.mainNavElement.querySelectorAll('li'));
284
- }
285
-
286
- this.tearDownNavControls();
287
- this.setUpNavControls(megaMenuListItems);
288
- }
289
- }, {
290
- key: "tearDownNavControls",
291
- value: function tearDownNavControls() {
292
- var _this3 = this;
293
-
294
- if (this.isMegaMenuElement) {
295
- var listItems = [].slice.call(this.mainNavElement.querySelectorAll('li'));
296
- listItems.forEach(function (item) {
297
- var submenu = item.querySelector('[id^=sub-nav-]');
298
- var link = item.querySelector('a');
299
-
300
- if (submenu) {
301
- link.removeAttribute('role');
302
- link.removeAttribute('aria-expanded');
303
- link.removeAttribute('aria-controls');
304
- link.removeEventListener('click', _this3.desktopButtonClickEvent, false);
305
- link.removeEventListener('keydown', _this3.desktopButtonKeydownEvent, false);
306
- }
307
- });
308
- }
309
- }
310
- }, {
311
- key: "setUpMobileControls",
312
- value: function setUpMobileControls() {
313
- var _this4 = this;
314
-
315
- this.openNavButton.addEventListener('click', this.mobileToggleMainNavEvent, false);
316
- this.closeNavButtons.forEach(function (element) {
317
- element.addEventListener('click', _this4.mobileToggleMainNavEvent, false);
114
+ }
115
+ responsiveCheck(e) {
116
+ let megaMenuListItems = [];
117
+ if (e.matches) {
118
+ megaMenuListItems = [].slice.call(this.mainNavElement.querySelectorAll('ul > li'));
119
+ this.body.classList.remove('main-nav-active');
120
+ } else {
121
+ megaMenuListItems = [].slice.call(this.mainNavElement.querySelectorAll('li'));
122
+ }
123
+ this.tearDownNavControls();
124
+ this.setUpNavControls(megaMenuListItems);
125
+ }
126
+ tearDownNavControls() {
127
+ if (this.isMegaMenuElement) {
128
+ const listItems = [].slice.call(this.mainNavElement.querySelectorAll('li'));
129
+ listItems.forEach(item => {
130
+ const submenu = item.querySelector('[id^=sub-nav-]');
131
+ const link = item.querySelector('a');
132
+ if (submenu) {
133
+ link.removeAttribute('role');
134
+ link.removeAttribute('aria-expanded');
135
+ link.removeAttribute('aria-controls');
136
+ link.removeEventListener('click', this.desktopButtonClickEvent, false);
137
+ link.removeEventListener('keydown', this.desktopButtonKeydownEvent, false);
138
+ }
318
139
  });
319
- this.closeSubNavButtons.forEach(function (element) {
320
- element.addEventListener('click', _this4.mobileToggleSubNavEvent, false);
140
+ }
141
+ }
142
+ setUpMobileControls() {
143
+ this.openNavButton.addEventListener('click', this.mobileToggleMainNavEvent, false);
144
+ this.closeNavButtons.forEach(element => {
145
+ element.addEventListener('click', this.mobileToggleMainNavEvent, false);
146
+ });
147
+ this.closeSubNavButtons.forEach(element => {
148
+ element.addEventListener('click', this.mobileToggleSubNavEvent, false);
149
+ });
150
+ }
151
+ mobileMainNavTrapTabs(e) {
152
+ const elemObj = getFocusableElementBySelector(this.mainNavElement.id, ['> div button', '> ul > li > a']);
153
+ trapTabKey(e, elemObj);
154
+ }
155
+ setUpNavControls(listItems) {
156
+ if (this.isMegaMenuElement) {
157
+ listItems.forEach(item => {
158
+ const submenu = item.querySelector('[id^=sub-nav-]');
159
+ const link = item.querySelector('a');
160
+ if (submenu) {
161
+ link.setAttribute('role', 'button');
162
+ link.setAttribute('aria-expanded', 'false');
163
+ link.setAttribute('aria-controls', submenu.id);
164
+ link.addEventListener('click', this.desktopButtonClickEvent, false);
165
+ link.addEventListener('keydown', this.desktopButtonKeydownEvent, false);
166
+ document.addEventListener('keydown', this.escapeCloseEvent, false);
167
+ }
321
168
  });
322
169
  }
323
- }, {
324
- key: "mobileMainNavTrapTabs",
325
- value: function mobileMainNavTrapTabs(e) {
326
- var elemObj = getFocusableElementBySelector(this.mainNavElement.id, ['> div button', '> ul > li > a']);
327
- trapTabKey(e, elemObj);
170
+ }
171
+ mobileShowMainNav(_ref) {
172
+ let {
173
+ propertyName
174
+ } = _ref;
175
+ if (!propertyName === 'transform') return;
176
+ getFocusableElementBySelector(this.mainNavElement.id, ['> div button', '> ul > li > a']).all[1].focus();
177
+ this.mainNavElement.classList.add('active');
178
+ this.mainNavElement.classList.remove('activating');
179
+ this.mainNavElement.removeEventListener(this.transitionEvent, this.mobileShowMainTransitionEndEvent, false);
180
+ this.mainNavElement.addEventListener('keydown', this.mobileTrapTabKeyEvent, false);
181
+ }
182
+ mobileHideMainNav(_ref2) {
183
+ let {
184
+ propertyName
185
+ } = _ref2;
186
+ if (!propertyName === 'transform') return;
187
+ this.mainNavElement.classList.remove('active');
188
+ this.mainNavElement.classList.remove('closing');
189
+ while (this.openSubNavElements.length > 0) {
190
+ const {
191
+ submenu
192
+ } = this.whichSubNavLatest();
193
+ submenu.removeEventListener('keydown', this.mobileSubNavTrapTabKeyEvent, false);
194
+ submenu.classList.remove('active');
195
+ submenu.classList.remove('closing');
196
+ this.openSubNavElements.pop();
328
197
  }
329
- }, {
330
- key: "setUpNavControls",
331
- value: function setUpNavControls(listItems) {
332
- var _this5 = this;
333
-
334
- if (this.isMegaMenuElement) {
335
- listItems.forEach(function (item) {
336
- var submenu = item.querySelector('[id^=sub-nav-]');
337
- var link = item.querySelector('a');
338
-
339
- if (submenu) {
340
- link.setAttribute('role', 'button');
341
- link.setAttribute('aria-expanded', 'false');
342
- link.setAttribute('aria-controls', submenu.id);
343
- link.addEventListener('click', _this5.desktopButtonClickEvent, false);
344
- link.addEventListener('keydown', _this5.desktopButtonKeydownEvent, false);
345
- document.addEventListener('keydown', _this5.escapeCloseEvent, false);
346
- }
347
- });
348
- }
198
+ this.mainNavElement.removeEventListener(this.transitionEvent, this.mobileHideMainTransitionEndEvent, false);
199
+ this.mainNavElement.removeEventListener('keydown', this.mobileTrapTabKeyEvent, false);
200
+ }
201
+ mobileToggleMainNav(e) {
202
+ const {
203
+ currentTarget
204
+ } = e;
205
+ const isExpanded = currentTarget.getAttribute('aria-expanded') === 'true';
206
+ if (isExpanded) {
207
+ this.body.classList.remove('main-nav-active');
208
+ this.openNavButton.focus();
209
+ this.mainNavElement.classList.add('closing');
210
+ this.mainNavElement.addEventListener(this.transitionEvent, this.mobileHideMainTransitionEndEvent, false);
211
+ } else {
212
+ this.body.classList.add('main-nav-active');
213
+ this.mainNavElement.classList.add('activating');
214
+ this.mainNavElement.addEventListener(this.transitionEvent, this.mobileShowMainTransitionEndEvent, false);
349
215
  }
350
- }, {
351
- key: "mobileShowMainNav",
352
- value: function mobileShowMainNav(_ref) {
353
- var propertyName = _ref.propertyName;
354
- if (!propertyName === 'transform') return;
355
- getFocusableElementBySelector(this.mainNavElement.id, ['> div button', '> ul > li > a']).all[1].focus();
356
- this.mainNavElement.classList.add('active');
357
- this.mainNavElement.classList.remove('activating');
358
- this.mainNavElement.removeEventListener(this.transitionEvent, this.mobileShowMainTransitionEndEvent, false);
359
- this.mainNavElement.addEventListener('keydown', this.mobileTrapTabKeyEvent, false);
216
+ }
217
+ buttonClickDesktop(e) {
218
+ const isDesktop = this.breakpoint.matches;
219
+ if (!isDesktop || !e.target.closest('.nsw-main-nav__sub-nav')) {
220
+ this.saveElements(e);
221
+ this.toggleSubNavDesktop();
222
+ e.preventDefault();
360
223
  }
361
- }, {
362
- key: "mobileHideMainNav",
363
- value: function mobileHideMainNav(_ref2) {
364
- var propertyName = _ref2.propertyName;
365
- if (!propertyName === 'transform') return;
366
- this.mainNavElement.classList.remove('active');
367
- this.mainNavElement.classList.remove('closing');
368
-
369
- while (this.openSubNavElements.length > 0) {
370
- var _this$whichSubNavLate = this.whichSubNavLatest(),
371
- submenu = _this$whichSubNavLate.submenu;
372
-
373
- submenu.removeEventListener('keydown', this.mobileSubNavTrapTabKeyEvent, false);
374
- submenu.classList.remove('active');
375
- submenu.classList.remove('closing');
376
- this.openSubNavElements.pop();
377
- }
378
-
379
- this.mainNavElement.removeEventListener(this.transitionEvent, this.mobileHideMainTransitionEndEvent, false);
380
- this.mainNavElement.removeEventListener('keydown', this.mobileTrapTabKeyEvent, false);
224
+ }
225
+ buttonKeydownDesktop(e) {
226
+ if (e.key === ' ' || e.key === 'Enter' || e.key === 'Spacebar') {
227
+ this.saveElements(e);
228
+ this.toggleSubNavDesktop();
229
+ e.preventDefault();
381
230
  }
382
- }, {
383
- key: "mobileToggleMainNav",
384
- value: function mobileToggleMainNav(e) {
385
- var currentTarget = e.currentTarget;
386
- var isExpanded = currentTarget.getAttribute('aria-expanded') === 'true';
387
-
231
+ }
232
+ escapeClose(e) {
233
+ if (e.key === 'Escape') {
234
+ const {
235
+ link
236
+ } = this.whichSubNavLatest();
237
+ const isExpanded = link.getAttribute('aria-expanded') === 'true';
388
238
  if (isExpanded) {
389
- this.body.classList.remove('main-nav-active');
390
- this.openNavButton.focus();
391
- this.mainNavElement.classList.add('closing');
392
- this.mainNavElement.addEventListener(this.transitionEvent, this.mobileHideMainTransitionEndEvent, false);
393
- } else {
394
- this.body.classList.add('main-nav-active');
395
- this.mainNavElement.classList.add('activating');
396
- this.mainNavElement.addEventListener(this.transitionEvent, this.mobileShowMainTransitionEndEvent, false);
397
- }
398
- }
399
- }, {
400
- key: "buttonClickDesktop",
401
- value: function buttonClickDesktop(e) {
402
- var isDesktop = this.breakpoint.matches;
403
-
404
- if (!isDesktop || !e.target.closest('.nsw-main-nav__sub-nav')) {
405
- this.saveElements(e);
406
- this.toggleSubNavDesktop();
407
- e.preventDefault();
408
- }
409
- }
410
- }, {
411
- key: "buttonKeydownDesktop",
412
- value: function buttonKeydownDesktop(e) {
413
- if (e.key === ' ' || e.key === 'Enter' || e.key === 'Spacebar') {
414
- this.saveElements(e);
415
- this.toggleSubNavDesktop();
239
+ this.toggleSubNavDesktop(true);
416
240
  e.preventDefault();
417
- }
418
- }
419
- }, {
420
- key: "escapeClose",
421
- value: function escapeClose(e) {
422
- if (e.key === 'Escape') {
423
- var _this$whichSubNavLate2 = this.whichSubNavLatest(),
424
- link = _this$whichSubNavLate2.link;
425
-
426
- var isExpanded = link.getAttribute('aria-expanded') === 'true';
427
-
428
- if (isExpanded) {
429
- this.toggleSubNavDesktop(true);
430
- e.preventDefault();
431
- link.focus();
432
- }
433
- }
434
- }
435
- }, {
436
- key: "saveElements",
437
- value: function saveElements(e) {
438
- var currentTarget = e.currentTarget;
439
- var temp = {
440
- submenu: document.getElementById(currentTarget.getAttribute('aria-controls')),
441
- link: currentTarget,
442
- linkParent: currentTarget.parentNode
443
- };
444
- this.openSubNavElements.push(temp);
445
- }
446
- }, {
447
- key: "showSubNav",
448
- value: function showSubNav(_ref3) {
449
- var propertyName = _ref3.propertyName;
450
-
451
- var _this$whichSubNavLate3 = this.whichSubNavLatest(),
452
- submenu = _this$whichSubNavLate3.submenu;
453
-
454
- if (!propertyName === 'transform') return;
455
- getFocusableElementBySelector(submenu.id, ['> div button', '> .nsw-main-nav__title a', '> ul > li > a']).all[2].focus();
456
- submenu.removeEventListener(this.transitionEvent, this.showSubNavTransitionEndEvent, false);
457
- }
458
- }, {
459
- key: "closeSubNav",
460
- value: function closeSubNav() {
461
- var _this$whichSubNavLate4 = this.whichSubNavLatest(),
462
- submenu = _this$whichSubNavLate4.submenu,
463
- link = _this$whichSubNavLate4.link;
464
-
465
- if (this.breakpoint.matches) {
466
- link.setAttribute('aria-expanded', false);
467
- link.classList.remove('active');
468
- this.mainNavElement.removeEventListener('focus', this.checkFocusEvent, true); // fix: workaround for safari because it doesn't support focus event
469
-
470
- this.mainNavElement.removeEventListener('click', this.checkFocusEvent, true);
471
- } else {
472
241
  link.focus();
473
- submenu.removeEventListener('keydown', this.mobileSubNavTrapTabKeyEvent, false);
474
- }
475
-
476
- submenu.classList.remove('active');
477
- submenu.closest('ul').parentElement.classList.remove('no-scroll');
478
- this.openSubNavElements.pop();
479
- }
480
- }, {
481
- key: "openSubNav",
482
- value: function openSubNav() {
483
- var _this$whichSubNavLate5 = this.whichSubNavLatest(),
484
- submenu = _this$whichSubNavLate5.submenu,
485
- link = _this$whichSubNavLate5.link;
486
-
487
- if (this.breakpoint.matches) {
488
- link.setAttribute('aria-expanded', true);
489
- link.classList.add('active');
490
- this.mainNavElement.addEventListener('focus', this.checkFocusEvent, true); // fix: workaround for safari because it doesn't support focus event
491
-
492
- this.mainNavElement.addEventListener('click', this.checkFocusEvent, true);
493
- } else {
494
- submenu.addEventListener('keydown', this.mobileSubNavTrapTabKeyEvent, false);
495
- submenu.addEventListener(this.transitionEvent, this.showSubNavTransitionEndEvent, false);
496
- }
497
-
498
- submenu.closest('ul').parentElement.scrollTop = 0;
499
- submenu.closest('ul').parentElement.classList.add('no-scroll');
500
- submenu.classList.add('active');
501
- }
502
- }, {
503
- key: "toggleSubNavDesktop",
504
- value: function toggleSubNavDesktop() {
505
- var _this$whichSubNavLate6 = this.whichSubNavLatest(),
506
- link = _this$whichSubNavLate6.link;
507
-
508
- var isExpanded = link.getAttribute('aria-expanded') === 'true';
509
-
510
- if (isExpanded) {
511
- this.closeSubNav();
512
- } else {
513
- this.openSubNav();
514
- }
515
- }
516
- }, {
517
- key: "checkIfContainsFocus",
518
- value: function checkIfContainsFocus(e) {
519
- var _this$whichSubNavLate7 = this.whichSubNavLatest(),
520
- linkParent = _this$whichSubNavLate7.linkParent;
521
-
522
- var focusWithin = linkParent.contains(e.target);
523
- var isButton = e.target.getAttribute('role');
524
-
525
- if (!focusWithin && isButton) {
526
- this.toggleSubNavDesktop();
527
242
  }
528
243
  }
529
- }, {
530
- key: "whichSubNavLatest",
531
- value: function whichSubNavLatest() {
532
- var lastSubNav = this.openSubNavElements.length - 1;
533
- return this.openSubNavElements[lastSubNav];
244
+ }
245
+ saveElements(e) {
246
+ const {
247
+ currentTarget
248
+ } = e;
249
+ const temp = {
250
+ submenu: document.getElementById(currentTarget.getAttribute('aria-controls')),
251
+ link: currentTarget,
252
+ linkParent: currentTarget.parentNode
253
+ };
254
+ this.openSubNavElements.push(temp);
255
+ }
256
+ showSubNav(_ref3) {
257
+ let {
258
+ propertyName
259
+ } = _ref3;
260
+ const {
261
+ submenu
262
+ } = this.whichSubNavLatest();
263
+ if (!propertyName === 'transform') return;
264
+ getFocusableElementBySelector(submenu.id, ['> div button', '> .nsw-main-nav__title a', '> ul > li > a']).all[2].focus();
265
+ submenu.removeEventListener(this.transitionEvent, this.showSubNavTransitionEndEvent, false);
266
+ }
267
+ closeSubNav() {
268
+ const {
269
+ submenu,
270
+ link
271
+ } = this.whichSubNavLatest();
272
+ if (this.breakpoint.matches) {
273
+ link.setAttribute('aria-expanded', false);
274
+ link.classList.remove('active');
275
+ this.mainNavElement.removeEventListener('focus', this.checkFocusEvent, true);
276
+ // fix: workaround for safari because it doesn't support focus event
277
+ this.mainNavElement.removeEventListener('click', this.checkFocusEvent, true);
278
+ } else {
279
+ link.focus();
280
+ submenu.removeEventListener('keydown', this.mobileSubNavTrapTabKeyEvent, false);
281
+ }
282
+ submenu.classList.remove('active');
283
+ submenu.closest('ul').parentElement.classList.remove('no-scroll');
284
+ this.openSubNavElements.pop();
285
+ }
286
+ openSubNav() {
287
+ const {
288
+ submenu,
289
+ link
290
+ } = this.whichSubNavLatest();
291
+ if (this.breakpoint.matches) {
292
+ link.setAttribute('aria-expanded', true);
293
+ link.classList.add('active');
294
+ this.mainNavElement.addEventListener('focus', this.checkFocusEvent, true);
295
+ // fix: workaround for safari because it doesn't support focus event
296
+ this.mainNavElement.addEventListener('click', this.checkFocusEvent, true);
297
+ } else {
298
+ submenu.addEventListener('keydown', this.mobileSubNavTrapTabKeyEvent, false);
299
+ submenu.addEventListener(this.transitionEvent, this.showSubNavTransitionEndEvent, false);
300
+ }
301
+ submenu.closest('ul').parentElement.scrollTop = 0;
302
+ submenu.closest('ul').parentElement.classList.add('no-scroll');
303
+ submenu.classList.add('active');
304
+ }
305
+ toggleSubNavDesktop() {
306
+ const {
307
+ link
308
+ } = this.whichSubNavLatest();
309
+ const isExpanded = link.getAttribute('aria-expanded') === 'true';
310
+ if (isExpanded) {
311
+ this.closeSubNav();
312
+ } else {
313
+ this.openSubNav();
534
314
  }
535
- }, {
536
- key: "trapkeyEventStuff",
537
- value: function trapkeyEventStuff(e) {
538
- var _this$whichSubNavLate8 = this.whichSubNavLatest(),
539
- submenu = _this$whichSubNavLate8.submenu;
540
-
541
- var elemObj = getFocusableElementBySelector(submenu.id, ['> div button', '> ul > li > a']);
542
- trapTabKey(e, elemObj);
315
+ }
316
+ checkIfContainsFocus(e) {
317
+ const {
318
+ linkParent
319
+ } = this.whichSubNavLatest();
320
+ const focusWithin = linkParent.contains(e.target);
321
+ const isButton = e.target.getAttribute('role');
322
+ if (!focusWithin && isButton) {
323
+ this.toggleSubNavDesktop();
543
324
  }
544
- }]);
545
-
546
- return Navigation;
547
- }();
325
+ }
326
+ whichSubNavLatest() {
327
+ const lastSubNav = this.openSubNavElements.length - 1;
328
+ return this.openSubNavElements[lastSubNav];
329
+ }
330
+ trapkeyEventStuff(e) {
331
+ const {
332
+ submenu
333
+ } = this.whichSubNavLatest();
334
+ const elemObj = getFocusableElementBySelector(submenu.id, ['> div button', '> ul > li > a']);
335
+ trapTabKey(e, elemObj);
336
+ }
337
+ }
548
338
 
549
339
  function createButtons(_ref) {
550
- var textContent = _ref.textContent;
551
- var fragment = document.createDocumentFragment();
552
- var button = document.createElement('button');
553
- var uID = uniqueId('accordion');
340
+ let {
341
+ textContent
342
+ } = _ref;
343
+ const fragment = document.createDocumentFragment();
344
+ const button = document.createElement('button');
345
+ const uID = uniqueId('accordion');
554
346
  button.textContent = textContent;
555
347
  button.setAttribute('type', 'button');
556
348
  button.setAttribute('aria-expanded', 'false');
557
349
  button.setAttribute('aria-controls', uID);
558
350
  button.classList.add('nsw-accordion__button');
559
- button.insertAdjacentHTML('beforeend', "\n <span class=\"material-icons nsw-material-icons\" focusable=\"false\" aria-hidden=\"true\">keyboard_arrow_down</span>\n ");
351
+ button.insertAdjacentHTML('beforeend', `
352
+ <span class="material-icons nsw-material-icons" focusable="false" aria-hidden="true">keyboard_arrow_down</span>
353
+ `);
560
354
  fragment.appendChild(button);
561
355
  return fragment;
562
356
  }
563
-
564
- var Accordion = /*#__PURE__*/function () {
565
- function Accordion(element) {
566
- var _this = this;
567
-
568
- _classCallCheck(this, Accordion);
569
-
570
- var _Array$from = Array.from(element.querySelectorAll('.nsw-accordion__toggle button')),
571
- _Array$from2 = _slicedToArray(_Array$from, 2),
572
- expandAll = _Array$from2[0],
573
- collapseAll = _Array$from2[1];
574
-
357
+ class Accordion {
358
+ constructor(element) {
359
+ const [expandAll, collapseAll] = Array.from(element.querySelectorAll('.nsw-accordion__toggle button'));
575
360
  this.accordionHeadingClass = '.nsw-accordion__title';
576
361
  this.accordion = element;
577
362
  this.headings = element.querySelectorAll(this.accordionHeadingClass);
@@ -579,229 +364,142 @@
579
364
  this.collapseAllBtn = collapseAll;
580
365
  this.buttons = [];
581
366
  this.content = [];
582
-
583
- this.toggleEvent = function (e) {
584
- return _this.toggle(e);
585
- };
586
-
587
- this.expandAllEvent = function (e) {
588
- return _this.expandAll(e);
589
- };
590
-
591
- this.collapseAllEvent = function (e) {
592
- return _this.collapseAll(e);
593
- };
367
+ this.toggleEvent = e => this.toggle(e);
368
+ this.expandAllEvent = e => this.expandAll(e);
369
+ this.collapseAllEvent = e => this.collapseAll(e);
594
370
  }
595
-
596
- _createClass(Accordion, [{
597
- key: "init",
598
- value: function init() {
599
- this.setUpDom();
600
- this.controls();
601
- }
602
- }, {
603
- key: "setUpDom",
604
- value: function setUpDom() {
605
- var _this2 = this;
606
-
607
- this.accordion.classList.add('ready');
608
-
609
- if (this.collapseAllBtn) {
610
- this.collapseAllBtn.disabled = true;
611
- }
612
-
613
- this.headings.forEach(function (heading) {
614
- var headingElem = heading;
615
- var contentElem = heading.nextElementSibling;
616
- var buttonFrag = createButtons(heading);
617
- headingElem.textContent = '';
618
- headingElem.appendChild(buttonFrag);
619
- var buttonElem = headingElem.getElementsByTagName('button')[0];
620
- contentElem.id = buttonElem.getAttribute('aria-controls');
621
- contentElem.hidden = true;
622
-
623
- _this2.content.push(contentElem);
624
-
625
- _this2.buttons.push(buttonElem);
626
- });
627
- }
628
- }, {
629
- key: "controls",
630
- value: function controls() {
631
- var _this3 = this;
632
-
633
- this.buttons.forEach(function (element) {
634
- element.addEventListener('click', _this3.toggleEvent, false);
635
- });
636
-
637
- if (this.expandAllBtn && this.collapseAllBtn) {
638
- this.expandAllBtn.addEventListener('click', this.expandAllEvent, false);
639
- this.collapseAllBtn.addEventListener('click', this.collapseAllEvent, false);
640
- }
641
- }
642
- }, {
643
- key: "getTargetContent",
644
- value: function getTargetContent(element) {
645
- var currentIndex = this.buttons.indexOf(element);
646
- return this.content[currentIndex];
647
- }
648
- }, {
649
- key: "setAccordionState",
650
- value: function setAccordionState(element, state) {
651
- var targetContent = this.getTargetContent(element);
652
-
653
- if (state === 'open') {
654
- element.classList.add('active');
655
- element.setAttribute('aria-expanded', 'true');
656
- targetContent.hidden = false;
657
- } else if (state === 'close') {
658
- element.classList.remove('active');
659
- element.setAttribute('aria-expanded', 'false');
660
- targetContent.hidden = true;
661
- }
371
+ init() {
372
+ this.setUpDom();
373
+ this.controls();
374
+ }
375
+ setUpDom() {
376
+ this.accordion.classList.add('ready');
377
+ if (this.collapseAllBtn) {
378
+ this.collapseAllBtn.disabled = true;
662
379
  }
663
- }, {
664
- key: "toggle",
665
- value: function toggle(e) {
666
- var currentTarget = e.currentTarget;
667
- var targetContent = this.getTargetContent(currentTarget);
668
- var isHidden = targetContent.hidden;
669
-
670
- if (isHidden) {
671
- this.setAccordionState(currentTarget, 'open');
672
- } else {
673
- this.setAccordionState(currentTarget, 'close');
674
- }
675
-
676
- if (this.expandAllBtn && this.collapseAllBtn) {
677
- this.expandAllBtn.disabled = this.content.every(function (item) {
678
- return item.hidden === false;
679
- });
680
- this.collapseAllBtn.disabled = this.content.every(function (item) {
681
- return item.hidden === true;
682
- });
683
- }
380
+ this.headings.forEach(heading => {
381
+ const headingElem = heading;
382
+ const contentElem = heading.nextElementSibling;
383
+ const buttonFrag = createButtons(heading);
384
+ headingElem.textContent = '';
385
+ headingElem.appendChild(buttonFrag);
386
+ const buttonElem = headingElem.getElementsByTagName('button')[0];
387
+ contentElem.id = buttonElem.getAttribute('aria-controls');
388
+ contentElem.hidden = true;
389
+ this.content.push(contentElem);
390
+ this.buttons.push(buttonElem);
391
+ });
392
+ }
393
+ controls() {
394
+ this.buttons.forEach(element => {
395
+ element.addEventListener('click', this.toggleEvent, false);
396
+ });
397
+ if (this.expandAllBtn && this.collapseAllBtn) {
398
+ this.expandAllBtn.addEventListener('click', this.expandAllEvent, false);
399
+ this.collapseAllBtn.addEventListener('click', this.collapseAllEvent, false);
684
400
  }
685
- }, {
686
- key: "expandAll",
687
- value: function expandAll() {
688
- var _this4 = this;
689
-
690
- this.buttons.forEach(function (element) {
691
- _this4.setAccordionState(element, 'open');
692
- });
693
- this.expandAllBtn.disabled = true;
694
- this.collapseAllBtn.disabled = false;
401
+ }
402
+ getTargetContent(element) {
403
+ const currentIndex = this.buttons.indexOf(element);
404
+ return this.content[currentIndex];
405
+ }
406
+ setAccordionState(element, state) {
407
+ const targetContent = this.getTargetContent(element);
408
+ if (state === 'open') {
409
+ element.classList.add('active');
410
+ element.setAttribute('aria-expanded', 'true');
411
+ targetContent.hidden = false;
412
+ } else if (state === 'close') {
413
+ element.classList.remove('active');
414
+ element.setAttribute('aria-expanded', 'false');
415
+ targetContent.hidden = true;
695
416
  }
696
- }, {
697
- key: "collapseAll",
698
- value: function collapseAll() {
699
- var _this5 = this;
700
-
701
- this.buttons.forEach(function (element) {
702
- _this5.setAccordionState(element, 'close');
703
- });
704
- this.expandAllBtn.disabled = false;
705
- this.collapseAllBtn.disabled = true;
417
+ }
418
+ toggle(e) {
419
+ const {
420
+ currentTarget
421
+ } = e;
422
+ const targetContent = this.getTargetContent(currentTarget);
423
+ const isHidden = targetContent.hidden;
424
+ if (isHidden) {
425
+ this.setAccordionState(currentTarget, 'open');
426
+ } else {
427
+ this.setAccordionState(currentTarget, 'close');
428
+ }
429
+ if (this.expandAllBtn && this.collapseAllBtn) {
430
+ this.expandAllBtn.disabled = this.content.every(item => item.hidden === false);
431
+ this.collapseAllBtn.disabled = this.content.every(item => item.hidden === true);
706
432
  }
707
- }]);
708
-
709
- return Accordion;
710
- }();
711
-
712
- var Dialog = /*#__PURE__*/function () {
713
- function Dialog(element) {
714
- var _this = this;
715
-
716
- _classCallCheck(this, Dialog);
433
+ }
434
+ expandAll() {
435
+ this.buttons.forEach(element => {
436
+ this.setAccordionState(element, 'open');
437
+ });
438
+ this.expandAllBtn.disabled = true;
439
+ this.collapseAllBtn.disabled = false;
440
+ }
441
+ collapseAll() {
442
+ this.buttons.forEach(element => {
443
+ this.setAccordionState(element, 'close');
444
+ });
445
+ this.expandAllBtn.disabled = false;
446
+ this.collapseAllBtn.disabled = true;
447
+ }
448
+ }
717
449
 
450
+ class Dialog {
451
+ constructor(element) {
718
452
  this.dialog = element;
719
453
  this.dialogWrapper = element.querySelector('.nsw-dialog__wrapper');
720
454
  this.openBtn = document.querySelectorAll('.js-open-dialog-'.concat(element.getAttribute('id')));
721
- this.closeBtn = element.querySelectorAll('.js-close-dialog'); // eslint-disable-next-line max-len
722
-
455
+ this.closeBtn = element.querySelectorAll('.js-close-dialog');
456
+ // eslint-disable-next-line max-len
723
457
  this.focusableEls = element.querySelectorAll('a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])');
724
458
  this.body = document.body;
725
-
726
- this.openEvent = function (e) {
727
- return _this.openDialog(e);
728
- };
729
-
730
- this.closeEvent = function (e) {
731
- return _this.closeDialog(e);
732
- };
733
-
734
- this.clickEvent = function (e) {
735
- return _this.clickDialog(e);
736
- };
737
-
738
- this.trapEvent = function (e) {
739
- return _this.trapFocus(e);
740
- };
459
+ this.openEvent = e => this.openDialog(e);
460
+ this.closeEvent = e => this.closeDialog(e);
461
+ this.clickEvent = e => this.clickDialog(e);
462
+ this.trapEvent = e => this.trapFocus(e);
741
463
  }
742
-
743
- _createClass(Dialog, [{
744
- key: "init",
745
- value: function init() {
746
- this.controls();
747
- }
748
- }, {
749
- key: "controls",
750
- value: function controls() {
751
- var _this2 = this;
752
-
753
- this.openBtn.forEach(function (btn) {
754
- btn.addEventListener('click', _this2.openEvent, false);
755
- });
756
- this.closeBtn.forEach(function (btn) {
757
- btn.addEventListener('click', _this2.closeEvent, false);
758
- });
759
-
760
- if (this.dialog.classList.contains('js-dialog-dismiss')) {
761
- this.dialog.addEventListener('click', this.clickEvent, false);
762
- }
763
-
764
- this.focusableEls[this.focusableEls.length - 1].addEventListener('blur', this.trapEvent, false);
765
- }
766
- }, {
767
- key: "openDialog",
768
- value: function openDialog() {
769
- this.dialog.setAttribute('aria-expanded', 'true');
770
- this.dialog.classList.add('active');
771
- this.body.classList.add('dialog-active');
772
- this.focusableEls[0].focus();
773
- }
774
- }, {
775
- key: "closeDialog",
776
- value: function closeDialog() {
777
- this.dialog.setAttribute('aria-expanded', 'false');
778
- this.dialog.classList.remove('active');
779
- this.body.classList.remove('dialog-active');
780
- }
781
- }, {
782
- key: "clickDialog",
783
- value: function clickDialog(e) {
784
- if (!this.dialogWrapper.contains(e.target)) {
785
- this.closeDialog();
786
- }
464
+ init() {
465
+ this.controls();
466
+ }
467
+ controls() {
468
+ this.openBtn.forEach(btn => {
469
+ btn.addEventListener('click', this.openEvent, false);
470
+ });
471
+ this.closeBtn.forEach(btn => {
472
+ btn.addEventListener('click', this.closeEvent, false);
473
+ });
474
+ if (this.dialog.classList.contains('js-dialog-dismiss')) {
475
+ this.dialog.addEventListener('click', this.clickEvent, false);
787
476
  }
788
- }, {
789
- key: "trapFocus",
790
- value: function trapFocus(e) {
791
- e.preventDefault();
792
- this.focusableEls[0].focus();
477
+ this.focusableEls[this.focusableEls.length - 1].addEventListener('blur', this.trapEvent, false);
478
+ }
479
+ openDialog() {
480
+ this.dialog.setAttribute('aria-expanded', 'true');
481
+ this.dialog.classList.add('active');
482
+ this.body.classList.add('dialog-active');
483
+ this.focusableEls[0].focus();
484
+ }
485
+ closeDialog() {
486
+ this.dialog.setAttribute('aria-expanded', 'false');
487
+ this.dialog.classList.remove('active');
488
+ this.body.classList.remove('dialog-active');
489
+ }
490
+ clickDialog(e) {
491
+ if (!this.dialogWrapper.contains(e.target)) {
492
+ this.closeDialog();
793
493
  }
794
- }]);
795
-
796
- return Dialog;
797
- }();
798
-
799
- var Filters = /*#__PURE__*/function () {
800
- function Filters(element) {
801
- var _this = this;
802
-
803
- _classCallCheck(this, Filters);
494
+ }
495
+ trapFocus(e) {
496
+ e.preventDefault();
497
+ this.focusableEls[0].focus();
498
+ }
499
+ }
804
500
 
501
+ class Filters {
502
+ constructor(element) {
805
503
  this.filters = element;
806
504
  this.filtersWrapper = element.querySelector('.nsw-filters__wrapper');
807
505
  this.openButton = element.querySelector('.nsw-filters__controls button');
@@ -818,463 +516,344 @@
818
516
  this.showAllBlocks = Array.prototype.slice.call(this.showAll);
819
517
  this.filtersItems = element.querySelectorAll('.nsw-filters__item');
820
518
  /* eslint-disable max-len */
821
-
822
519
  this.focusableEls = this.filtersWrapper.querySelectorAll('a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])');
823
520
  this.checkIcon = '<span class="material-icons nsw-material-icons" focusable="false" aria-hidden="true">check_circle</span>';
824
521
  this.arrowIcon = '<span class="material-icons nsw-material-icons" focusable="false" aria-hidden="true">keyboard_arrow_right</span>';
825
522
  /* eslint-ensable max-len */
826
-
827
- this.showEvent = function (e) {
828
- return _this.showFilters(e);
829
- };
830
-
831
- this.hideEvent = function (e) {
832
- return _this.hideFilters(e);
833
- };
834
-
835
- this.showMoreEvent = function (e) {
836
- return _this.showMore(e);
837
- };
838
-
839
- this.toggleEvent = function (e) {
840
- return _this.toggleAccordion(e);
841
- };
842
-
843
- this.resetEvent = function (e) {
844
- return _this.clearAllFilters(e);
845
- };
846
-
523
+ this.showEvent = e => this.showFilters(e);
524
+ this.hideEvent = e => this.hideFilters(e);
525
+ this.showMoreEvent = e => this.showMore(e);
526
+ this.toggleEvent = e => this.toggleAccordion(e);
527
+ this.resetEvent = e => this.clearAllFilters(e);
847
528
  this.body = document.body;
848
529
  this.buttons = [];
849
530
  this.content = [];
850
531
  this.selected = [];
851
532
  }
852
-
853
- _createClass(Filters, [{
854
- key: "init",
855
- value: function init() {
856
- this.setUpDom();
857
- this.controls();
858
- this.selectedItems();
859
- }
860
- }, {
861
- key: "setUpDom",
862
- value: function setUpDom() {
863
- var _this2 = this;
864
-
865
- this.filters.classList.add('ready');
866
-
867
- if (this.openButton) {
868
- if (this.openButtonIcons.length < 3) {
869
- this.openButton.insertAdjacentHTML('beforeend', this.arrowIcon);
870
- }
533
+ init() {
534
+ this.setUpDom();
535
+ this.controls();
536
+ this.selectedItems();
537
+ }
538
+ setUpDom() {
539
+ this.filters.classList.add('ready');
540
+ if (this.openButton) {
541
+ if (this.openButtonIcons.length < 3) {
542
+ this.openButton.insertAdjacentHTML('beforeend', this.arrowIcon);
871
543
  }
872
-
873
- this.accordionButtons.forEach(function (button) {
874
- var buttonElem = button;
875
- var uID = uniqueId('collapsed');
876
- buttonElem.setAttribute('type', 'button');
877
- buttonElem.setAttribute('aria-expanded', 'false');
878
- buttonElem.setAttribute('aria-controls', uID);
879
- var contentElem = buttonElem.nextElementSibling;
880
- contentElem.id = buttonElem.getAttribute('aria-controls');
881
- contentElem.hidden = true;
882
-
883
- _this2.content.push(contentElem);
884
-
885
- _this2.buttons.push(buttonElem);
886
- });
887
544
  }
888
- }, {
889
- key: "controls",
890
- value: function controls() {
891
- var _this3 = this;
892
-
893
- if (this.openButton) {
894
- this.openButton.addEventListener('click', this.showEvent, false);
895
- }
896
-
897
- if (this.acceptButton) {
898
- this.acceptButton.disabled = true;
899
- }
900
-
901
- if (this.closeButton) {
902
- this.closeButton.addEventListener('click', this.hideEvent, false);
903
- }
904
-
905
- this.showAll.forEach(function (element) {
906
- var showMoreButton = element.nextElementSibling;
907
- showMoreButton.addEventListener('click', _this3.showMoreEvent, false);
908
- });
909
-
910
- if (this.buttons) {
911
- this.buttons.forEach(function (element) {
912
- element.addEventListener('click', _this3.toggleEvent, false);
913
- });
914
- }
915
-
916
- if (this.clearButton) {
917
- this.clearButton.addEventListener('click', this.resetEvent, false);
918
- }
545
+ this.accordionButtons.forEach(button => {
546
+ const buttonElem = button;
547
+ const uID = uniqueId('collapsed');
548
+ buttonElem.setAttribute('type', 'button');
549
+ buttonElem.setAttribute('aria-expanded', 'false');
550
+ buttonElem.setAttribute('aria-controls', uID);
551
+ const contentElem = buttonElem.nextElementSibling;
552
+ contentElem.id = buttonElem.getAttribute('aria-controls');
553
+ contentElem.hidden = true;
554
+ this.content.push(contentElem);
555
+ this.buttons.push(buttonElem);
556
+ });
557
+ }
558
+ controls() {
559
+ if (this.openButton) {
560
+ this.openButton.addEventListener('click', this.showEvent, false);
919
561
  }
920
- }, {
921
- key: "showFilters",
922
- value: function showFilters(e) {
923
- e.preventDefault();
924
-
925
- if (this.filters.classList.contains('nsw-filters--down')) {
926
- this.filters.classList.toggle('active');
927
- } else {
928
- this.trapFocus(this.filtersWrapper);
929
- this.filters.classList.add('active');
930
- this.body.classList.add('filters-open');
931
- }
562
+ if (this.acceptButton) {
563
+ this.acceptButton.disabled = true;
932
564
  }
933
- }, {
934
- key: "hideFilters",
935
- value: function hideFilters(e) {
936
- e.preventDefault();
937
- this.filters.classList.remove('active');
938
- this.body.classList.remove('filters-open');
565
+ if (this.closeButton) {
566
+ this.closeButton.addEventListener('click', this.hideEvent, false);
939
567
  }
940
- }, {
941
- key: "showMore",
942
- value: function showMore(e) {
943
- e.preventDefault();
944
- var currentShowMore = e.target;
945
- var currentIndex = this.showMoreButtons.indexOf(currentShowMore);
946
- var currentAll = this.showAllBlocks[currentIndex];
947
- currentAll.classList.remove('hidden');
948
- currentShowMore.classList.add('hidden');
568
+ this.showAll.forEach(element => {
569
+ const showMoreButton = element.nextElementSibling;
570
+ showMoreButton.addEventListener('click', this.showMoreEvent, false);
571
+ });
572
+ if (this.buttons) {
573
+ this.buttons.forEach(element => {
574
+ element.addEventListener('click', this.toggleEvent, false);
575
+ });
949
576
  }
950
- }, {
951
- key: "getTargetContent",
952
- value: function getTargetContent(element) {
953
- var currentIndex = this.buttons.indexOf(element);
954
- return this.content[currentIndex];
577
+ if (this.clearButton) {
578
+ this.clearButton.addEventListener('click', this.resetEvent, false);
955
579
  }
956
- }, {
957
- key: "setAccordionState",
958
- value: function setAccordionState(element, state) {
959
- var targetContent = this.getTargetContent(element);
960
-
961
- if (state === 'open') {
962
- element.classList.add('active');
963
- element.setAttribute('aria-expanded', 'true');
964
- targetContent.hidden = false;
965
- } else if (state === 'close') {
966
- element.classList.remove('active');
967
- element.setAttribute('aria-expanded', 'false');
968
- targetContent.hidden = true;
969
- }
580
+ }
581
+ showFilters(e) {
582
+ e.preventDefault();
583
+ if (this.filters.classList.contains('nsw-filters--down')) {
584
+ this.filters.classList.toggle('active');
585
+ } else {
586
+ this.trapFocus(this.filtersWrapper);
587
+ this.filters.classList.add('active');
588
+ this.body.classList.add('filters-open');
970
589
  }
971
- }, {
972
- key: "toggleAccordion",
973
- value: function toggleAccordion(e) {
974
- var currentTarget = e.currentTarget;
975
- var targetContent = this.getTargetContent(currentTarget);
976
- var isHidden = targetContent.hidden;
977
-
978
- if (isHidden) {
979
- this.setAccordionState(currentTarget, 'open');
980
- } else {
981
- this.setAccordionState(currentTarget, 'close');
982
- }
590
+ }
591
+ hideFilters(e) {
592
+ e.preventDefault();
593
+ this.filters.classList.remove('active');
594
+ this.body.classList.remove('filters-open');
595
+ }
596
+ showMore(e) {
597
+ e.preventDefault();
598
+ const currentShowMore = e.target;
599
+ const currentIndex = this.showMoreButtons.indexOf(currentShowMore);
600
+ const currentAll = this.showAllBlocks[currentIndex];
601
+ currentAll.classList.remove('hidden');
602
+ currentShowMore.classList.add('hidden');
603
+ }
604
+ getTargetContent(element) {
605
+ const currentIndex = this.buttons.indexOf(element);
606
+ return this.content[currentIndex];
607
+ }
608
+ setAccordionState(element, state) {
609
+ const targetContent = this.getTargetContent(element);
610
+ if (state === 'open') {
611
+ element.classList.add('active');
612
+ element.setAttribute('aria-expanded', 'true');
613
+ targetContent.hidden = false;
614
+ } else if (state === 'close') {
615
+ element.classList.remove('active');
616
+ element.setAttribute('aria-expanded', 'false');
617
+ targetContent.hidden = true;
983
618
  }
984
- }, {
985
- key: "trapFocus",
986
- value: function trapFocus(element) {
987
- var firstFocusableEl = this.focusableEls[0];
988
- var lastFocusableEl = this.focusableEls[this.focusableEls.length - 1];
989
- var KEYCODE_TAB = 9;
990
- element.addEventListener('keydown', function (e) {
991
- var isTabPressed = e.key === 'Tab' || e.keyCode === KEYCODE_TAB;
992
-
993
- if (!isTabPressed) {
994
- return;
995
- }
996
-
997
- if (e.shiftKey) {
998
- if (document.activeElement === firstFocusableEl) {
999
- e.preventDefault();
1000
- lastFocusableEl.focus();
1001
- }
1002
- } else if (document.activeElement === lastFocusableEl) {
1003
- e.preventDefault();
1004
- firstFocusableEl.focus();
1005
- }
1006
- });
619
+ }
620
+ toggleAccordion(e) {
621
+ const {
622
+ currentTarget
623
+ } = e;
624
+ const targetContent = this.getTargetContent(currentTarget);
625
+ const isHidden = targetContent.hidden;
626
+ if (isHidden) {
627
+ this.setAccordionState(currentTarget, 'open');
628
+ } else {
629
+ this.setAccordionState(currentTarget, 'close');
1007
630
  }
1008
- }, {
1009
- key: "toggleAccept",
1010
- value: function toggleAccept(array) {
1011
- if (this.acceptButton) {
1012
- if (array.length > 0) {
1013
- this.acceptButton.disabled = false;
1014
- } else {
1015
- this.acceptButton.disabled = true;
631
+ }
632
+ trapFocus(element) {
633
+ const firstFocusableEl = this.focusableEls[0];
634
+ const lastFocusableEl = this.focusableEls[this.focusableEls.length - 1];
635
+ const KEYCODE_TAB = 9;
636
+ element.addEventListener('keydown', e => {
637
+ const isTabPressed = e.key === 'Tab' || e.keyCode === KEYCODE_TAB;
638
+ if (!isTabPressed) {
639
+ return;
640
+ }
641
+ if (e.shiftKey) {
642
+ if (document.activeElement === firstFocusableEl) {
643
+ e.preventDefault();
644
+ lastFocusableEl.focus();
1016
645
  }
646
+ } else if (document.activeElement === lastFocusableEl) {
647
+ e.preventDefault();
648
+ firstFocusableEl.focus();
1017
649
  }
1018
- }
1019
- }, {
1020
- key: "toggleSelectedState",
1021
- value: function toggleSelectedState(array) {
650
+ });
651
+ }
652
+ toggleAccept(array) {
653
+ if (this.acceptButton) {
1022
654
  if (array.length > 0) {
1023
- this.openButton.parentElement.classList.add('active');
655
+ this.acceptButton.disabled = false;
1024
656
  } else {
1025
- this.openButton.parentElement.classList.remove('active');
657
+ this.acceptButton.disabled = true;
1026
658
  }
1027
659
  }
1028
- }, {
1029
- key: "resultsCount",
1030
- value: function resultsCount(array, buttonText) {
1031
- if (this.openButtonText) {
1032
- if (array.length > 0) {
1033
- this.openButtonText.innerText = "".concat(buttonText, " (").concat(array.length, ")");
1034
- } else {
1035
- this.openButtonText.innerText = "".concat(buttonText);
1036
- }
660
+ }
661
+ toggleSelectedState(array) {
662
+ if (array.length > 0) {
663
+ this.openButton.parentElement.classList.add('active');
664
+ } else {
665
+ this.openButton.parentElement.classList.remove('active');
666
+ }
667
+ }
668
+ resultsCount(array, buttonText) {
669
+ if (this.openButtonText) {
670
+ if (array.length > 0) {
671
+ this.openButtonText.innerText = `${buttonText} (${array.length})`;
672
+ } else {
673
+ this.openButtonText.innerText = `${buttonText}`;
1037
674
  }
1038
675
  }
1039
- }, {
1040
- key: "updateDom",
1041
- value: function updateDom() {
1042
- this.resultsCount(this.selected, this.buttonLabel);
1043
- this.toggleAccept(this.selected);
1044
- this.toggleSelectedState(this.selected);
676
+ }
677
+ updateDom() {
678
+ this.resultsCount(this.selected, this.buttonLabel);
679
+ this.toggleAccept(this.selected);
680
+ this.toggleSelectedState(this.selected);
681
+ }
682
+ static getEventType(type) {
683
+ if (type === 'text') {
684
+ return 'input';
1045
685
  }
1046
- }, {
1047
- key: "updateCount",
1048
- value: function updateCount(options) {
1049
- var _this4 = this;
1050
-
1051
- var id = uniqueId();
1052
- var GroupArray = [];
1053
-
1054
- if (options.array.length > 0) {
1055
- options.array.forEach(function (element, index) {
1056
- var getEventType = _this4.constructor.getEventType(element.type);
1057
-
1058
- var _this4$constructor$si = _this4.constructor.singleCount(element, index, id),
1059
- uniqueID = _this4$constructor$si.uniqueID,
1060
- singleID = _this4$constructor$si.singleID,
1061
- isSingleCount = _this4$constructor$si.isSingleCount;
1062
-
1063
- if (_this4.constructor.getCondition(element)) {
1064
- _this4.selected.push(uniqueID);
1065
-
1066
- if (isSingleCount) {
1067
- GroupArray.push(singleID);
1068
- }
1069
-
1070
- _this4.updateDom();
686
+ return 'change';
687
+ }
688
+ static getCondition(element) {
689
+ if (element.type === 'text' || element.type === 'select-one') {
690
+ return element.value !== '';
691
+ }
692
+ return element.checked;
693
+ }
694
+ static singleCount(element, index, id) {
695
+ const isSingleCount = element.closest('.js-filters--single-count');
696
+ if (!isSingleCount) {
697
+ return {
698
+ uniqueID: `${id}-${index}`,
699
+ singleID: `${id}-${index}`,
700
+ isSingleCount
701
+ };
702
+ }
703
+ return {
704
+ uniqueID: `${id}`,
705
+ singleID: `${id}-${index}`,
706
+ isSingleCount
707
+ };
708
+ }
709
+ updateCount(options) {
710
+ const id = uniqueId();
711
+ const GroupArray = [];
712
+ if (options.array.length > 0) {
713
+ options.array.forEach((element, index) => {
714
+ const getEventType = this.constructor.getEventType(element.type);
715
+ const {
716
+ uniqueID,
717
+ singleID,
718
+ isSingleCount
719
+ } = this.constructor.singleCount(element, index, id);
720
+ if (this.constructor.getCondition(element)) {
721
+ this.selected.push(uniqueID);
722
+ if (isSingleCount) {
723
+ GroupArray.push(singleID);
1071
724
  }
1072
-
1073
- element.addEventListener(getEventType, function () {
1074
- var selectedIndex = _this4.selected.indexOf(uniqueID);
1075
-
1076
- var singleSelectedIndex = GroupArray.indexOf(singleID);
1077
-
1078
- if (_this4.constructor.getCondition(element)) {
1079
- if (!_this4.selected.includes(uniqueID)) {
1080
- _this4.selected.push(uniqueID);
1081
- }
1082
-
1083
- if (isSingleCount && !GroupArray.includes(singleID)) {
1084
- GroupArray.push(singleID);
1085
- }
1086
-
1087
- _this4.updateDom();
1088
- } else {
1089
- if (isSingleCount && singleSelectedIndex !== -1) {
1090
- GroupArray.splice(singleSelectedIndex, 1);
1091
- }
1092
-
1093
- if (!isSingleCount && selectedIndex !== -1) {
1094
- _this4.selected.splice(selectedIndex, 1);
1095
- } else if (GroupArray.length <= 0) {
1096
- _this4.selected.splice(selectedIndex, 1);
1097
- }
1098
-
1099
- _this4.updateDom();
725
+ this.updateDom();
726
+ }
727
+ element.addEventListener(getEventType, () => {
728
+ const selectedIndex = this.selected.indexOf(uniqueID);
729
+ const singleSelectedIndex = GroupArray.indexOf(singleID);
730
+ if (this.constructor.getCondition(element)) {
731
+ if (!this.selected.includes(uniqueID)) {
732
+ this.selected.push(uniqueID);
1100
733
  }
1101
- });
1102
- });
1103
- }
1104
- }
1105
- }, {
1106
- key: "updateStatus",
1107
- value: function updateStatus(options) {
1108
- var _this5 = this;
1109
-
1110
- var id = uniqueId();
1111
- var text = options.title;
1112
- var GroupArray = [];
1113
-
1114
- if (options.array.length > 0) {
1115
- var labelText = text ? text.textContent : null;
1116
- options.array.forEach(function (element, index) {
1117
- var getEventType = _this5.constructor.getEventType(element.type);
1118
-
1119
- var _this5$constructor$si = _this5.constructor.singleCount(element, index, id),
1120
- singleID = _this5$constructor$si.singleID;
1121
-
1122
- if (_this5.constructor.getCondition(element)) {
1123
- if (text) {
1124
- text.textContent = labelText;
1125
- text.innerHTML = "".concat(text.textContent, " ").concat(_this5.checkIcon);
734
+ if (isSingleCount && !GroupArray.includes(singleID)) {
735
+ GroupArray.push(singleID);
1126
736
  }
1127
- }
1128
-
1129
- element.addEventListener(getEventType, function () {
1130
- if (_this5.constructor.getCondition(element)) {
1131
- if (!GroupArray.includes(singleID)) {
1132
- GroupArray.push(singleID);
1133
- }
1134
- } else if (GroupArray.indexOf(singleID) !== -1) {
1135
- GroupArray.splice(GroupArray.indexOf(singleID), 1);
737
+ this.updateDom();
738
+ } else {
739
+ if (isSingleCount && singleSelectedIndex !== -1) {
740
+ GroupArray.splice(singleSelectedIndex, 1);
1136
741
  }
1137
-
1138
- if (text) {
1139
- if (GroupArray.length > 0) {
1140
- text.textContent = labelText;
1141
- text.innerHTML = "".concat(text.textContent, " ").concat(_this5.checkIcon);
1142
- } else {
1143
- text.textContent = labelText;
1144
- }
742
+ if (!isSingleCount && selectedIndex !== -1) {
743
+ this.selected.splice(selectedIndex, 1);
744
+ } else if (GroupArray.length <= 0) {
745
+ this.selected.splice(selectedIndex, 1);
1145
746
  }
1146
- });
1147
- });
1148
- }
1149
- }
1150
- }, {
1151
- key: "selectedItems",
1152
- value: function selectedItems() {
1153
- var _this6 = this;
1154
-
1155
- this.filtersItems.forEach(function (filter) {
1156
- var button = filter.querySelector('.nsw-filters__item-name');
1157
- var content = filter.querySelector('.nsw-filters__item-content');
1158
- var text = content ? content.querySelectorAll('input[type="text"]') : null;
1159
- var selects = content ? content.querySelectorAll('select') : null;
1160
- var checkboxes = content ? content.querySelectorAll('input[type="checkbox"]') : null;
1161
- if (!content) return;
1162
-
1163
- _this6.updateCount({
1164
- array: text,
1165
- title: button
1166
- });
1167
-
1168
- _this6.updateCount({
1169
- array: selects,
1170
- title: button
1171
- });
1172
-
1173
- _this6.updateCount({
1174
- array: checkboxes,
1175
- title: button
1176
- });
1177
-
1178
- _this6.updateStatus({
1179
- array: text,
1180
- title: button
1181
- });
1182
-
1183
- _this6.updateStatus({
1184
- array: selects,
1185
- title: button
1186
- });
1187
-
1188
- _this6.updateStatus({
1189
- array: checkboxes,
1190
- title: button
747
+ this.updateDom();
748
+ }
1191
749
  });
1192
750
  });
1193
751
  }
1194
- }, {
1195
- key: "clearAllFilters",
1196
- value: function clearAllFilters(e) {
1197
- var _this7 = this;
1198
-
1199
- e.preventDefault();
1200
- this.filtersItems.forEach(function (filter) {
1201
- var button = filter.querySelector('.nsw-filters__item-name');
1202
- var buttonCheck = button ? button.querySelector('span.nsw-material-icons') : null;
1203
- var content = filter.querySelector('.nsw-filters__item-content');
1204
- var text = content.querySelectorAll('input[type="text"]');
1205
- var selects = content.querySelectorAll('select');
1206
- var checkboxes = content.querySelectorAll('input[type="checkbox"]');
1207
- var allFields = [].concat(_toConsumableArray(text), _toConsumableArray(selects), _toConsumableArray(checkboxes));
1208
- if (!content) return;
1209
-
1210
- if (allFields.length > 0) {
1211
- allFields.forEach(function (input) {
1212
- var field = input;
1213
-
1214
- if (_this7.constructor.getCondition(field) && (field.type === 'text' || field.type === 'select-one')) {
1215
- field.value = '';
752
+ }
753
+ updateStatus(options) {
754
+ const id = uniqueId();
755
+ const text = options.title;
756
+ const GroupArray = [];
757
+ if (options.array.length > 0) {
758
+ const labelText = text ? text.textContent : null;
759
+ options.array.forEach((element, index) => {
760
+ const getEventType = this.constructor.getEventType(element.type);
761
+ const {
762
+ singleID
763
+ } = this.constructor.singleCount(element, index, id);
764
+ if (this.constructor.getCondition(element)) {
765
+ if (text) {
766
+ text.textContent = labelText;
767
+ text.innerHTML = `${text.textContent} ${this.checkIcon}`;
768
+ }
769
+ }
770
+ element.addEventListener(getEventType, () => {
771
+ if (this.constructor.getCondition(element)) {
772
+ if (!GroupArray.includes(singleID)) {
773
+ GroupArray.push(singleID);
774
+ }
775
+ } else if (GroupArray.indexOf(singleID) !== -1) {
776
+ GroupArray.splice(GroupArray.indexOf(singleID), 1);
777
+ }
778
+ if (text) {
779
+ if (GroupArray.length > 0) {
780
+ text.textContent = labelText;
781
+ text.innerHTML = `${text.textContent} ${this.checkIcon}`;
1216
782
  } else {
1217
- field.checked = false;
783
+ text.textContent = labelText;
1218
784
  }
1219
- });
1220
- }
1221
-
1222
- if (buttonCheck) {
1223
- buttonCheck.remove();
1224
- }
1225
-
1226
- _this7.selected = [];
1227
-
1228
- _this7.updateDom();
785
+ }
786
+ });
1229
787
  });
1230
788
  }
1231
- }], [{
1232
- key: "getEventType",
1233
- value: function getEventType(type) {
1234
- if (type === 'text') {
1235
- return 'input';
1236
- }
1237
-
1238
- return 'change';
1239
- }
1240
- }, {
1241
- key: "getCondition",
1242
- value: function getCondition(element) {
1243
- if (element.type === 'text' || element.type === 'select-one') {
1244
- return element.value !== '';
789
+ }
790
+ selectedItems() {
791
+ this.filtersItems.forEach(filter => {
792
+ const button = filter.querySelector('.nsw-filters__item-name');
793
+ const content = filter.querySelector('.nsw-filters__item-content');
794
+ const text = content ? content.querySelectorAll('input[type="text"]') : null;
795
+ const selects = content ? content.querySelectorAll('select') : null;
796
+ const checkboxes = content ? content.querySelectorAll('input[type="checkbox"]') : null;
797
+ if (!content) return;
798
+ this.updateCount({
799
+ array: text,
800
+ title: button
801
+ });
802
+ this.updateCount({
803
+ array: selects,
804
+ title: button
805
+ });
806
+ this.updateCount({
807
+ array: checkboxes,
808
+ title: button
809
+ });
810
+ this.updateStatus({
811
+ array: text,
812
+ title: button
813
+ });
814
+ this.updateStatus({
815
+ array: selects,
816
+ title: button
817
+ });
818
+ this.updateStatus({
819
+ array: checkboxes,
820
+ title: button
821
+ });
822
+ });
823
+ }
824
+ clearAllFilters(e) {
825
+ e.preventDefault();
826
+ this.filtersItems.forEach(filter => {
827
+ const button = filter.querySelector('.nsw-filters__item-name');
828
+ const buttonCheck = button ? button.querySelector('span.nsw-material-icons') : null;
829
+ const content = filter.querySelector('.nsw-filters__item-content');
830
+ const text = content.querySelectorAll('input[type="text"]');
831
+ const selects = content.querySelectorAll('select');
832
+ const checkboxes = content.querySelectorAll('input[type="checkbox"]');
833
+ const allFields = [...text, ...selects, ...checkboxes];
834
+ if (!content) return;
835
+ if (allFields.length > 0) {
836
+ allFields.forEach(input => {
837
+ const field = input;
838
+ if (this.constructor.getCondition(field) && (field.type === 'text' || field.type === 'select-one')) {
839
+ field.value = '';
840
+ } else {
841
+ field.checked = false;
842
+ }
843
+ });
1245
844
  }
1246
-
1247
- return element.checked;
1248
- }
1249
- }, {
1250
- key: "singleCount",
1251
- value: function singleCount(element, index, id) {
1252
- var isSingleCount = element.closest('.js-filters--single-count');
1253
-
1254
- if (!isSingleCount) {
1255
- return {
1256
- uniqueID: "".concat(id, "-").concat(index),
1257
- singleID: "".concat(id, "-").concat(index),
1258
- isSingleCount: isSingleCount
1259
- };
845
+ if (buttonCheck) {
846
+ buttonCheck.remove();
1260
847
  }
1261
-
1262
- return {
1263
- uniqueID: "".concat(id),
1264
- singleID: "".concat(id, "-").concat(index),
1265
- isSingleCount: isSingleCount
1266
- };
1267
- }
1268
- }]);
1269
-
1270
- return Filters;
1271
- }();
848
+ this.selected = [];
849
+ this.updateDom();
850
+ });
851
+ }
852
+ }
1272
853
 
1273
854
  /* eslint-disable max-len */
1274
- var FileUpload = /*#__PURE__*/function () {
1275
- function FileUpload(element) {
1276
- _classCallCheck(this, FileUpload);
1277
-
855
+ class FileUpload {
856
+ constructor(element) {
1278
857
  this.element = element;
1279
858
  this.input = this.element.querySelector('.nsw-file-upload__input');
1280
859
  this.label = this.element.querySelector('.nsw-file-upload__label');
@@ -1282,96 +861,70 @@
1282
861
  this.replaceFiles = this.element.hasAttribute('data-replace-files');
1283
862
  this.filesList = false;
1284
863
  }
1285
-
1286
- _createClass(FileUpload, [{
1287
- key: "init",
1288
- value: function init() {
1289
- var _this = this;
1290
-
1291
- if (!this.input) return;
1292
- this.input.addEventListener('change', function () {
1293
- if (_this.input.value === '') return;
1294
-
1295
- _this.updateFileList();
1296
- });
1297
- }
1298
- }, {
1299
- key: "createFileList",
1300
- value: function createFileList() {
1301
- var ul = document.createElement('ul');
1302
- ul.classList.add('nsw-file-upload__list');
1303
- this.label.insertAdjacentElement('afterend', ul);
1304
- this.filesList = this.element.querySelector('.nsw-file-upload__list');
1305
- }
1306
- }, {
1307
- key: "createFileItem",
1308
- value: function createFileItem(file) {
1309
- var li = document.createElement('li');
1310
- li.classList.add('nsw-file-upload__item');
1311
- var html = "\n <span class=\"nsw-file-upload__item-filename\"></span>\n <button type=\"button\" class=\"nsw-icon-button\">\n <span class=\"sr-only\">Remove file</span>\n <span class=\"material-icons nsw-material-icons\" focusable=\"false\" aria-hidden=\"true\">cancel</span>\n </button>";
1312
- li.insertAdjacentHTML('afterbegin', html);
1313
- li.querySelector('.nsw-file-upload__item-filename').textContent = this.constructor.truncateString(file.name, 50);
1314
- return li.outerHTML;
1315
- }
1316
- }, {
1317
- key: "updateFileList",
1318
- value: function updateFileList() {
1319
- if (!this.filesList) {
1320
- this.createFileList();
1321
- }
1322
-
1323
- this.filesList.classList.add('active');
1324
- var string = '';
1325
-
1326
- for (var i = 0; i < this.input.files.length; i += 1) {
1327
- var file = this.input.files[i];
1328
- string = this.createFileItem(file) + string;
1329
- }
1330
-
1331
- if (this.replaceFiles) {
1332
- this.filesList.innerHTML = string;
1333
- } else {
1334
- this.filesList.insertAdjacentHTML('beforeend', string);
1335
- }
1336
-
1337
- this.removeFile();
1338
- }
1339
- }, {
1340
- key: "removeFile",
1341
- value: function removeFile() {
1342
- var _this2 = this;
1343
-
1344
- this.filesList.addEventListener('click', function (event) {
1345
- if (!event.target.closest('.nsw-icon-button')) return;
1346
- event.preventDefault();
1347
- var item = event.target.closest('.nsw-file-upload__item');
1348
- item.remove();
1349
-
1350
- if (event.currentTarget.children.length === 0) {
1351
- _this2.filesList.classList.remove('active');
1352
- }
1353
- });
1354
- }
1355
- }], [{
1356
- key: "truncateString",
1357
- value: function truncateString(str, num) {
1358
- if (str.length <= num) {
1359
- return str;
864
+ init() {
865
+ if (!this.input) return;
866
+ this.input.addEventListener('change', () => {
867
+ if (this.input.value === '') return;
868
+ this.updateFileList();
869
+ });
870
+ }
871
+ createFileList() {
872
+ const ul = document.createElement('ul');
873
+ ul.classList.add('nsw-file-upload__list');
874
+ this.label.insertAdjacentElement('afterend', ul);
875
+ this.filesList = this.element.querySelector('.nsw-file-upload__list');
876
+ }
877
+ createFileItem(file) {
878
+ const li = document.createElement('li');
879
+ li.classList.add('nsw-file-upload__item');
880
+ const html = `
881
+ <span class="nsw-file-upload__item-filename"></span>
882
+ <button type="button" class="nsw-icon-button">
883
+ <span class="sr-only">Remove file</span>
884
+ <span class="material-icons nsw-material-icons" focusable="false" aria-hidden="true">cancel</span>
885
+ </button>`;
886
+ li.insertAdjacentHTML('afterbegin', html);
887
+ li.querySelector('.nsw-file-upload__item-filename').textContent = this.constructor.truncateString(file.name, 50);
888
+ return li.outerHTML;
889
+ }
890
+ updateFileList() {
891
+ if (!this.filesList) {
892
+ this.createFileList();
893
+ }
894
+ this.filesList.classList.add('active');
895
+ let string = '';
896
+ for (let i = 0; i < this.input.files.length; i += 1) {
897
+ const file = this.input.files[i];
898
+ string = this.createFileItem(file) + string;
899
+ }
900
+ if (this.replaceFiles) {
901
+ this.filesList.innerHTML = string;
902
+ } else {
903
+ this.filesList.insertAdjacentHTML('beforeend', string);
904
+ }
905
+ this.removeFile();
906
+ }
907
+ removeFile() {
908
+ this.filesList.addEventListener('click', event => {
909
+ if (!event.target.closest('.nsw-icon-button')) return;
910
+ event.preventDefault();
911
+ const item = event.target.closest('.nsw-file-upload__item');
912
+ item.remove();
913
+ if (event.currentTarget.children.length === 0) {
914
+ this.filesList.classList.remove('active');
1360
915
  }
1361
-
1362
- return "".concat(str.slice(0, num), "...");
916
+ });
917
+ }
918
+ static truncateString(str, num) {
919
+ if (str.length <= num) {
920
+ return str;
1363
921
  }
1364
- }]);
1365
-
1366
- return FileUpload;
1367
- }();
1368
-
1369
- var Tabs = /*#__PURE__*/function () {
1370
- function Tabs(element, showTab) {
1371
- var _this = this;
1372
-
1373
- _classCallCheck(this, Tabs);
922
+ return `${str.slice(0, num)}...`;
923
+ }
924
+ }
1374
925
 
926
+ class Tabs {
927
+ constructor(element, showTab) {
1375
928
  this.tablistClass = '.nsw-tabs__list';
1376
929
  this.tablistItemClass = 'li';
1377
930
  this.tablistLinkClass = 'a';
@@ -1383,209 +936,150 @@
1383
936
  this.tabLinks = [];
1384
937
  this.tabPanel = [];
1385
938
  this.selectedTab = null;
1386
-
1387
- this.clickTabEvent = function (e) {
1388
- return _this.clickTab(e);
1389
- };
1390
-
1391
- this.arrowKeysEvent = function (e) {
1392
- return _this.arrowKeys(e);
1393
- };
939
+ this.clickTabEvent = e => this.clickTab(e);
940
+ this.arrowKeysEvent = e => this.arrowKeys(e);
1394
941
  }
1395
-
1396
- _createClass(Tabs, [{
1397
- key: "init",
1398
- value: function init() {
1399
- this.setUpDom();
1400
- this.controls();
1401
- this.setInitalTab();
1402
- }
1403
- }, {
1404
- key: "setUpDom",
1405
- value: function setUpDom() {
1406
- var _this2 = this;
1407
-
1408
- var tabListWrapper = document.createElement('div');
1409
- tabListWrapper.classList.add('nsw-tabs__list-wrapper');
1410
- this.tab.prepend(tabListWrapper);
1411
- tabListWrapper.prepend(this.tabList);
1412
- this.tabList.setAttribute('role', 'tablist');
1413
- this.tabItems.forEach(function (item) {
1414
- var itemElem = item;
1415
- var itemLink = item.querySelector(_this2.tablistLinkClass);
1416
-
1417
- var panel = _this2.tab.querySelector(itemLink.hash);
1418
-
1419
- var uID = uniqueId('tab');
1420
- itemElem.setAttribute('role', 'presentation');
1421
-
1422
- _this2.enhanceTabLink(itemLink, uID);
1423
-
1424
- _this2.enhanceTabPanel(panel, uID);
1425
- });
1426
- }
1427
- }, {
1428
- key: "enhanceTabLink",
1429
- value: function enhanceTabLink(link, id) {
1430
- link.setAttribute('role', 'tab');
1431
- link.setAttribute('id', id);
1432
- link.setAttribute('aria-selected', false);
1433
- link.setAttribute('tabindex', '-1');
1434
- this.tabLinks.push(link);
1435
- }
1436
- }, {
1437
- key: "enhanceTabPanel",
1438
- value: function enhanceTabPanel(panel, id) {
1439
- var panelElem = panel;
1440
- panelElem.setAttribute('role', 'tabpanel');
1441
- panelElem.setAttribute('role', 'tabpanel');
1442
- panelElem.setAttribute('aria-labelledBy', id);
1443
- panelElem.setAttribute('tabindex', '0');
1444
- panelElem.hidden = true;
1445
- this.tabPanel.push(panelElem);
1446
- }
1447
- }, {
1448
- key: "setInitalTab",
1449
- value: function setInitalTab() {
1450
- var tabLinks = this.tabLinks,
1451
- tabPanel = this.tabPanel,
1452
- showTab = this.showTab;
1453
- var index = showTab === undefined ? 0 : showTab;
1454
- var selectedLink = tabLinks[index];
1455
- selectedLink.classList.add('active');
1456
- selectedLink.removeAttribute('tabindex');
1457
- selectedLink.setAttribute('aria-selected', true);
1458
- tabPanel[index].hidden = false;
1459
- this.selectedTab = selectedLink;
1460
- }
1461
- }, {
1462
- key: "clickTab",
1463
- value: function clickTab(e) {
1464
- e.preventDefault();
1465
- this.switchTabs(e.currentTarget);
1466
- }
1467
- }, {
1468
- key: "switchTabs",
1469
- value: function switchTabs(elem) {
1470
- var clickedTab = elem;
1471
-
1472
- if (clickedTab !== this.selectedTab) {
1473
- clickedTab.focus();
1474
- clickedTab.removeAttribute('tabindex');
1475
- clickedTab.setAttribute('aria-selected', true);
1476
- clickedTab.classList.add('active');
1477
- this.selectedTab.setAttribute('aria-selected', false);
1478
- this.selectedTab.setAttribute('tabindex', '-1');
1479
- this.selectedTab.classList.remove('active');
1480
- var clickedTabIndex = this.tabLinks.indexOf(clickedTab);
1481
- var selectedTabIndex = this.tabLinks.indexOf(this.selectedTab);
1482
- this.tabPanel[clickedTabIndex].hidden = false;
1483
- this.tabPanel[selectedTabIndex].hidden = true;
1484
- this.selectedTab = clickedTab;
1485
-
1486
- if (!clickedTab.classList.contains('js-tabs-fixed')) {
1487
- clickedTab.scrollIntoView({
1488
- behavior: 'smooth',
1489
- block: 'nearest',
1490
- inline: 'nearest'
1491
- });
1492
- }
942
+ init() {
943
+ this.setUpDom();
944
+ this.controls();
945
+ this.setInitalTab();
946
+ }
947
+ setUpDom() {
948
+ const tabListWrapper = document.createElement('div');
949
+ tabListWrapper.classList.add('nsw-tabs__list-wrapper');
950
+ this.tab.prepend(tabListWrapper);
951
+ tabListWrapper.prepend(this.tabList);
952
+ this.tabList.setAttribute('role', 'tablist');
953
+ this.tabItems.forEach(item => {
954
+ const itemElem = item;
955
+ const itemLink = item.querySelector(this.tablistLinkClass);
956
+ const panel = this.tab.querySelector(itemLink.hash);
957
+ const uID = uniqueId('tab');
958
+ itemElem.setAttribute('role', 'presentation');
959
+ this.enhanceTabLink(itemLink, uID);
960
+ this.enhanceTabPanel(panel, uID);
961
+ });
962
+ }
963
+ enhanceTabLink(link, id) {
964
+ link.setAttribute('role', 'tab');
965
+ link.setAttribute('id', id);
966
+ link.setAttribute('aria-selected', false);
967
+ link.setAttribute('tabindex', '-1');
968
+ this.tabLinks.push(link);
969
+ }
970
+ enhanceTabPanel(panel, id) {
971
+ const panelElem = panel;
972
+ panelElem.setAttribute('role', 'tabpanel');
973
+ panelElem.setAttribute('role', 'tabpanel');
974
+ panelElem.setAttribute('aria-labelledBy', id);
975
+ panelElem.setAttribute('tabindex', '0');
976
+ panelElem.hidden = true;
977
+ this.tabPanel.push(panelElem);
978
+ }
979
+ setInitalTab() {
980
+ const {
981
+ tabLinks,
982
+ tabPanel,
983
+ showTab
984
+ } = this;
985
+ const index = showTab === undefined ? 0 : showTab;
986
+ const selectedLink = tabLinks[index];
987
+ selectedLink.classList.add('active');
988
+ selectedLink.removeAttribute('tabindex');
989
+ selectedLink.setAttribute('aria-selected', true);
990
+ tabPanel[index].hidden = false;
991
+ this.selectedTab = selectedLink;
992
+ }
993
+ clickTab(e) {
994
+ e.preventDefault();
995
+ this.switchTabs(e.currentTarget);
996
+ }
997
+ switchTabs(elem) {
998
+ const clickedTab = elem;
999
+ if (clickedTab !== this.selectedTab) {
1000
+ clickedTab.focus();
1001
+ clickedTab.removeAttribute('tabindex');
1002
+ clickedTab.setAttribute('aria-selected', true);
1003
+ clickedTab.classList.add('active');
1004
+ this.selectedTab.setAttribute('aria-selected', false);
1005
+ this.selectedTab.setAttribute('tabindex', '-1');
1006
+ this.selectedTab.classList.remove('active');
1007
+ const clickedTabIndex = this.tabLinks.indexOf(clickedTab);
1008
+ const selectedTabIndex = this.tabLinks.indexOf(this.selectedTab);
1009
+ this.tabPanel[clickedTabIndex].hidden = false;
1010
+ this.tabPanel[selectedTabIndex].hidden = true;
1011
+ this.selectedTab = clickedTab;
1012
+ if (!clickedTab.classList.contains('js-tabs-fixed')) {
1013
+ clickedTab.scrollIntoView({
1014
+ behavior: 'smooth',
1015
+ block: 'nearest',
1016
+ inline: 'nearest'
1017
+ });
1493
1018
  }
1494
1019
  }
1495
- }, {
1496
- key: "arrowKeys",
1497
- value: function arrowKeys(_ref) {
1498
- var which = _ref.which;
1499
- var linkLength = this.tabLinks.length - 1;
1500
- var index = this.tabLinks.indexOf(this.selectedTab);
1501
- var down = false;
1502
-
1503
- if (this.allowedKeys.includes(which)) {
1504
- switch (which) {
1505
- case 35:
1506
- index = linkLength;
1507
- break;
1508
-
1509
- case 36:
1510
- index = 0;
1511
- break;
1512
-
1513
- case 37:
1514
- index = index === 0 ? -1 : index -= 1;
1515
- break;
1516
-
1517
- case 39:
1518
- index = index === linkLength ? -1 : index += 1;
1519
- break;
1520
-
1521
- case 40:
1522
- down = true;
1523
- break;
1524
- }
1525
-
1526
- if (index > -1) {
1527
- if (down) {
1528
- this.tabPanel[index].focus();
1529
- } else {
1530
- this.switchTabs(this.tabLinks[index]);
1531
- }
1020
+ }
1021
+ arrowKeys(_ref) {
1022
+ let {
1023
+ which
1024
+ } = _ref;
1025
+ const linkLength = this.tabLinks.length - 1;
1026
+ let index = this.tabLinks.indexOf(this.selectedTab);
1027
+ let down = false;
1028
+ if (this.allowedKeys.includes(which)) {
1029
+ switch (which) {
1030
+ case 35:
1031
+ index = linkLength;
1032
+ break;
1033
+ case 36:
1034
+ index = 0;
1035
+ break;
1036
+ case 37:
1037
+ index = index === 0 ? -1 : index -= 1;
1038
+ break;
1039
+ case 39:
1040
+ index = index === linkLength ? -1 : index += 1;
1041
+ break;
1042
+ case 40:
1043
+ down = true;
1044
+ break;
1045
+ }
1046
+ if (index > -1) {
1047
+ if (down) {
1048
+ this.tabPanel[index].focus();
1049
+ } else {
1050
+ this.switchTabs(this.tabLinks[index]);
1532
1051
  }
1533
1052
  }
1534
1053
  }
1535
- }, {
1536
- key: "controls",
1537
- value: function controls() {
1538
- var _this3 = this;
1539
-
1540
- this.tabLinks.forEach(function (link) {
1541
- link.addEventListener('click', _this3.clickTabEvent, false);
1542
- link.addEventListener('keydown', _this3.arrowKeysEvent, false);
1543
- });
1544
- }
1545
- }]);
1546
-
1547
- return Tabs;
1548
- }();
1549
-
1550
- var GlobalAlert = /*#__PURE__*/function () {
1551
- function GlobalAlert(element) {
1552
- var _this = this;
1553
-
1554
- _classCallCheck(this, GlobalAlert);
1054
+ }
1055
+ controls() {
1056
+ this.tabLinks.forEach(link => {
1057
+ link.addEventListener('click', this.clickTabEvent, false);
1058
+ link.addEventListener('keydown', this.arrowKeysEvent, false);
1059
+ });
1060
+ }
1061
+ }
1555
1062
 
1063
+ class GlobalAlert {
1064
+ constructor(element) {
1556
1065
  this.messageElement = element;
1557
1066
  this.closeButton = element.querySelector('.js-close-alert');
1558
-
1559
- this.closeMessageEvent = function (e) {
1560
- return _this.closeMessage(e);
1561
- };
1067
+ this.closeMessageEvent = e => this.closeMessage(e);
1562
1068
  }
1563
-
1564
- _createClass(GlobalAlert, [{
1565
- key: "init",
1566
- value: function init() {
1567
- this.controls();
1568
- }
1569
- }, {
1570
- key: "controls",
1571
- value: function controls() {
1572
- this.closeButton.addEventListener('click', this.closeMessageEvent, false);
1573
- }
1574
- }, {
1575
- key: "closeMessage",
1576
- value: function closeMessage() {
1577
- this.messageElement.hidden = true;
1578
- }
1579
- }]);
1580
-
1581
- return GlobalAlert;
1582
- }();
1069
+ init() {
1070
+ this.controls();
1071
+ }
1072
+ controls() {
1073
+ this.closeButton.addEventListener('click', this.closeMessageEvent, false);
1074
+ }
1075
+ closeMessage() {
1076
+ this.messageElement.hidden = true;
1077
+ }
1078
+ }
1583
1079
 
1584
1080
  /* eslint-disable max-len */
1585
- var Select = /*#__PURE__*/function () {
1586
- function Select(element) {
1587
- _classCallCheck(this, Select);
1588
-
1081
+ class Select {
1082
+ constructor(element) {
1589
1083
  this.element = element;
1590
1084
  this.select = this.element.querySelector('select');
1591
1085
  this.options = this.select.querySelectorAll('option');
@@ -1597,463 +1091,370 @@
1597
1091
  this.optionIndex = 0;
1598
1092
  this.textSelected = this.element.getAttribute('data-selection-text') || 'selected';
1599
1093
  }
1600
-
1601
- _createClass(Select, [{
1602
- key: "init",
1603
- value: function init() {
1604
- this.initCustomSelect();
1605
- this.initCustomSelectEvents();
1606
- }
1607
- }, {
1608
- key: "initCustomSelect",
1609
- value: function initCustomSelect() {
1610
- this.element.insertAdjacentHTML('beforeend', this.initButtonSelect() + this.initListSelect());
1611
- this.dropdown = this.element.querySelector('.nsw-multi-select__dropdown');
1612
- this.trigger = this.element.querySelector('.nsw-multi-select__button');
1613
- this.multiSelectList = this.dropdown.querySelector('.nsw-multi-select__list');
1614
- this.customOptions = this.multiSelectList.querySelectorAll('.nsw-multi-select__option');
1615
- this.multiSelectList.insertAdjacentHTML('afterbegin', this.initAllButton());
1616
- this.allButton = this.multiSelectList.querySelector('.js-multi-select-all');
1617
- this.allButtonInput = this.allButton.querySelector('.nsw-form__checkbox-input');
1618
- }
1619
- }, {
1620
- key: "initCustomSelectEvents",
1621
- value: function initCustomSelectEvents() {
1622
- var _this = this;
1623
-
1624
- this.initSelection();
1625
- this.trigger.addEventListener('click', function (event) {
1094
+ init() {
1095
+ this.initCustomSelect();
1096
+ this.initCustomSelectEvents();
1097
+ }
1098
+ initCustomSelect() {
1099
+ this.element.insertAdjacentHTML('beforeend', this.initButtonSelect() + this.initListSelect());
1100
+ this.dropdown = this.element.querySelector('.nsw-multi-select__dropdown');
1101
+ this.trigger = this.element.querySelector('.nsw-multi-select__button');
1102
+ this.multiSelectList = this.dropdown.querySelector('.nsw-multi-select__list');
1103
+ this.customOptions = this.multiSelectList.querySelectorAll('.nsw-multi-select__option');
1104
+ this.multiSelectList.insertAdjacentHTML('afterbegin', this.initAllButton());
1105
+ this.allButton = this.multiSelectList.querySelector('.js-multi-select-all');
1106
+ this.allButtonInput = this.allButton.querySelector('.nsw-form__checkbox-input');
1107
+ }
1108
+ initCustomSelectEvents() {
1109
+ this.initSelection();
1110
+ this.trigger.addEventListener('click', event => {
1111
+ event.preventDefault();
1112
+ this.toggleCustomSelect(false);
1113
+ });
1114
+ this.trigger.addEventListener('keydown', event => {
1115
+ if (event.code && event.code === 38 || event.key && event.key.toLowerCase() === 'arrowup' || event.code && event.code === 40 || event.key && event.key.toLowerCase() === 'arrowdown') {
1626
1116
  event.preventDefault();
1627
-
1628
- _this.toggleCustomSelect(false);
1629
- });
1630
- this.trigger.addEventListener('keydown', function (event) {
1631
- if (event.code && event.code === 38 || event.key && event.key.toLowerCase() === 'arrowup' || event.code && event.code === 40 || event.key && event.key.toLowerCase() === 'arrowdown') {
1632
- event.preventDefault();
1633
-
1634
- _this.toggleCustomSelect(false);
1635
- }
1636
- });
1637
- this.dropdown.addEventListener('keydown', function (event) {
1638
- if (event.code && event.code === 38 || event.key && event.key.toLowerCase() === 'arrowup') {
1639
- _this.keyboardCustomSelect('prev', event);
1640
- } else if (event.code && event.code === 40 || event.key && event.key.toLowerCase() === 'arrowdown') {
1641
- _this.keyboardCustomSelect('next', event);
1642
- }
1643
- });
1644
- window.addEventListener('keyup', function (event) {
1645
- if (event.key && event.key.toLowerCase() === 'escape') {
1646
- _this.constructor.moveFocusToSelectTrigger(event.target);
1647
-
1648
- _this.toggleCustomSelect('false');
1649
- }
1650
- });
1651
- window.addEventListener('click', function (event) {
1652
- _this.checkCustomSelectClick(event.target);
1653
- });
1654
- window.addEventListener('resize', this.placeDropdown);
1655
- this.allButton.addEventListener('change', function () {
1656
- _this.toggleAllOptions();
1657
- });
1658
- }
1659
- }, {
1660
- key: "toggleCustomSelect",
1661
- value: function toggleCustomSelect(bool) {
1662
- var ariaExpanded;
1663
-
1664
- if (bool) {
1665
- ariaExpanded = bool;
1666
- } else {
1667
- ariaExpanded = this.trigger.getAttribute('aria-expanded') === 'true' ? 'false' : 'true';
1117
+ this.toggleCustomSelect(false);
1668
1118
  }
1669
-
1670
- this.trigger.setAttribute('aria-expanded', ariaExpanded);
1671
-
1672
- if (ariaExpanded === 'true') {
1673
- var selectedOption = this.getSelectedOption();
1674
- this.constructor.moveFocus(selectedOption);
1675
- this.dropdown.addEventListener('transitionend', function cb() {
1676
- this.constructor.moveFocus(selectedOption);
1677
- this.dropdown.removeEventListener('transitionend', cb);
1678
- });
1679
- this.constructor.trapFocus(this.dropdown);
1680
- this.placeDropdown();
1119
+ });
1120
+ this.dropdown.addEventListener('keydown', event => {
1121
+ if (event.code && event.code === 38 || event.key && event.key.toLowerCase() === 'arrowup') {
1122
+ this.keyboardCustomSelect('prev', event);
1123
+ } else if (event.code && event.code === 40 || event.key && event.key.toLowerCase() === 'arrowdown') {
1124
+ this.keyboardCustomSelect('next', event);
1681
1125
  }
1682
- }
1683
- }, {
1684
- key: "placeDropdown",
1685
- value: function placeDropdown() {
1686
- var _this$trigger$getBoun = this.trigger.getBoundingClientRect(),
1687
- top = _this$trigger$getBoun.top,
1688
- bottom = _this$trigger$getBoun.bottom;
1689
-
1690
- var moveUp = window.innerHeight - bottom < top;
1691
- var maxHeight = moveUp ? top - 20 : window.innerHeight - bottom - 20;
1692
- var vhCalc = Math.ceil(100 * maxHeight / window.innerHeight);
1693
- this.dropdown.setAttribute('style', "max-height: ".concat(vhCalc, "vh;"));
1694
- }
1695
- }, {
1696
- key: "keyboardCustomSelect",
1697
- value: function keyboardCustomSelect(direction, event) {
1698
- event.preventDefault();
1699
- var allOptions = [].concat(_toConsumableArray(this.customOptions), [this.allButton]);
1700
- var index = Array.prototype.indexOf.call(allOptions, document.activeElement.closest('.nsw-multi-select__option'));
1701
- index = direction === 'next' ? index + 1 : index - 1;
1702
- if (index < 0) index = allOptions.length - 1;
1703
- if (index >= allOptions.length) index = 0;
1704
- this.constructor.moveFocus(allOptions[index].querySelector('.nsw-form__checkbox-input'));
1705
- }
1706
- }, {
1707
- key: "initSelection",
1708
- value: function initSelection() {
1709
- var _this2 = this;
1710
-
1711
- if (!this.dropdown) return;
1712
- this.customOptions.forEach(function (opt) {
1713
- opt.addEventListener('change', function (event) {
1714
- var option = event.currentTarget.closest('.nsw-multi-select__option');
1715
- if (!option) return;
1716
-
1717
- _this2.selectOption(option);
1718
- });
1719
- opt.addEventListener('click', function (event) {
1720
- var option = event.currentTarget.closest('.nsw-multi-select__option');
1721
- if (!option || !event.target.classList.contains('nsw-multi-select__option')) return;
1722
-
1723
- _this2.selectOption(option);
1724
- });
1725
- });
1726
- }
1727
- }, {
1728
- key: "getSelectedOptionCount",
1729
- value: function getSelectedOptionCount() {
1730
- var selectedOptCounter = 0;
1731
-
1732
- for (var i = 0; i < this.options.length; i += 1) {
1733
- if (this.options[i].selected) {
1734
- selectedOptCounter += 1;
1735
- }
1126
+ });
1127
+ window.addEventListener('keyup', event => {
1128
+ if (event.key && event.key.toLowerCase() === 'escape') {
1129
+ this.constructor.moveFocusToSelectTrigger(event.target);
1130
+ this.toggleCustomSelect('false');
1736
1131
  }
1737
-
1738
- return selectedOptCounter;
1132
+ });
1133
+ window.addEventListener('click', event => {
1134
+ this.checkCustomSelectClick(event.target);
1135
+ });
1136
+ window.addEventListener('resize', this.placeDropdown);
1137
+ this.allButton.addEventListener('change', () => {
1138
+ this.toggleAllOptions();
1139
+ });
1140
+ }
1141
+ toggleCustomSelect(bool) {
1142
+ let ariaExpanded;
1143
+ if (bool) {
1144
+ ariaExpanded = bool;
1145
+ } else {
1146
+ ariaExpanded = this.trigger.getAttribute('aria-expanded') === 'true' ? 'false' : 'true';
1147
+ }
1148
+ this.trigger.setAttribute('aria-expanded', ariaExpanded);
1149
+ if (ariaExpanded === 'true') {
1150
+ const selectedOption = this.getSelectedOption();
1151
+ this.constructor.moveFocus(selectedOption);
1152
+ this.dropdown.addEventListener('transitionend', function cb() {
1153
+ this.constructor.moveFocus(selectedOption);
1154
+ this.dropdown.removeEventListener('transitionend', cb);
1155
+ });
1156
+ this.constructor.trapFocus(this.dropdown);
1157
+ this.placeDropdown();
1739
1158
  }
1740
- }, {
1741
- key: "toggleAllOptions",
1742
- value: function toggleAllOptions() {
1743
- var _this3 = this;
1744
-
1745
- var count = this.getSelectedOptionCount();
1746
- this.customOptions.forEach(function (check) {
1747
- var input = check.querySelector('.nsw-form__checkbox-input');
1748
-
1749
- if (count === _this3.options.length) {
1750
- input.checked = false;
1751
- input.removeAttribute('checked');
1752
- check.setAttribute('aria-selected', 'false');
1753
-
1754
- _this3.updateNativeSelect(check.getAttribute('data-index'), false);
1755
- } else {
1756
- input.checked = true;
1757
- input.setAttribute('checked', '');
1758
- check.setAttribute('aria-selected', 'true');
1759
-
1760
- _this3.updateNativeSelect(check.getAttribute('data-index'), true);
1761
- } //
1762
-
1159
+ }
1160
+ placeDropdown() {
1161
+ const {
1162
+ top,
1163
+ bottom
1164
+ } = this.trigger.getBoundingClientRect();
1165
+ const moveUp = window.innerHeight - bottom < top;
1166
+ const maxHeight = moveUp ? top - 20 : window.innerHeight - bottom - 20;
1167
+ const vhCalc = Math.ceil(100 * maxHeight / window.innerHeight);
1168
+ this.dropdown.setAttribute('style', `max-height: ${vhCalc}vh;`);
1169
+ }
1170
+ keyboardCustomSelect(direction, event) {
1171
+ event.preventDefault();
1172
+ const allOptions = [...this.customOptions, this.allButton];
1173
+ let index = Array.prototype.indexOf.call(allOptions, document.activeElement.closest('.nsw-multi-select__option'));
1174
+ index = direction === 'next' ? index + 1 : index - 1;
1175
+ if (index < 0) index = allOptions.length - 1;
1176
+ if (index >= allOptions.length) index = 0;
1177
+ this.constructor.moveFocus(allOptions[index].querySelector('.nsw-form__checkbox-input'));
1178
+ }
1179
+ initSelection() {
1180
+ if (!this.dropdown) return;
1181
+ this.customOptions.forEach(opt => {
1182
+ opt.addEventListener('change', event => {
1183
+ const option = event.currentTarget.closest('.nsw-multi-select__option');
1184
+ if (!option) return;
1185
+ this.selectOption(option);
1763
1186
  });
1764
-
1765
- var _this$getSelectedOpti = this.getSelectedOptionText(),
1766
- _this$getSelectedOpti2 = _slicedToArray(_this$getSelectedOpti, 2),
1767
- label = _this$getSelectedOpti2[0],
1768
- ariaLabel = _this$getSelectedOpti2[1];
1769
-
1770
- this.trigger.querySelector('.nsw-multi-select__label').innerHTML = label;
1771
- this.constructor.toggleClass(this.trigger, 'active', count > 0);
1772
- this.updateTriggerAria(ariaLabel);
1187
+ opt.addEventListener('click', event => {
1188
+ const option = event.currentTarget.closest('.nsw-multi-select__option');
1189
+ if (!option || !event.target.classList.contains('nsw-multi-select__option')) return;
1190
+ this.selectOption(option);
1191
+ });
1192
+ });
1193
+ }
1194
+ getSelectedOptionCount() {
1195
+ let selectedOptCounter = 0;
1196
+ for (let i = 0; i < this.options.length; i += 1) {
1197
+ if (this.options[i].selected) {
1198
+ selectedOptCounter += 1;
1199
+ }
1773
1200
  }
1774
- }, {
1775
- key: "selectOption",
1776
- value: function selectOption(option) {
1777
- var input = option.querySelector('.nsw-form__checkbox-input');
1778
-
1779
- if (option.hasAttribute('aria-selected') && option.getAttribute('aria-selected') === 'true') {
1201
+ return selectedOptCounter;
1202
+ }
1203
+ toggleAllOptions() {
1204
+ const count = this.getSelectedOptionCount();
1205
+ this.customOptions.forEach(check => {
1206
+ const input = check.querySelector('.nsw-form__checkbox-input');
1207
+ if (count === this.options.length) {
1780
1208
  input.checked = false;
1781
1209
  input.removeAttribute('checked');
1782
- option.setAttribute('aria-selected', 'false');
1783
- this.updateNativeSelect(option.getAttribute('data-index'), false);
1210
+ check.setAttribute('aria-selected', 'false');
1211
+ this.updateNativeSelect(check.getAttribute('data-index'), false);
1784
1212
  } else {
1785
1213
  input.checked = true;
1786
- input.value = true;
1787
1214
  input.setAttribute('checked', '');
1788
- option.setAttribute('aria-selected', 'true');
1789
- this.updateNativeSelect(option.getAttribute('data-index'), true);
1790
- }
1791
-
1792
- var _this$getSelectedOpti3 = this.getSelectedOptionText(),
1793
- _this$getSelectedOpti4 = _slicedToArray(_this$getSelectedOpti3, 2),
1794
- label = _this$getSelectedOpti4[0],
1795
- ariaLabel = _this$getSelectedOpti4[1];
1796
-
1797
- var count = this.getSelectedOptionCount();
1798
-
1799
- if (count === this.options.length) {
1800
- this.allButtonInput.checked = true;
1801
- this.allButtonInput.setAttribute('checked', '');
1802
- this.allButton.setAttribute('aria-selected', 'true');
1803
- } else {
1804
- this.allButtonInput.checked = false;
1805
- this.allButtonInput.removeAttribute('checked');
1806
- this.allButton.setAttribute('aria-selected', 'false');
1807
- }
1808
-
1809
- this.trigger.querySelector('.nsw-multi-select__label').innerHTML = label;
1810
- this.constructor.toggleClass(this.trigger, 'active', count > 0);
1811
- this.updateTriggerAria(ariaLabel);
1812
- }
1813
- }, {
1814
- key: "initButtonSelect",
1815
- value: function initButtonSelect() {
1816
- var triggerLabel = this.getSelectedOptionText(this.element);
1817
- var button = "<button class=\"nsw-button nsw-multi-select__button\" aria-label=\"".concat(triggerLabel[1], "\" aria-expanded=\"false\" aria-controls=\"").concat(this.selectId, "-dropdown\">\n <span aria-hidden=\"true\" class=\"nsw-multi-select__label\">").concat(triggerLabel[0], "</span>\n <span class=\"material-icons nsw-material-icons\" focusable=\"false\" aria-hidden=\"true\">keyboard_arrow_down</span>\n </button>");
1818
- return button;
1819
- }
1820
- }, {
1821
- key: "initAllButton",
1822
- value: function initAllButton() {
1823
- var all = this.getSelectedOptionCount() === this.options.length;
1824
- var selected = all ? ' aria-selected="true"' : ' aria-selected="false"';
1825
- var checked = all ? 'checked' : '';
1826
- var allButton = "\n <li class=\"js-multi-select-all nsw-multi-select__option\" role=\"option\" data-value=\"Select all\" aria-selected=\"false\" ".concat(selected, " data-label=\"Select all\">\n <input aria-hidden=\"true\" class=\"nsw-form__checkbox-input\" type=\"checkbox\" id=\"").concat(this.selectId, "-all\" ").concat(checked, ">\n <label class=\"nsw-form__checkbox-label\" aria-hidden=\"true\" for=\"").concat(this.selectId, "-all\">\n <span>Select all</span>\n </label>\n </li>");
1827
- return allButton;
1828
- }
1829
- }, {
1830
- key: "getSelectedOptionText",
1831
- value: function getSelectedOptionText() {
1832
- var noSelectionText = '<span class="multi-select__term">Please select</span>';
1833
- var label = '';
1834
- var ariaLabel = '';
1835
- var count = this.getSelectedOptionCount();
1836
-
1837
- if (count === this.options.length) {
1838
- label = "All ".concat(this.textSelected);
1839
- ariaLabel = "All ".concat(this.textSelected);
1840
- } else if (count > 1) {
1841
- label = "".concat(count, " ").concat(this.textSelected);
1842
- ariaLabel = "".concat(count, " ").concat(this.textSelected, ", Please select");
1843
- } else if (count > 0) {
1844
- ariaLabel += "".concat(this.options[0].text, ", Please select");
1845
- label = this.options[0].text;
1846
- } else {
1847
- label = noSelectionText;
1848
- ariaLabel = 'Please select';
1849
- }
1850
-
1851
- return [label, ariaLabel];
1852
- }
1853
- }, {
1854
- key: "initListSelect",
1855
- value: function initListSelect() {
1856
- var _this4 = this;
1857
-
1858
- var list = "<div class=\"nsw-multi-select__dropdown\" aria-describedby=".concat(this.selectId, "-description\" id=\"").concat(this.selectId, "-dropdown\">");
1859
-
1860
- if (this.optGroups.length > 0) {
1861
- this.optGroups.forEach(function (optionGroup) {
1862
- var optGroupList = optionGroup.querySelectorAll('option');
1863
- var optGroupLabel = "<li><span>".concat(optionGroup.getAttribute('label'), "</span></li>");
1864
- list += "<ul class=\"nsw-multi-select__list\" role=\"listbox\" aria-multiselectable=\"true\">\n ".concat(optGroupLabel + _this4.getOptionsList(optGroupList), "\n </ul>");
1865
- });
1866
- } else {
1867
- list += "<ul class=\"nsw-multi-select__list\" role=\"listbox\" aria-multiselectable=\"true\">".concat(this.getOptionsList(this.options), "</ul>");
1215
+ check.setAttribute('aria-selected', 'true');
1216
+ this.updateNativeSelect(check.getAttribute('data-index'), true);
1868
1217
  }
1218
+ //
1219
+ });
1869
1220
 
1870
- return list;
1871
- }
1872
- }, {
1873
- key: "getOptionsList",
1874
- value: function getOptionsList(options) {
1875
- var _this5 = this;
1876
-
1877
- var list = '';
1878
- options.forEach(function (option) {
1879
- var selected = option.hasAttribute('selected') ? ' aria-selected="true"' : ' aria-selected="false"';
1880
- var checked = option.hasAttribute('selected') ? 'checked' : '';
1881
-
1882
- var uniqueName = _this5.constructor.createSafeCssClassname("".concat(_this5.selectId, "-").concat(option.value, "-").concat(_this5.optionIndex.toString()));
1883
-
1884
- list += "\n <li class=\"nsw-multi-select__option\" role=\"option\" data-value=\"".concat(option.value, "\" ").concat(selected, " data-label=\"").concat(option.text, "\" data-index=\"").concat(_this5.optionIndex, "\">\n <input aria-hidden=\"true\" class=\"nsw-form__checkbox-input\" type=\"checkbox\" id=\"").concat(uniqueName, "\" ").concat(checked, ">\n <label class=\"nsw-form__checkbox-label\" aria-hidden=\"true\" for=\"").concat(uniqueName, "\">\n <span>").concat(option.text, "</span>\n </label>\n </li>");
1885
- _this5.optionIndex += 1;
1221
+ const [label, ariaLabel] = this.getSelectedOptionText();
1222
+ this.trigger.querySelector('.nsw-multi-select__label').innerHTML = label;
1223
+ this.constructor.toggleClass(this.trigger, 'active', count > 0);
1224
+ this.updateTriggerAria(ariaLabel);
1225
+ }
1226
+ selectOption(option) {
1227
+ const input = option.querySelector('.nsw-form__checkbox-input');
1228
+ if (option.hasAttribute('aria-selected') && option.getAttribute('aria-selected') === 'true') {
1229
+ input.checked = false;
1230
+ input.removeAttribute('checked');
1231
+ option.setAttribute('aria-selected', 'false');
1232
+ this.updateNativeSelect(option.getAttribute('data-index'), false);
1233
+ } else {
1234
+ input.checked = true;
1235
+ input.value = true;
1236
+ input.setAttribute('checked', '');
1237
+ option.setAttribute('aria-selected', 'true');
1238
+ this.updateNativeSelect(option.getAttribute('data-index'), true);
1239
+ }
1240
+ const [label, ariaLabel] = this.getSelectedOptionText();
1241
+ const count = this.getSelectedOptionCount();
1242
+ if (count === this.options.length) {
1243
+ this.allButtonInput.checked = true;
1244
+ this.allButtonInput.setAttribute('checked', '');
1245
+ this.allButton.setAttribute('aria-selected', 'true');
1246
+ } else {
1247
+ this.allButtonInput.checked = false;
1248
+ this.allButtonInput.removeAttribute('checked');
1249
+ this.allButton.setAttribute('aria-selected', 'false');
1250
+ }
1251
+ this.trigger.querySelector('.nsw-multi-select__label').innerHTML = label;
1252
+ this.constructor.toggleClass(this.trigger, 'active', count > 0);
1253
+ this.updateTriggerAria(ariaLabel);
1254
+ }
1255
+ initButtonSelect() {
1256
+ const triggerLabel = this.getSelectedOptionText(this.element);
1257
+ const button = `<button class="nsw-button nsw-multi-select__button" aria-label="${triggerLabel[1]}" aria-expanded="false" aria-controls="${this.selectId}-dropdown">
1258
+ <span aria-hidden="true" class="nsw-multi-select__label">${triggerLabel[0]}</span>
1259
+ <span class="material-icons nsw-material-icons" focusable="false" aria-hidden="true">keyboard_arrow_down</span>
1260
+ </button>`;
1261
+ return button;
1262
+ }
1263
+ initAllButton() {
1264
+ const all = this.getSelectedOptionCount() === this.options.length;
1265
+ const selected = all ? ' aria-selected="true"' : ' aria-selected="false"';
1266
+ const checked = all ? 'checked' : '';
1267
+ const allButton = `
1268
+ <li class="js-multi-select-all nsw-multi-select__option" role="option" data-value="Select all" aria-selected="false" ${selected} data-label="Select all">
1269
+ <input aria-hidden="true" class="nsw-form__checkbox-input" type="checkbox" id="${this.selectId}-all" ${checked}>
1270
+ <label class="nsw-form__checkbox-label" aria-hidden="true" for="${this.selectId}-all">
1271
+ <span>Select all</span>
1272
+ </label>
1273
+ </li>`;
1274
+ return allButton;
1275
+ }
1276
+ getSelectedOptionText() {
1277
+ const noSelectionText = '<span class="multi-select__term">Please select</span>';
1278
+ let label = '';
1279
+ let ariaLabel = '';
1280
+ const count = this.getSelectedOptionCount();
1281
+ if (count === this.options.length) {
1282
+ label = `All ${this.textSelected}`;
1283
+ ariaLabel = `All ${this.textSelected}`;
1284
+ } else if (count > 1) {
1285
+ label = `${count} ${this.textSelected}`;
1286
+ ariaLabel = `${count} ${this.textSelected}, Please select`;
1287
+ } else if (count > 0) {
1288
+ ariaLabel += `${this.options[0].text}, Please select`;
1289
+ label = this.options[0].text;
1290
+ } else {
1291
+ label = noSelectionText;
1292
+ ariaLabel = 'Please select';
1293
+ }
1294
+ return [label, ariaLabel];
1295
+ }
1296
+ initListSelect() {
1297
+ let list = `<div class="nsw-multi-select__dropdown" aria-describedby=${this.selectId}-description" id="${this.selectId}-dropdown">`;
1298
+ if (this.optGroups.length > 0) {
1299
+ this.optGroups.forEach(optionGroup => {
1300
+ const optGroupList = optionGroup.querySelectorAll('option');
1301
+ const optGroupLabel = `<li><span>${optionGroup.getAttribute('label')}</span></li>`;
1302
+ list += `<ul class="nsw-multi-select__list" role="listbox" aria-multiselectable="true">
1303
+ ${optGroupLabel + this.getOptionsList(optGroupList)}
1304
+ </ul>`;
1886
1305
  });
1887
- return list;
1888
- }
1889
- }, {
1890
- key: "getSelectedOption",
1891
- value: function getSelectedOption() {
1892
- var option = this.dropdown.querySelector('[aria-selected="true"]');
1893
-
1894
- if (option) {
1895
- return option.querySelector('.nsw-form__checkbox-input');
1896
- }
1897
-
1898
- return this.dropdown.querySelector('.nsw-multi-select__option').querySelector('.nsw-form__checkbox-input');
1306
+ } else {
1307
+ list += `<ul class="nsw-multi-select__list" role="listbox" aria-multiselectable="true">${this.getOptionsList(this.options)}</ul>`;
1899
1308
  }
1900
- }, {
1901
- key: "checkCustomSelectClick",
1902
- value: function checkCustomSelectClick(target) {
1903
- if (!this.element.contains(target)) this.toggleCustomSelect('false');
1904
- }
1905
- }, {
1906
- key: "updateNativeSelect",
1907
- value: function updateNativeSelect(index, bool) {
1908
- this.options[index].selected = bool;
1909
- this.select.dispatchEvent(new CustomEvent('update', {
1910
- bubbles: true
1911
- }));
1309
+ return list;
1310
+ }
1311
+ getOptionsList(options) {
1312
+ let list = '';
1313
+ options.forEach(option => {
1314
+ const selected = option.hasAttribute('selected') ? ' aria-selected="true"' : ' aria-selected="false"';
1315
+ const checked = option.hasAttribute('selected') ? 'checked' : '';
1316
+ const uniqueName = this.constructor.createSafeCssClassname(`${this.selectId}-${option.value}-${this.optionIndex.toString()}`);
1317
+ list += `
1318
+ <li class="nsw-multi-select__option" role="option" data-value="${option.value}" ${selected} data-label="${option.text}" data-index="${this.optionIndex}">
1319
+ <input aria-hidden="true" class="nsw-form__checkbox-input" type="checkbox" id="${uniqueName}" ${checked}>
1320
+ <label class="nsw-form__checkbox-label" aria-hidden="true" for="${uniqueName}">
1321
+ <span>${option.text}</span>
1322
+ </label>
1323
+ </li>`;
1324
+ this.optionIndex += 1;
1325
+ });
1326
+ return list;
1327
+ }
1328
+ getSelectedOption() {
1329
+ const option = this.dropdown.querySelector('[aria-selected="true"]');
1330
+ if (option) {
1331
+ return option.querySelector('.nsw-form__checkbox-input');
1912
1332
  }
1913
- }, {
1914
- key: "updateTriggerAria",
1915
- value: function updateTriggerAria(ariaLabel) {
1916
- this.trigger.setAttribute('aria-label', ariaLabel);
1333
+ return this.dropdown.querySelector('.nsw-multi-select__option').querySelector('.nsw-form__checkbox-input');
1334
+ }
1335
+ checkCustomSelectClick(target) {
1336
+ if (!this.element.contains(target)) this.toggleCustomSelect('false');
1337
+ }
1338
+ updateNativeSelect(index, bool) {
1339
+ this.options[index].selected = bool;
1340
+ this.select.dispatchEvent(new CustomEvent('update', {
1341
+ bubbles: true
1342
+ }));
1343
+ }
1344
+ updateTriggerAria(ariaLabel) {
1345
+ this.trigger.setAttribute('aria-label', ariaLabel);
1346
+ }
1347
+ static createSafeCssClassname(str) {
1348
+ const invalidBeginningOfClassname = /^([0-9]|--|-[0-9])/;
1349
+ if (typeof str !== 'string') {
1350
+ return '';
1917
1351
  }
1918
- }], [{
1919
- key: "createSafeCssClassname",
1920
- value: function createSafeCssClassname(str) {
1921
- var invalidBeginningOfClassname = /^([0-9]|--|-[0-9])/;
1922
-
1923
- if (typeof str !== 'string') {
1924
- return '';
1352
+ const strippedClassname = str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(x => x.toLowerCase()).join('-');
1353
+ return invalidBeginningOfClassname.test(strippedClassname) ? `_${strippedClassname}` : strippedClassname;
1354
+ }
1355
+ static moveFocusToSelectTrigger(target) {
1356
+ const multiSelect = target.closest('.js-multi-select');
1357
+ if (!multiSelect) return;
1358
+ multiSelect.querySelector('.nsw-multi-select__button').focus();
1359
+ }
1360
+ static trapFocus(element) {
1361
+ const focusableElements = 'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])';
1362
+ const firstFocusableElement = element.querySelectorAll(focusableElements)[0];
1363
+ const focusableContent = element.querySelectorAll(focusableElements);
1364
+ const lastFocusableElement = focusableContent[focusableContent.length - 1];
1365
+ document.addEventListener('keydown', event => {
1366
+ const isTabPressed = event.key === 'Tab' || event.code === 9;
1367
+ if (!isTabPressed) {
1368
+ return;
1925
1369
  }
1926
-
1927
- var strippedClassname = str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(function (x) {
1928
- return x.toLowerCase();
1929
- }).join('-');
1930
- return invalidBeginningOfClassname.test(strippedClassname) ? "_".concat(strippedClassname) : strippedClassname;
1931
- }
1932
- }, {
1933
- key: "moveFocusToSelectTrigger",
1934
- value: function moveFocusToSelectTrigger(target) {
1935
- var multiSelect = target.closest('.js-multi-select');
1936
- if (!multiSelect) return;
1937
- multiSelect.querySelector('.nsw-multi-select__button').focus();
1938
- }
1939
- }, {
1940
- key: "trapFocus",
1941
- value: function trapFocus(element) {
1942
- var focusableElements = 'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])';
1943
- var firstFocusableElement = element.querySelectorAll(focusableElements)[0];
1944
- var focusableContent = element.querySelectorAll(focusableElements);
1945
- var lastFocusableElement = focusableContent[focusableContent.length - 1];
1946
- document.addEventListener('keydown', function (event) {
1947
- var isTabPressed = event.key === 'Tab' || event.code === 9;
1948
-
1949
- if (!isTabPressed) {
1950
- return;
1951
- }
1952
-
1953
- if (event.shiftKey) {
1954
- if (document.activeElement === firstFocusableElement) {
1955
- lastFocusableElement.focus();
1956
- event.preventDefault();
1957
- }
1958
- } else if (document.activeElement === lastFocusableElement) {
1959
- firstFocusableElement.focus();
1370
+ if (event.shiftKey) {
1371
+ if (document.activeElement === firstFocusableElement) {
1372
+ lastFocusableElement.focus();
1960
1373
  event.preventDefault();
1961
1374
  }
1962
- });
1963
- firstFocusableElement.focus();
1964
- }
1965
- }, {
1966
- key: "moveFocus",
1967
- value: function moveFocus(element) {
1968
- if (document.activeElement !== element) {
1969
- element.focus();
1375
+ } else if (document.activeElement === lastFocusableElement) {
1376
+ firstFocusableElement.focus();
1377
+ event.preventDefault();
1970
1378
  }
1379
+ });
1380
+ firstFocusableElement.focus();
1381
+ }
1382
+ static moveFocus(element) {
1383
+ if (document.activeElement !== element) {
1384
+ element.focus();
1971
1385
  }
1972
- }, {
1973
- key: "toggleClass",
1974
- value: function toggleClass(el, className, bool) {
1975
- if (bool) el.classList.add(className);else el.classList.remove(className);
1976
- }
1977
- }]);
1978
-
1979
- return Select;
1980
- }();
1386
+ }
1387
+ static toggleClass(el, className, bool) {
1388
+ if (bool) el.classList.add(className);else el.classList.remove(className);
1389
+ }
1390
+ }
1981
1391
 
1982
1392
  if (window.NodeList && !NodeList.prototype.forEach) {
1983
1393
  NodeList.prototype.forEach = Array.prototype.forEach;
1984
1394
  }
1985
-
1986
1395
  if (!Element.prototype.closest) {
1987
1396
  if (!Element.prototype.matches) {
1988
1397
  Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
1989
1398
  }
1990
-
1991
1399
  Element.prototype.closest = function closest(s) {
1992
- var el = this;
1993
- var ancestor = this;
1400
+ const el = this;
1401
+ let ancestor = this;
1994
1402
  if (!document.documentElement.contains(el)) return null;
1995
-
1996
1403
  do {
1997
1404
  if (ancestor.matches(s)) return ancestor;
1998
1405
  ancestor = ancestor.parentElement;
1999
1406
  } while (ancestor !== null);
2000
-
2001
1407
  return null;
2002
1408
  };
2003
1409
  }
2004
-
2005
1410
  function initSite() {
2006
1411
  // Header Search
2007
- var openSearchButton = document.querySelectorAll('.js-open-search');
2008
- var closeSearchButton = document.querySelectorAll('.js-close-search');
2009
- var accordions = document.querySelectorAll('.js-accordion');
2010
- var dialogs = document.querySelectorAll('.js-dialog');
2011
- var fileUpload = document.querySelectorAll('.js-file-upload');
2012
- var filters = document.querySelectorAll('.js-filters');
2013
- var tabs = document.querySelectorAll('.js-tabs');
2014
- var globalAlert = document.querySelectorAll('.js-global-alert');
2015
- var multiSelect = document.querySelectorAll('.js-multi-select');
2016
- openSearchButton.forEach(function (element) {
1412
+ const openSearchButton = document.querySelectorAll('.js-open-search');
1413
+ const closeSearchButton = document.querySelectorAll('.js-close-search');
1414
+ const accordions = document.querySelectorAll('.js-accordion');
1415
+ const dialogs = document.querySelectorAll('.js-dialog');
1416
+ const fileUpload = document.querySelectorAll('.js-file-upload');
1417
+ const filters = document.querySelectorAll('.js-filters');
1418
+ const tabs = document.querySelectorAll('.js-tabs');
1419
+ const globalAlert = document.querySelectorAll('.js-global-alert');
1420
+ const multiSelect = document.querySelectorAll('.js-multi-select');
1421
+ openSearchButton.forEach(element => {
2017
1422
  new SiteSearch(element).init();
2018
1423
  });
2019
- closeSearchButton.forEach(function (element) {
1424
+ closeSearchButton.forEach(element => {
2020
1425
  new SiteSearch(element).init();
2021
- }); // Navigation
1426
+ });
2022
1427
 
1428
+ // Navigation
2023
1429
  new Navigation().init();
2024
- accordions.forEach(function (element) {
1430
+ accordions.forEach(element => {
2025
1431
  new Accordion(element).init();
2026
1432
  });
2027
- dialogs.forEach(function (element) {
1433
+ dialogs.forEach(element => {
2028
1434
  new Dialog(element).init();
2029
1435
  });
2030
-
2031
1436
  if (fileUpload) {
2032
- fileUpload.forEach(function (element) {
1437
+ fileUpload.forEach(element => {
2033
1438
  new FileUpload(element).init();
2034
1439
  });
2035
1440
  }
2036
-
2037
1441
  if (filters) {
2038
- filters.forEach(function (element) {
1442
+ filters.forEach(element => {
2039
1443
  new Filters(element).init();
2040
1444
  });
2041
1445
  }
2042
-
2043
1446
  if (tabs) {
2044
- tabs.forEach(function (element) {
1447
+ tabs.forEach(element => {
2045
1448
  new Tabs(element).init();
2046
1449
  });
2047
1450
  }
2048
-
2049
1451
  if (globalAlert) {
2050
- globalAlert.forEach(function (element) {
1452
+ globalAlert.forEach(element => {
2051
1453
  new GlobalAlert(element).init();
2052
1454
  });
2053
1455
  }
2054
-
2055
1456
  if (multiSelect) {
2056
- multiSelect.forEach(function (element) {
1457
+ multiSelect.forEach(element => {
2057
1458
  new Select(element).init();
2058
1459
  });
2059
1460
  }
@@ -2070,6 +1471,4 @@
2070
1471
  exports.Tabs = Tabs;
2071
1472
  exports.initSite = initSite;
2072
1473
 
2073
- Object.defineProperty(exports, '__esModule', { value: true });
2074
-
2075
- })));
1474
+ }));