@internetstiftelsen/styleguide 5.0.19 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +71 -0
- package/dist/assets/js/Events.js +43 -77
- package/dist/assets/js/RequestError.js +16 -31
- package/dist/assets/js/anchorScroll.js +22 -15
- package/dist/assets/js/charCounter.js +100 -142
- package/dist/assets/js/className.js +19 -20
- package/dist/assets/js/conditional.js +96 -152
- package/dist/assets/js/debounce.js +15 -22
- package/dist/assets/js/el.js +108 -159
- package/dist/assets/js/getCookieByName.js +13 -11
- package/dist/assets/js/hasCookieConsent.js +30 -40
- package/dist/assets/js/htmlTextLength.js +12 -10
- package/dist/assets/js/iconToggle.js +16 -20
- package/dist/assets/js/nodeAdded.js +40 -53
- package/dist/assets/js/objToQuery.js +25 -41
- package/dist/assets/js/offset.js +29 -25
- package/dist/assets/js/ot.js +10 -13
- package/dist/assets/js/parallax.js +23 -23
- package/dist/assets/js/queryToObj.js +16 -22
- package/dist/assets/js/readSpeakerHandling.js +26 -28
- package/dist/assets/js/request.js +43 -52
- package/dist/assets/js/responsivePosition.js +46 -74
- package/dist/assets/js/stringToNode.js +11 -10
- package/dist/assets/js/template.js +15 -21
- package/dist/assets/js/textToggle.js +19 -24
- package/dist/assets/js/track.js +14 -12
- package/dist/assets/js/uid.js +10 -6
- package/dist/assets/js/utmGenerator.js +27 -33
- package/dist/assets/js/validationMessage.js +18 -25
- package/dist/assets/js/youtube.js +134 -170
- package/dist/atoms/button/Button.js +42 -55
- package/dist/atoms/file/file.js +25 -29
- package/dist/atoms/file/filePreview.js +27 -31
- package/dist/atoms/grid-toggle/grid-toggle.js +6 -9
- package/dist/atoms/height-limiter/height-limiter.js +37 -50
- package/dist/atoms/password-toggle/password-toggle.js +9 -11
- package/dist/atoms/range/range.js +32 -39
- package/dist/atoms/textarea/rich-text.js +221 -251
- package/dist/atoms/tooltip/tooltip.js +13 -17
- package/dist/components.js +42 -77
- package/dist/focusTrap.js +66 -77
- package/dist/molecules/alert/alert.js +15 -20
- package/dist/molecules/context-menu/context-menu.js +11 -16
- package/dist/molecules/continue-video-guide/continue-video-guide.js +90 -101
- package/dist/molecules/cookie-disclaimer/cookie-disclaimer.js +24 -33
- package/dist/molecules/form/Form.js +242 -352
- package/dist/molecules/form/index.js +15 -14
- package/dist/molecules/glider/glider-course.js +62 -75
- package/dist/molecules/glider/glider-hero.js +88 -101
- package/dist/molecules/glider/glider.js +49 -45
- package/dist/molecules/modal/modal.js +256 -325
- package/dist/molecules/multi-select/multi-select.js +198 -304
- package/dist/molecules/natural-language-form/natural-language-form.js +32 -46
- package/dist/molecules/overview-navigation/overview-navigation.js +90 -141
- package/dist/molecules/share/share.js +15 -20
- package/dist/molecules/system-error/system-error.js +6 -9
- package/dist/organisms/accordion/accordion.js +44 -50
- package/dist/organisms/footer/footer.js +1 -1
- package/dist/organisms/haveibeenpwned/haveibeenpwned.js +17 -16
- package/dist/organisms/mailchimp/mailchimp.js +72 -89
- package/dist/organisms/map-box/map-box.js +3 -4
- package/dist/organisms/mega-menu/mega-menu.js +177 -212
- package/dist/organisms/podcast/podcast.js +192 -215
- package/dist/organisms/schedule/schedule-filter.js +9 -15
- package/dist/organisms/tabs/tabs.js +194 -253
- package/dist/organisms/timeline/openTimelineItem.js +38 -51
- package/dist/organisms/timeline/timeline.js +111 -128
- package/dist/organisms/video-guide/VideoGuidePlayback.js +210 -286
- package/dist/organisms/video-guide/VideoGuideSubtitles.js +57 -80
- package/dist/organisms/video-guide/VideoGuideTimeline.js +74 -108
- package/dist/organisms/video-guide/getCurrentCueIndex.js +11 -9
- package/dist/organisms/video-guide/video-guide.js +66 -103
- package/dist/utilities/tab-highlighting/tab-highlighting.js +14 -22
- package/dist/vendor/toggle/a11y.toggle-switcher.js +10 -16
- package/package.json +78 -99
- package/src/app.js +5 -5
- package/src/assets/js/anchorScroll.js +1 -1
- package/src/assets/js/offset.js +1 -1
- package/src/atoms/button/Button.js +1 -1
- package/src/atoms/icon/richtext-ordered-list.svg +1 -1
- package/src/atoms/icon/sprite.svg +6 -5
- package/src/molecules/glider/glider-course.js +0 -2
- package/src/molecules/glider/glider.js +2 -2
- package/src/organisms/accordion/accordion.js +1 -2
- package/src/organisms/timeline/timeline.js +2 -3
- package/dist/atoms/timeline/anchorScroll.js +0 -13
- package/dist/atoms/toggle-high-contrast/toggle-high-contrast.js +0 -12
- package/dist/molecules/glider/glider-single.js +0 -68
- package/dist/molecules/modal/modal-graph.js +0 -40
- package/dist/molecules/timeline-navigation/timeline-navigation.js +0 -34
- /package/src/atoms/icon/{heading-3.svg → richtext-heading-3.svg} +0 -0
- /package/src/molecules/alert/{_alert.scss → alert.scss} +0 -0
|
@@ -1,305 +1,199 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.input.focus();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
this.selectedItems = this.selectedItems.filter(function (i) {
|
|
199
|
-
return i.value !== item.value;
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
var itemInput = this.element.querySelector('input[value="' + item.value + '"]');
|
|
203
|
-
itemInput.remove();
|
|
204
|
-
}
|
|
205
|
-
}, {
|
|
206
|
-
key: 'addItem',
|
|
207
|
-
value: function addItem(item) {
|
|
208
|
-
var _this4 = this;
|
|
209
|
-
|
|
210
|
-
var save = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
211
|
-
|
|
212
|
-
if (!item) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
var newItem = document.createElement('li');
|
|
217
|
-
newItem.textContent = item.name + ' ';
|
|
218
|
-
newItem.setAttribute('data-value', item.value);
|
|
219
|
-
newItem.classList.add((0, _className2.default)('a-tag'));
|
|
220
|
-
newItem.classList.add((0, _className2.default)(this.baseClassName + '__tag'));
|
|
221
|
-
|
|
222
|
-
var removeBtn = document.createElement('button');
|
|
223
|
-
removeBtn.classList.add((0, _className2.default)(this.baseClassName + '-selected-items__remove-btn'));
|
|
224
|
-
|
|
225
|
-
var buttonTextContainer = document.createElement('span');
|
|
226
|
-
buttonTextContainer.classList.add('u-visuallyhidden');
|
|
227
|
-
removeBtn.appendChild(buttonTextContainer);
|
|
228
|
-
buttonTextContainer.textContent = 'Ta bort ' + item.name; // Accessibility label for screen readers
|
|
229
|
-
|
|
230
|
-
// Event listener for removing the selected item
|
|
231
|
-
removeBtn.addEventListener('click', function () {
|
|
232
|
-
_this4.removeItem(item);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
newItem.appendChild(removeBtn);
|
|
236
|
-
|
|
237
|
-
this.selectedItemsList.appendChild(newItem);
|
|
238
|
-
this.selectedItems.push(item);
|
|
239
|
-
|
|
240
|
-
if (save) {
|
|
241
|
-
var itemInput = document.createElement('input');
|
|
242
|
-
|
|
243
|
-
itemInput.type = 'hidden';
|
|
244
|
-
itemInput.name = this.name + '[]';
|
|
245
|
-
itemInput.value = item.value;
|
|
246
|
-
|
|
247
|
-
this.element.appendChild(itemInput);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}, {
|
|
251
|
-
key: 'removeHighlight',
|
|
252
|
-
value: function removeHighlight() {
|
|
253
|
-
var items = this.suggestionsBox.getElementsByClassName((0, _className2.default)(this.baseClassName + '__suggestion-btn'));
|
|
254
|
-
|
|
255
|
-
[].forEach.call(items, function (item) {
|
|
256
|
-
item.classList.remove('autocomplete-active');
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}, {
|
|
260
|
-
key: 'highlight',
|
|
261
|
-
value: function highlight(direction) {
|
|
262
|
-
var items = this.suggestionsBox.getElementsByClassName((0, _className2.default)(this.baseClassName + '__suggestion-btn'));
|
|
263
|
-
var focus = this.currentFocus;
|
|
264
|
-
|
|
265
|
-
if (direction === 'down') {
|
|
266
|
-
focus = focus >= items.length - 1 ? 0 : focus + 1;
|
|
267
|
-
} else {
|
|
268
|
-
focus = focus <= 0 ? items.length - 1 : focus - 1;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
this.setFocus(focus);
|
|
272
|
-
this.removeHighlight();
|
|
273
|
-
|
|
274
|
-
items[this.currentFocus].classList.add('autocomplete-active');
|
|
275
|
-
items[this.currentFocus].scrollIntoView({ block: 'nearest' });
|
|
276
|
-
}
|
|
277
|
-
}, {
|
|
278
|
-
key: 'selectHighlighted',
|
|
279
|
-
value: function selectHighlighted() {
|
|
280
|
-
var items = this.suggestionsBox.getElementsByClassName((0, _className2.default)(this.baseClassName + '__suggestion-btn'));
|
|
281
|
-
|
|
282
|
-
if (this.currentFocus > -1 && items[this.currentFocus]) {
|
|
283
|
-
var item = items[this.currentFocus];
|
|
284
|
-
|
|
285
|
-
this.addItem(this.data.find(function (d) {
|
|
286
|
-
return d.value === item.value;
|
|
287
|
-
}));
|
|
288
|
-
|
|
289
|
-
this.clearSuggestions();
|
|
290
|
-
this.input.value = '';
|
|
291
|
-
this.resetFocus();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}]);
|
|
295
|
-
|
|
296
|
-
return MultiSelect;
|
|
297
|
-
}();
|
|
298
|
-
|
|
299
|
-
var multiSelectElements = document.querySelectorAll('.js-m-multi-select');
|
|
300
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _className = /*#__PURE__*/ _interop_require_default(require("../../assets/js/className"));
|
|
6
|
+
function _interop_require_default(obj) {
|
|
7
|
+
return obj && obj.__esModule ? obj : {
|
|
8
|
+
default: obj
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
class MultiSelect {
|
|
12
|
+
getData() {
|
|
13
|
+
const id = this.input.getAttribute('data-multi-select-suggestions');
|
|
14
|
+
const el = document.getElementById(id);
|
|
15
|
+
if (!el) {
|
|
16
|
+
this.data = [];
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.data = JSON.parse(el.textContent);
|
|
20
|
+
}
|
|
21
|
+
attach() {
|
|
22
|
+
this.input.addEventListener('input', this.onInput);
|
|
23
|
+
this.input.addEventListener('keydown', this.onKeyDown);
|
|
24
|
+
this.suggestionsBox.addEventListener('click', this.onClick);
|
|
25
|
+
}
|
|
26
|
+
setFocus(index) {
|
|
27
|
+
this.currentFocus = index;
|
|
28
|
+
}
|
|
29
|
+
resetFocus() {
|
|
30
|
+
this.setFocus(-1);
|
|
31
|
+
}
|
|
32
|
+
clearSuggestions() {
|
|
33
|
+
this.input.setAttribute('aria-expanded', 'false');
|
|
34
|
+
this.suggestionsBox.innerHTML = '';
|
|
35
|
+
}
|
|
36
|
+
addSuggestions(suggestions) {
|
|
37
|
+
this.data = [
|
|
38
|
+
...this.data,
|
|
39
|
+
...suggestions.filter((s)=>!this.data.find((d)=>d.value === s.value))
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
sync() {
|
|
43
|
+
const inputs = this.element.querySelectorAll(`input[name="${this.name}[]"]`);
|
|
44
|
+
this.selectedItems = [];
|
|
45
|
+
inputs.forEach((input)=>{
|
|
46
|
+
const item = this.data.find((d)=>d.value === input.value);
|
|
47
|
+
if (item) {
|
|
48
|
+
this.addItem(item, false);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
filterData(query) {
|
|
53
|
+
const selectedValues = this.selectedItems.map((item)=>item.value);
|
|
54
|
+
return this.data.filter((item)=>item.name.toLowerCase().startsWith(query.toLowerCase())).filter((item)=>!selectedValues.includes(item.value));
|
|
55
|
+
}
|
|
56
|
+
populateSuggestions(suggestions) {
|
|
57
|
+
const cls = (0, _className.default)(`${this.baseClassName}__suggestion-btn`);
|
|
58
|
+
this.suggestionsBox.innerHTML = suggestions.map((item)=>`<button class='${cls}' tabindex='0' value="${item.value}">${item.name}</button>`).join('');
|
|
59
|
+
if (this.suggestionsBox.innerHTML) {
|
|
60
|
+
this.input.setAttribute('aria-expanded', 'true');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
removeItem(item) {
|
|
64
|
+
const node = this.element.querySelector(`.js-m-multi-select-selected-items li[data-value="${item.value}"]`);
|
|
65
|
+
if (!node) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const parent = node.closest('.js-m-multi-select-selected-items');
|
|
69
|
+
const index = Array.prototype.indexOf.call(parent.children, node);
|
|
70
|
+
node.remove();
|
|
71
|
+
const remainingItems = parent.getElementsByTagName('li');
|
|
72
|
+
// Focus management: set focus to the next item, or the search input if no items left
|
|
73
|
+
if (remainingItems.length > 0) {
|
|
74
|
+
if (index < remainingItems.length) {
|
|
75
|
+
remainingItems[index].getElementsByTagName('button')[0].focus();
|
|
76
|
+
} else {
|
|
77
|
+
remainingItems[remainingItems.length - 1].getElementsByTagName('button')[0].focus();
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
this.input.focus();
|
|
81
|
+
}
|
|
82
|
+
this.selectedItems = this.selectedItems.filter((i)=>i.value !== item.value);
|
|
83
|
+
const itemInput = this.element.querySelector(`input[value="${item.value}"]`);
|
|
84
|
+
itemInput.remove();
|
|
85
|
+
}
|
|
86
|
+
addItem(item, save = true) {
|
|
87
|
+
if (!item) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const newItem = document.createElement('li');
|
|
91
|
+
newItem.textContent = `${item.name} `;
|
|
92
|
+
newItem.setAttribute('data-value', item.value);
|
|
93
|
+
newItem.classList.add((0, _className.default)('a-tag'));
|
|
94
|
+
newItem.classList.add((0, _className.default)(`${this.baseClassName}__tag`));
|
|
95
|
+
const removeBtn = document.createElement('button');
|
|
96
|
+
removeBtn.classList.add((0, _className.default)(`${this.baseClassName}-selected-items__remove-btn`));
|
|
97
|
+
const buttonTextContainer = document.createElement('span');
|
|
98
|
+
buttonTextContainer.classList.add('u-visuallyhidden');
|
|
99
|
+
removeBtn.appendChild(buttonTextContainer);
|
|
100
|
+
buttonTextContainer.textContent = `Ta bort ${item.name}`; // Accessibility label for screen readers
|
|
101
|
+
// Event listener for removing the selected item
|
|
102
|
+
removeBtn.addEventListener('click', ()=>{
|
|
103
|
+
this.removeItem(item);
|
|
104
|
+
});
|
|
105
|
+
newItem.appendChild(removeBtn);
|
|
106
|
+
this.selectedItemsList.appendChild(newItem);
|
|
107
|
+
this.selectedItems.push(item);
|
|
108
|
+
if (save) {
|
|
109
|
+
const itemInput = document.createElement('input');
|
|
110
|
+
itemInput.type = 'hidden';
|
|
111
|
+
itemInput.name = `${this.name}[]`;
|
|
112
|
+
itemInput.value = item.value;
|
|
113
|
+
this.element.appendChild(itemInput);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
removeHighlight() {
|
|
117
|
+
const items = this.suggestionsBox.getElementsByClassName((0, _className.default)(`${this.baseClassName}__suggestion-btn`));
|
|
118
|
+
[].forEach.call(items, (item)=>{
|
|
119
|
+
item.classList.remove('autocomplete-active');
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
highlight(direction) {
|
|
123
|
+
const items = this.suggestionsBox.getElementsByClassName((0, _className.default)(`${this.baseClassName}__suggestion-btn`));
|
|
124
|
+
let focus = this.currentFocus;
|
|
125
|
+
if (direction === 'down') {
|
|
126
|
+
focus = focus >= items.length - 1 ? 0 : focus + 1;
|
|
127
|
+
} else {
|
|
128
|
+
focus = focus <= 0 ? items.length - 1 : focus - 1;
|
|
129
|
+
}
|
|
130
|
+
this.setFocus(focus);
|
|
131
|
+
this.removeHighlight();
|
|
132
|
+
items[this.currentFocus].classList.add('autocomplete-active');
|
|
133
|
+
items[this.currentFocus].scrollIntoView({
|
|
134
|
+
block: 'nearest'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
selectHighlighted() {
|
|
138
|
+
const items = this.suggestionsBox.getElementsByClassName((0, _className.default)(`${this.baseClassName}__suggestion-btn`));
|
|
139
|
+
if (this.currentFocus > -1 && items[this.currentFocus]) {
|
|
140
|
+
const item = items[this.currentFocus];
|
|
141
|
+
this.addItem(this.data.find((d)=>d.value === item.value));
|
|
142
|
+
this.clearSuggestions();
|
|
143
|
+
this.input.value = '';
|
|
144
|
+
this.resetFocus();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
constructor(el){
|
|
148
|
+
this.onInput = ()=>{
|
|
149
|
+
const { value } = this.input;
|
|
150
|
+
// Clear suggestions if less than 2 characters are typed
|
|
151
|
+
if (value.length < 2) {
|
|
152
|
+
this.clearSuggestions();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const suggestions = this.filterData(value);
|
|
156
|
+
if (suggestions.length) {
|
|
157
|
+
this.populateSuggestions(suggestions);
|
|
158
|
+
} else {
|
|
159
|
+
this.clearSuggestions();
|
|
160
|
+
}
|
|
161
|
+
this.resetFocus();
|
|
162
|
+
};
|
|
163
|
+
this.onKeyDown = (e)=>{
|
|
164
|
+
if (e.keyCode === 40) {
|
|
165
|
+
this.highlight('down');
|
|
166
|
+
} else if (e.keyCode === 38) {
|
|
167
|
+
this.highlight('up');
|
|
168
|
+
} else if (e.keyCode === 13) {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
this.selectHighlighted();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
this.onClick = (e)=>{
|
|
174
|
+
if (e.target.classList.contains((0, _className.default)(`${this.baseClassName}__suggestion-btn`))) {
|
|
175
|
+
this.addItem(this.data.find((d)=>d.value === e.target.value));
|
|
176
|
+
this.clearSuggestions();
|
|
177
|
+
this.input.value = '';
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
this.element = el;
|
|
181
|
+
this.baseClassName = 'm-multi-select';
|
|
182
|
+
this.currentFocus = -1;
|
|
183
|
+
this.name = this.element.getAttribute('data-multi-select-name');
|
|
184
|
+
this.input = this.element.querySelector(`.js-${this.baseClassName}__input`);
|
|
185
|
+
this.suggestionsBox = this.element.querySelector(`.js-${this.baseClassName}-suggestions-box`);
|
|
186
|
+
this.selectedItemsList = this.element.querySelector('.js-m-multi-select-selected-items');
|
|
187
|
+
this.selectedItems = [];
|
|
188
|
+
this.data = [];
|
|
189
|
+
this.getData();
|
|
190
|
+
this.attach();
|
|
191
|
+
this.sync();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const multiSelectElements = document.querySelectorAll('.js-m-multi-select');
|
|
301
195
|
if (multiSelectElements) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
196
|
+
[].forEach.call(multiSelectElements, (el)=>{
|
|
197
|
+
el.multiSelect = new MultiSelect(el);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -1,55 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var inputs = document.querySelectorAll('.js-natural-language-input');
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const selects = document.querySelectorAll('.js-natural-language-select');
|
|
3
|
+
const inputs = document.querySelectorAll('.js-natural-language-input');
|
|
6
4
|
function sync(el, option) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
el.dataset.color = color;
|
|
11
|
-
el.innerText = option.innerText;
|
|
5
|
+
const { color } = option.dataset;
|
|
6
|
+
el.dataset.color = color;
|
|
7
|
+
el.innerText = option.innerText;
|
|
12
8
|
}
|
|
13
|
-
|
|
14
9
|
function setupSelect(select) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
sync(text, select.options[select.selectedIndex]);
|
|
25
|
-
}, 0);
|
|
10
|
+
const parent = select.parentNode;
|
|
11
|
+
const text = parent.querySelector('label');
|
|
12
|
+
select.addEventListener('change', ()=>{
|
|
13
|
+
sync(text, select.options[select.selectedIndex]);
|
|
14
|
+
});
|
|
15
|
+
// Next tick
|
|
16
|
+
setTimeout(()=>{
|
|
17
|
+
sync(text, select.options[select.selectedIndex]);
|
|
18
|
+
}, 0);
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
if (selects) {
|
|
29
|
-
|
|
21
|
+
[].forEach.call(selects, setupSelect);
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function syncInput(el, input, value) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}, 0);
|
|
24
|
+
el.innerText = value;
|
|
25
|
+
setTimeout(()=>{
|
|
26
|
+
const selectWidth = el.getBoundingClientRect().width;
|
|
27
|
+
input.style.width = `${selectWidth}px`;
|
|
28
|
+
}, 0);
|
|
39
29
|
}
|
|
40
|
-
|
|
41
30
|
if (inputs) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
31
|
+
[].forEach.call(inputs, (input)=>{
|
|
32
|
+
const text = input.nextElementSibling;
|
|
33
|
+
syncInput(text, input, input.value);
|
|
34
|
+
input.addEventListener('input', (e)=>{
|
|
35
|
+
syncInput(text, input, e.target.value);
|
|
36
|
+
});
|
|
37
|
+
input.addEventListener('change', (e)=>{
|
|
38
|
+
syncInput(text, input, e.target.value);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|