@qld-gov-au/qgds-bootstrap5 1.0.11 → 1.0.13
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/assets/css/qld.bootstrap.css +1 -1
- package/dist/assets/css/qld.bootstrap.css.map +3 -3
- package/dist/assets/js/qld.bootstrap.min.js +20 -14
- package/dist/assets/js/qld.bootstrap.min.js.map +4 -4
- package/dist/components/bs5/header/header.hbs +18 -72
- package/dist/sample-data/header/header.data.json +33 -169
- package/dist/sample-data/tag/tag.data.json +19 -15
- package/package.json +18 -17
- package/src/components/bs5/breadcrumbs/breadcrumb.functions.js +56 -0
- package/src/components/bs5/breadcrumbs/breadcrumbs.scss +20 -0
- package/src/components/bs5/card/card.scss +13 -2
- package/src/components/bs5/correctincorrect/correctincorrect.scss +45 -51
- package/src/components/bs5/correctincorrect/correctincorrect.stories.js +29 -28
- package/src/components/bs5/header/_colours.scss +93 -122
- package/src/components/bs5/header/header.data.json +33 -169
- package/src/components/bs5/header/header.functions.js +141 -78
- package/src/components/bs5/header/header.hbs +18 -72
- package/src/components/bs5/header/header.scss +32 -9
- package/src/components/bs5/navbar/navbar.functions.js +26 -7
- package/src/components/bs5/spinner/spinner.scss +1 -3
- package/src/components/bs5/tag/tag.data.json +19 -15
- package/src/components/bs5/tag/tag.scss +129 -39
- package/src/components/bs5/tag/tag.stories.js +12 -12
- package/src/main.js +13 -15
- package/src/main.scss +1 -0
- package/src/scss/qld-variables.scss +6 -15
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"masterbrand_variant": {
|
|
3
3
|
"icon-root": "assets/img/svg-icons.svg",
|
|
4
|
+
"icons": {
|
|
5
|
+
"menu-icon": "qld__icon__mobile-menu",
|
|
6
|
+
"search-icon": "qld__icon__search",
|
|
7
|
+
"close-icon": "qld__icon__close"
|
|
8
|
+
},
|
|
4
9
|
"sitePreHeader": {
|
|
5
10
|
"url": {
|
|
6
11
|
"value": "https://qld.gov.au"
|
|
@@ -140,49 +145,7 @@
|
|
|
140
145
|
"dropdown_options": {
|
|
141
146
|
"dropdown_type": "form",
|
|
142
147
|
"dropdown_config": {
|
|
143
|
-
"
|
|
144
|
-
{
|
|
145
|
-
"heading": "Log in to For government",
|
|
146
|
-
"content": "Most employees can log in using single sign on (SSO).",
|
|
147
|
-
"usesButton": "true",
|
|
148
|
-
"actionType": "button",
|
|
149
|
-
"action": {
|
|
150
|
-
"button_action": "#",
|
|
151
|
-
"button_targetAttr": "_blank",
|
|
152
|
-
"button_label": "Login"
|
|
153
|
-
},
|
|
154
|
-
"links": [
|
|
155
|
-
{
|
|
156
|
-
"action": "_blank",
|
|
157
|
-
"label": "If your agency doesn't use SSO.",
|
|
158
|
-
"url": "https://www.forgov.qld.gov.au/user#log-in"
|
|
159
|
-
}
|
|
160
|
-
]
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"heading": "Select your agency",
|
|
164
|
-
"content": "See information relevant to your agency.",
|
|
165
|
-
"actionType": "select",
|
|
166
|
-
"options": [
|
|
167
|
-
{
|
|
168
|
-
"value": "agency 1"
|
|
169
|
-
}
|
|
170
|
-
]
|
|
171
|
-
}
|
|
172
|
-
],
|
|
173
|
-
"examples": [
|
|
174
|
-
{
|
|
175
|
-
"heading": "For employees",
|
|
176
|
-
"actionType": "list",
|
|
177
|
-
"list_items": [
|
|
178
|
-
{
|
|
179
|
-
"action": "_self",
|
|
180
|
-
"label": "Your profile",
|
|
181
|
-
"href": "#"
|
|
182
|
-
}
|
|
183
|
-
]
|
|
184
|
-
}
|
|
185
|
-
]
|
|
148
|
+
"content": "<div></div>"
|
|
186
149
|
}
|
|
187
150
|
}
|
|
188
151
|
}
|
|
@@ -215,14 +178,11 @@
|
|
|
215
178
|
"placeholder": "",
|
|
216
179
|
"label": "",
|
|
217
180
|
"formAction": {
|
|
218
|
-
"url": "https://www.forgov.qld.gov.au/search"
|
|
181
|
+
"url": "https://www.forgov.qld.gov.au/search",
|
|
182
|
+
"suggestions": "https://discover.search.qld.gov.au/s/suggest.json",
|
|
183
|
+
"results": "https://discover.search.qld.gov.au/s/search.json"
|
|
219
184
|
},
|
|
220
185
|
"options": {
|
|
221
|
-
"icons": {
|
|
222
|
-
"menu-icon": "qld__icon__mobile-menu",
|
|
223
|
-
"search-icon": "qld__icon__search",
|
|
224
|
-
"search-close-icon": "qld__icon__close"
|
|
225
|
-
},
|
|
226
186
|
"borderStyle": {
|
|
227
187
|
"full": true
|
|
228
188
|
}
|
|
@@ -231,6 +191,11 @@
|
|
|
231
191
|
},
|
|
232
192
|
"subbrand_variant": {
|
|
233
193
|
"icon-root": "assets/img/svg-icons.svg",
|
|
194
|
+
"icons": {
|
|
195
|
+
"menu-icon": "qld__icon__mobile-menu",
|
|
196
|
+
"search-icon": "qld__icon__search",
|
|
197
|
+
"close-icon": "qld__icon__close"
|
|
198
|
+
},
|
|
234
199
|
"sitePreHeader": {
|
|
235
200
|
"url": {
|
|
236
201
|
"value": "https://qld.gov.au"
|
|
@@ -276,23 +241,7 @@
|
|
|
276
241
|
"dropdown_options": {
|
|
277
242
|
"dropdown_type": "form",
|
|
278
243
|
"dropdown_config": {
|
|
279
|
-
"
|
|
280
|
-
{
|
|
281
|
-
"heading": "Log in to For government",
|
|
282
|
-
"button_action": "#",
|
|
283
|
-
"button_targetAttr": "_blank",
|
|
284
|
-
"button_label": "Login"
|
|
285
|
-
}
|
|
286
|
-
],
|
|
287
|
-
"examples": [
|
|
288
|
-
{
|
|
289
|
-
"heading": "For employees",
|
|
290
|
-
"content": "See information relevant to your agency.",
|
|
291
|
-
"button_action": "#",
|
|
292
|
-
"button_targetAttr": "_blank",
|
|
293
|
-
"button_label": "Login"
|
|
294
|
-
}
|
|
295
|
-
]
|
|
244
|
+
"content": "<div></div>"
|
|
296
245
|
}
|
|
297
246
|
}
|
|
298
247
|
}
|
|
@@ -325,14 +274,11 @@
|
|
|
325
274
|
"placeholder": "Placeholder",
|
|
326
275
|
"label": "Label",
|
|
327
276
|
"formAction": {
|
|
328
|
-
"url": "https://www.forgov.qld.gov.au/search"
|
|
277
|
+
"url": "https://www.forgov.qld.gov.au/search",
|
|
278
|
+
"suggestions": "https://discover.search.qld.gov.au/s/suggest.json",
|
|
279
|
+
"results": "https://discover.search.qld.gov.au/s/search.json"
|
|
329
280
|
},
|
|
330
281
|
"options": {
|
|
331
|
-
"icons": {
|
|
332
|
-
"menu-icon": "qld__icon__mobile-menu",
|
|
333
|
-
"search-icon": "qld__icon__search",
|
|
334
|
-
"search-close-icon": "qld__icon__close"
|
|
335
|
-
},
|
|
336
282
|
"borderStyle": {
|
|
337
283
|
"full": false
|
|
338
284
|
}
|
|
@@ -341,6 +287,11 @@
|
|
|
341
287
|
},
|
|
342
288
|
"endorsed_variant": {
|
|
343
289
|
"icon-root": "assets/img/svg-icons.svg",
|
|
290
|
+
"icons": {
|
|
291
|
+
"menu-icon": "qld__icon__mobile-menu",
|
|
292
|
+
"search-icon": "qld__icon__search",
|
|
293
|
+
"close-icon": "qld__icon__close"
|
|
294
|
+
},
|
|
344
295
|
"sitePreHeader": {
|
|
345
296
|
"url": {
|
|
346
297
|
"value": "https://qld.gov.au"
|
|
@@ -480,49 +431,7 @@
|
|
|
480
431
|
"dropdown_options": {
|
|
481
432
|
"dropdown_type": "form",
|
|
482
433
|
"dropdown_config": {
|
|
483
|
-
"
|
|
484
|
-
{
|
|
485
|
-
"heading": "Log in to For government",
|
|
486
|
-
"content": "Most employees can log in using single sign on (SSO).",
|
|
487
|
-
"usesButton": "true",
|
|
488
|
-
"actionType": "button",
|
|
489
|
-
"action": {
|
|
490
|
-
"button_action": "#",
|
|
491
|
-
"button_targetAttr": "_blank",
|
|
492
|
-
"button_label": "Login"
|
|
493
|
-
},
|
|
494
|
-
"links": [
|
|
495
|
-
{
|
|
496
|
-
"action": "_blank",
|
|
497
|
-
"label": "If your agency doesn't use SSO.",
|
|
498
|
-
"url": "https://www.forgov.qld.gov.au/user#log-in"
|
|
499
|
-
}
|
|
500
|
-
]
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
"heading": "Select your agency",
|
|
504
|
-
"content": "See information relevant to your agency.",
|
|
505
|
-
"actionType": "select",
|
|
506
|
-
"options": [
|
|
507
|
-
{
|
|
508
|
-
"value": "agency 1"
|
|
509
|
-
}
|
|
510
|
-
]
|
|
511
|
-
}
|
|
512
|
-
],
|
|
513
|
-
"examples": [
|
|
514
|
-
{
|
|
515
|
-
"heading": "For employees",
|
|
516
|
-
"actionType": "list",
|
|
517
|
-
"list_items": [
|
|
518
|
-
{
|
|
519
|
-
"action": "_self",
|
|
520
|
-
"label": "Your profile",
|
|
521
|
-
"href": "#"
|
|
522
|
-
}
|
|
523
|
-
]
|
|
524
|
-
}
|
|
525
|
-
]
|
|
434
|
+
"content": "<div></div>"
|
|
526
435
|
}
|
|
527
436
|
}
|
|
528
437
|
}
|
|
@@ -555,14 +464,11 @@
|
|
|
555
464
|
"placeholder": "",
|
|
556
465
|
"label": "",
|
|
557
466
|
"formAction": {
|
|
558
|
-
"url": "https://www.forgov.qld.gov.au/search"
|
|
467
|
+
"url": "https://www.forgov.qld.gov.au/search",
|
|
468
|
+
"suggestions": "https://discover.search.qld.gov.au/s/suggest.json",
|
|
469
|
+
"results": "https://discover.search.qld.gov.au/s/search.json"
|
|
559
470
|
},
|
|
560
471
|
"options": {
|
|
561
|
-
"icons": {
|
|
562
|
-
"menu-icon": "qld__icon__mobile-menu",
|
|
563
|
-
"search-icon": "qld__icon__search",
|
|
564
|
-
"search-close-icon": "qld__icon__close"
|
|
565
|
-
},
|
|
566
472
|
"borderStyle": {
|
|
567
473
|
"full": true
|
|
568
474
|
}
|
|
@@ -571,6 +477,11 @@
|
|
|
571
477
|
},
|
|
572
478
|
"standalone_variant": {
|
|
573
479
|
"icon-root": "assets/img/svg-icons.svg",
|
|
480
|
+
"icons": {
|
|
481
|
+
"menu-icon": "qld__icon__mobile-menu",
|
|
482
|
+
"search-icon": "qld__icon__search",
|
|
483
|
+
"close-icon": "qld__icon__close"
|
|
484
|
+
},
|
|
574
485
|
"sitePreHeader": {
|
|
575
486
|
"url": {
|
|
576
487
|
"value": "https://qld.gov.au"
|
|
@@ -710,49 +621,7 @@
|
|
|
710
621
|
"dropdown_options": {
|
|
711
622
|
"dropdown_type": "form",
|
|
712
623
|
"dropdown_config": {
|
|
713
|
-
"
|
|
714
|
-
{
|
|
715
|
-
"heading": "Log in to For government",
|
|
716
|
-
"content": "Most employees can log in using single sign on (SSO).",
|
|
717
|
-
"usesButton": "true",
|
|
718
|
-
"actionType": "button",
|
|
719
|
-
"action": {
|
|
720
|
-
"button_action": "#",
|
|
721
|
-
"button_targetAttr": "_blank",
|
|
722
|
-
"button_label": "Login"
|
|
723
|
-
},
|
|
724
|
-
"links": [
|
|
725
|
-
{
|
|
726
|
-
"action": "_blank",
|
|
727
|
-
"label": "If your agency doesn't use SSO.",
|
|
728
|
-
"url": "https://www.forgov.qld.gov.au/user#log-in"
|
|
729
|
-
}
|
|
730
|
-
]
|
|
731
|
-
},
|
|
732
|
-
{
|
|
733
|
-
"heading": "Select your agency",
|
|
734
|
-
"content": "See information relevant to your agency.",
|
|
735
|
-
"actionType": "select",
|
|
736
|
-
"options": [
|
|
737
|
-
{
|
|
738
|
-
"value": "agency 1"
|
|
739
|
-
}
|
|
740
|
-
]
|
|
741
|
-
}
|
|
742
|
-
],
|
|
743
|
-
"examples": [
|
|
744
|
-
{
|
|
745
|
-
"heading": "For employees",
|
|
746
|
-
"actionType": "list",
|
|
747
|
-
"list_items": [
|
|
748
|
-
{
|
|
749
|
-
"action": "_self",
|
|
750
|
-
"label": "Your profile",
|
|
751
|
-
"href": "#"
|
|
752
|
-
}
|
|
753
|
-
]
|
|
754
|
-
}
|
|
755
|
-
]
|
|
624
|
+
"content": "<div></div>"
|
|
756
625
|
}
|
|
757
626
|
}
|
|
758
627
|
}
|
|
@@ -788,11 +657,6 @@
|
|
|
788
657
|
"url": "https://www.forgov.qld.gov.au/search"
|
|
789
658
|
},
|
|
790
659
|
"options": {
|
|
791
|
-
"icons": {
|
|
792
|
-
"menu-icon": "qld__icon__mobile-menu",
|
|
793
|
-
"search-icon": "qld__icon__search",
|
|
794
|
-
"search-close-icon": "qld__icon__close"
|
|
795
|
-
},
|
|
796
660
|
"borderStyle": {
|
|
797
661
|
"full": true
|
|
798
662
|
}
|
|
@@ -21,7 +21,8 @@ export function toggleSearch(event) {
|
|
|
21
21
|
// Get the search div
|
|
22
22
|
const searchDiv = document.getElementById('qld-header-search');
|
|
23
23
|
const toggleButton = event.currentTarget;
|
|
24
|
-
const
|
|
24
|
+
const searchIcon = toggleButton.querySelector('use.icon-search');
|
|
25
|
+
const closeIcon = toggleButton.querySelector('use.icon-close');
|
|
25
26
|
const toggleText = toggleButton.querySelector('.qld__main-nav__toggle-text');
|
|
26
27
|
|
|
27
28
|
// Check current class and swap
|
|
@@ -31,14 +32,16 @@ export function toggleSearch(event) {
|
|
|
31
32
|
searchDiv.classList.add('qld__header__site-search--closed');
|
|
32
33
|
|
|
33
34
|
// Change icon and text back to default
|
|
34
|
-
|
|
35
|
+
searchIcon.style.display = 'block';
|
|
36
|
+
closeIcon.style.display = 'none';
|
|
35
37
|
toggleText.textContent = 'Search';
|
|
36
38
|
} else {
|
|
37
39
|
searchDiv.classList.remove('qld__header__site-search--closed');
|
|
38
40
|
searchDiv.classList.add('qld__header__site-search--open');
|
|
39
41
|
|
|
40
42
|
// Change icon and text to active state
|
|
41
|
-
|
|
43
|
+
searchIcon.style.display = 'none';
|
|
44
|
+
closeIcon.style.display = 'block';
|
|
42
45
|
toggleText.textContent = 'Close';
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -48,14 +51,84 @@ export function toggleSearch(event) {
|
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Fetches suggestions from the provided URL.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} url - The URL to fetch suggestions from.
|
|
58
|
+
* @returns {Promise<Object>} - A promise that resolves to the fetched suggestions.
|
|
59
|
+
*/
|
|
60
|
+
async function fetchSuggestions(url) {
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetch(url);
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw new Error('Network response was not ok');
|
|
65
|
+
}
|
|
66
|
+
const data = await response.json();
|
|
67
|
+
return data;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error("Error fetching suggestions:", error);
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Fetches related services from the provided URL.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} url - The URL to fetch related services from.
|
|
78
|
+
* @returns {Promise<Object>} - A promise that resolves to the fetched services.
|
|
79
|
+
*/
|
|
80
|
+
async function fetchServices(url) {
|
|
81
|
+
try {
|
|
82
|
+
const response = await fetch(url);
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
throw new Error('Network response was not ok');
|
|
85
|
+
}
|
|
86
|
+
const data = await response.json();
|
|
87
|
+
return data;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error("Error fetching services:", error);
|
|
90
|
+
return {};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Sets the selected suggestion into the input field and submits the form.
|
|
96
|
+
*
|
|
97
|
+
* @param {string} value - The selected suggestion.
|
|
98
|
+
* @returns {void}
|
|
99
|
+
*/
|
|
100
|
+
export function selectSuggestion(value) {
|
|
101
|
+
const searchInput = document.getElementById('search-input');
|
|
102
|
+
const suggestions = document.getElementById('suggestions');
|
|
103
|
+
const form = document.getElementById('site-search');
|
|
104
|
+
|
|
105
|
+
if (searchInput && suggestions && form) {
|
|
106
|
+
searchInput.value = value;
|
|
107
|
+
suggestions.style.display = 'none';
|
|
108
|
+
|
|
109
|
+
// Construct the action URL with query and other parameters
|
|
110
|
+
const baseUrl = form.getAttribute('action');
|
|
111
|
+
const collection = 'qgov~sp-search';
|
|
112
|
+
const profile = 'qld';
|
|
113
|
+
const query = encodeURIComponent(value);
|
|
114
|
+
const actionUrl = `${baseUrl}?query=${query}&collection=${collection}&profile=${profile}`;
|
|
115
|
+
|
|
116
|
+
// Update the form's action attribute
|
|
117
|
+
form.setAttribute('action', actionUrl);
|
|
118
|
+
|
|
119
|
+
// Submit the form
|
|
120
|
+
form.submit();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
51
124
|
/**
|
|
52
125
|
* Shows suggestions based on the user's input.
|
|
53
126
|
*
|
|
54
127
|
* @param {string} value - The current input value.
|
|
55
128
|
* @param {boolean} isDefault - Whether to show default suggestions or not.
|
|
56
129
|
* @returns {void}
|
|
57
|
-
**/
|
|
58
|
-
export function showSuggestions(value = '', isDefault = false) {
|
|
130
|
+
**/
|
|
131
|
+
export async function showSuggestions(value = '', isDefault = false) {
|
|
59
132
|
const suggestions = document.getElementById('suggestions');
|
|
60
133
|
const searchInput = document.getElementById('search-input');
|
|
61
134
|
|
|
@@ -64,19 +137,23 @@ export function showSuggestions(value = '', isDefault = false) {
|
|
|
64
137
|
return;
|
|
65
138
|
}
|
|
66
139
|
|
|
140
|
+
// Clear previous suggestions and services
|
|
141
|
+
suggestions.innerHTML = '';
|
|
142
|
+
|
|
67
143
|
const loadedSuggestions = defaultSuggestions;
|
|
68
144
|
|
|
69
145
|
if (isDefault) {
|
|
70
146
|
suggestions.innerHTML = `
|
|
71
|
-
<div class="suggestions-category mt-
|
|
72
|
-
<strong>Popular
|
|
73
|
-
<ul class="mt-2">${loadedSuggestions.popular_services.map(item => `<li onclick="selectSuggestion('${item.title}')"><a href="${item.href}">${item.title}</a></li>`).join('')}</ul>
|
|
147
|
+
<div class="suggestions-category mt-2">
|
|
148
|
+
<strong>Popular services</strong>
|
|
149
|
+
<ul class="mt-2">${loadedSuggestions.popular_services.slice(0, 4).map(item => `<li onclick="window.selectSuggestion('${item.title}')"><a href="${item.href}">${item.title}</a></li>`).join('')}</ul>
|
|
74
150
|
</div>
|
|
75
|
-
<
|
|
76
|
-
|
|
77
|
-
<
|
|
151
|
+
<hr>
|
|
152
|
+
<div class="suggestions-category mt-2">
|
|
153
|
+
<strong>Browse by category</strong>
|
|
154
|
+
<ul class="mt-2">${loadedSuggestions.categories.slice(0, 4).map(item => `<li onclick="window.selectSuggestion('${item.title}')"><a href="${item.href}">${item.title}</a></li>`).join('')}</ul>
|
|
78
155
|
</div>
|
|
79
|
-
|
|
156
|
+
<!--${loadedSuggestions.options.view_more ? `<div class="suggestions-category mt-4 mb-4"><a href="${loadedSuggestions.options.href}">${loadedSuggestions.options.label}</a></div>-->` : ''}
|
|
80
157
|
`;
|
|
81
158
|
suggestions.classList.add('show');
|
|
82
159
|
createPopper(searchInput, suggestions, {
|
|
@@ -92,74 +169,60 @@ export function showSuggestions(value = '', isDefault = false) {
|
|
|
92
169
|
return;
|
|
93
170
|
}
|
|
94
171
|
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
172
|
+
// Fetch suggestions from the provided URL
|
|
173
|
+
const form = document.getElementById('site-search');
|
|
174
|
+
const suggestUrl = form.getAttribute('data-suggestions');
|
|
175
|
+
const resultsUrl = form.getAttribute('data-results-url');
|
|
176
|
+
|
|
177
|
+
if (suggestUrl) {
|
|
178
|
+
const fetchedSuggestions = await fetchSuggestions(`${suggestUrl}?collection=qgov~sp-search&fmt=json%2B%2B&alpha=0.5&profile=qld&partial_query=${encodeURIComponent(value)}`);
|
|
179
|
+
|
|
180
|
+
// Use the fetched suggestions to populate the suggestions dropdown
|
|
181
|
+
if (fetchedSuggestions.length > 0) {
|
|
182
|
+
suggestions.innerHTML = `
|
|
183
|
+
<div class="suggestions-category mt-2">
|
|
184
|
+
<strong>Suggestions</strong>
|
|
185
|
+
<ul class="mt-2">${fetchedSuggestions.slice(0, 4).map(item => {
|
|
186
|
+
if (!item.disp) return ''; // Check if item.disp is defined
|
|
187
|
+
const highlightedText = item.disp.replace(new RegExp(`(${value})`, 'gi'), '<strong>$1</strong>');
|
|
188
|
+
return `<li onclick="window.selectSuggestion('${item.disp}')"><a href="#">${highlightedText}</a></li>`;
|
|
189
|
+
}).join('')}</ul>
|
|
190
|
+
</div>
|
|
191
|
+
`;
|
|
192
|
+
suggestions.classList.add('show');
|
|
193
|
+
|
|
194
|
+
// Initialize Popper.js to manage the dropdown position
|
|
195
|
+
createPopper(searchInput, suggestions, {
|
|
196
|
+
placement: 'bottom-start',
|
|
197
|
+
});
|
|
198
|
+
suggestions.style.display = 'block';
|
|
199
|
+
} else {
|
|
200
|
+
suggestions.innerHTML = '';
|
|
201
|
+
suggestions.style.display = 'none';
|
|
202
|
+
}
|
|
102
203
|
}
|
|
103
204
|
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Sets the selected suggestion into the input field.
|
|
126
|
-
*
|
|
127
|
-
* @param {string} value - The selected suggestion.
|
|
128
|
-
* @returns {void}
|
|
129
|
-
*/
|
|
130
|
-
export function selectSuggestion(value) {
|
|
131
|
-
const searchInput = document.getElementById('search-input');
|
|
132
|
-
const suggestions = document.getElementById('suggestions');
|
|
133
|
-
|
|
134
|
-
if (searchInput && suggestions) {
|
|
135
|
-
searchInput.value = value;
|
|
136
|
-
suggestions.style.display = 'none';
|
|
205
|
+
if (resultsUrl) {
|
|
206
|
+
const fetchedServices = await fetchServices(`${resultsUrl}?collection=qgov~sp-search&profile=qld&smeta_sfinder_sand=yes&query=${encodeURIComponent(value)}`);
|
|
207
|
+
|
|
208
|
+
// Use the fetched services to populate the services dropdown
|
|
209
|
+
if (fetchedServices.response.resultPacket && fetchedServices.response.resultPacket.results.length > 0) {
|
|
210
|
+
suggestions.innerHTML += `
|
|
211
|
+
<div class="suggestions-category feature pt-2">
|
|
212
|
+
<strong>Services</strong>
|
|
213
|
+
<ul class="mt-2">${fetchedServices.response.resultPacket.results.slice(0, 4).map(item => `<li class="pb-2" onclick="window.selectSuggestion('${item.title}')"><a href="${item.liveUrl}">${item.title}</a></li>`).join('')}</ul>
|
|
214
|
+
</div>
|
|
215
|
+
`;
|
|
216
|
+
suggestions.classList.add('show');
|
|
217
|
+
|
|
218
|
+
// Initialize Popper.js to manage the dropdown position
|
|
219
|
+
createPopper(searchInput, suggestions, {
|
|
220
|
+
placement: 'bottom-start',
|
|
221
|
+
});
|
|
222
|
+
suggestions.style.display = 'block';
|
|
223
|
+
}
|
|
137
224
|
}
|
|
138
225
|
}
|
|
139
226
|
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
if (searchInput) {
|
|
143
|
-
|
|
144
|
-
// Events
|
|
145
|
-
searchInput.addEventListener('keyup', function() {
|
|
146
|
-
showSuggestions(this.value);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
searchInput.addEventListener('focus', function() {
|
|
150
|
-
showSuggestions('', true);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
searchInput.addEventListener('click', function() {
|
|
154
|
-
if (this.value === '') {
|
|
155
|
-
showSuggestions('', true);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// Close suggestions when clicking outside
|
|
160
|
-
document.addEventListener('click', function(event) {
|
|
161
|
-
if (!searchInput.contains(event.target) && !document.getElementById('suggestions').contains(event.target)) {
|
|
162
|
-
document.getElementById('suggestions').style.display = 'none';
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
227
|
+
// Attach the function to the window object to make it globally accessible
|
|
228
|
+
window.selectSuggestion = selectSuggestion;
|