@searchstax-inc/searchstudio-ux-js 0.0.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/CHANGELOG.md +15 -0
- package/LICENSE.md +9 -0
- package/README.md +61 -0
- package/dist/@searchstax-inc/searchstudio-ux-js.cjs +69 -0
- package/dist/@searchstax-inc/searchstudio-ux-js.d.ts +163 -0
- package/dist/@searchstax-inc/searchstudio-ux-js.iife.js +69 -0
- package/dist/@searchstax-inc/searchstudio-ux-js.mjs +995 -0
- package/dist/styles/mainTheme.css +153 -0
- package/package.json +60 -0
|
@@ -0,0 +1,995 @@
|
|
|
1
|
+
var U = Object.defineProperty;
|
|
2
|
+
var K = (i, e, t) => e in i ? U(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var u = (i, e, t) => (K(i, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
class A {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
u(this, "value");
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
8
|
+
u(this, "observers", []);
|
|
9
|
+
this.value = e, this.observers = [];
|
|
10
|
+
}
|
|
11
|
+
subscribe(e) {
|
|
12
|
+
this.observers.push(e), e(this.value);
|
|
13
|
+
}
|
|
14
|
+
unsubscribe(e) {
|
|
15
|
+
const t = this.observers.indexOf(e);
|
|
16
|
+
t !== -1 && this.observers.splice(t, 1);
|
|
17
|
+
}
|
|
18
|
+
setValue(e) {
|
|
19
|
+
this.value = e, this.notify();
|
|
20
|
+
}
|
|
21
|
+
getValue() {
|
|
22
|
+
return this.value;
|
|
23
|
+
}
|
|
24
|
+
notify() {
|
|
25
|
+
this.observers.forEach((e) => e(this.value));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class j {
|
|
29
|
+
constructor() {
|
|
30
|
+
u(this, "searchTermChangeObservable", new A(""));
|
|
31
|
+
u(this, "loadingChangeObservable", new A(!1));
|
|
32
|
+
u(this, "searchResultsObservable", new A(null));
|
|
33
|
+
u(this, "searchResultsMetadataObservable", new A(null));
|
|
34
|
+
u(this, "searchAutosuggestObservable", new A(null));
|
|
35
|
+
u(this, "currentPage", 1);
|
|
36
|
+
u(this, "renderingEngine", "mustache");
|
|
37
|
+
}
|
|
38
|
+
setSearchTerm(e) {
|
|
39
|
+
this.searchTermChangeObservable.setValue(e);
|
|
40
|
+
}
|
|
41
|
+
setRenderingEngine(e) {
|
|
42
|
+
this.renderingEngine = e;
|
|
43
|
+
}
|
|
44
|
+
setCurrentPage(e) {
|
|
45
|
+
this.currentPage = e;
|
|
46
|
+
}
|
|
47
|
+
setLoading(e) {
|
|
48
|
+
this.loadingChangeObservable.setValue(e);
|
|
49
|
+
}
|
|
50
|
+
setSearchResults(e) {
|
|
51
|
+
this.searchResultsObservable.setValue(e);
|
|
52
|
+
}
|
|
53
|
+
setSearchResultsMetadata(e) {
|
|
54
|
+
this.searchResultsMetadataObservable.setValue(e);
|
|
55
|
+
}
|
|
56
|
+
setSearchAutosuggest(e) {
|
|
57
|
+
this.searchAutosuggestObservable.setValue(e);
|
|
58
|
+
}
|
|
59
|
+
get searchResultsValue() {
|
|
60
|
+
return this.searchResultsObservable.getValue();
|
|
61
|
+
}
|
|
62
|
+
get searchTermValue() {
|
|
63
|
+
return this.searchTermChangeObservable.getValue();
|
|
64
|
+
}
|
|
65
|
+
get loadingValue() {
|
|
66
|
+
return this.loadingChangeObservable.getValue();
|
|
67
|
+
}
|
|
68
|
+
get searchAutosuggestValue() {
|
|
69
|
+
return this.searchAutosuggestObservable.getValue();
|
|
70
|
+
}
|
|
71
|
+
get searchResultsMetadataValue() {
|
|
72
|
+
return this.searchResultsMetadataObservable.getValue();
|
|
73
|
+
}
|
|
74
|
+
get currentPageValue() {
|
|
75
|
+
return this.currentPage;
|
|
76
|
+
}
|
|
77
|
+
get renderingEngineValue() {
|
|
78
|
+
return this.renderingEngine;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class E {
|
|
82
|
+
static combineResultsWithMetadata(e) {
|
|
83
|
+
const t = [], s = parseInt(e.response.start + "");
|
|
84
|
+
return e.response.docs.forEach((a, r) => {
|
|
85
|
+
const n = {
|
|
86
|
+
custom: null,
|
|
87
|
+
uniqueId: this.getValueByKey(
|
|
88
|
+
e.responseHeader.params.uniqueId,
|
|
89
|
+
a,
|
|
90
|
+
e
|
|
91
|
+
) ?? "",
|
|
92
|
+
position: s + r + 1,
|
|
93
|
+
ribbon: this.doesMapExist("ribbon", e) ? this.getValueByKey("ribbon", a, e) : null,
|
|
94
|
+
paths: this.doesMapExist("paths", e) ? this.getValueByKey("paths", a, e) : null,
|
|
95
|
+
url: this.doesMapExist("url", e) ? this.getValueByKey("url", a, e) : null,
|
|
96
|
+
title: this.doesMapExist("title", e) ? this.getValueByKey("title", a, e) : null,
|
|
97
|
+
promoted: a["[elevated]"] ? a["[elevated]"] : !1,
|
|
98
|
+
thumbnail: this.doesMapExist("thumbnail", e) ? this.getValueByKey("thumbnail", a, e) : null,
|
|
99
|
+
date: this.doesMapExist("date", e) ? this.getValueByKey("date", a, e) : null,
|
|
100
|
+
snippet: this.doesMapExist("snippet", e) ? this.getValueByKey("snippet", a, e) : null,
|
|
101
|
+
description: this.doesMapExist("description", e) ? this.getValueByKey("description", a, e) : null,
|
|
102
|
+
unmappedFields: this.getUnmappedFields(a, e),
|
|
103
|
+
allFields: this.getAllFields(a, e)
|
|
104
|
+
};
|
|
105
|
+
t.push(n);
|
|
106
|
+
}), t;
|
|
107
|
+
}
|
|
108
|
+
static extractSearchResultsMetadata(e) {
|
|
109
|
+
var s, a, r, n;
|
|
110
|
+
let t = "";
|
|
111
|
+
return t = ((n = (r = (a = (s = e == null ? void 0 : e.spellcheck) == null ? void 0 : s.suggestions) == null ? void 0 : a[0]) == null ? void 0 : r.suggestion) == null ? void 0 : n[0]) ?? "", typeof t != "string" && (t = (t == null ? void 0 : t.word) ?? ""), {
|
|
112
|
+
recordsPerPageValue: parseInt(e.responseHeader.params.rows),
|
|
113
|
+
startDocVal: parseInt(e.response.start + ""),
|
|
114
|
+
totalResultsValue: parseInt(e.response.numFound + ""),
|
|
115
|
+
latency: parseInt(e.responseHeader.QTime + ""),
|
|
116
|
+
endDocValue: parseInt(e.responseHeader.params.rows) + parseInt(e.response.start + ""),
|
|
117
|
+
spellingSuggestion: t
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
static findResultByUniqueId(e, t) {
|
|
121
|
+
return t.find((s) => s.uniqueId === e) ?? null;
|
|
122
|
+
}
|
|
123
|
+
static getUnmappedFields(e, t) {
|
|
124
|
+
const s = t.metadata.results.filter((r) => r.result_card === "").map((r) => r.name), a = [];
|
|
125
|
+
for (const r of Object.keys(e))
|
|
126
|
+
if (s.indexOf(r) !== -1) {
|
|
127
|
+
const n = Array.isArray(e[r]) ? e[r].join(", ") : e[r];
|
|
128
|
+
a.push({
|
|
129
|
+
key: r,
|
|
130
|
+
value: n,
|
|
131
|
+
isImage: this.checkIfImage(e[r])
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return a;
|
|
135
|
+
}
|
|
136
|
+
static checkIfImage(e) {
|
|
137
|
+
return e === void 0 || typeof e != "string" ? !1 : /\.(gif|jpe?g|tiff?|png|webp|bmp)$/i.test(e);
|
|
138
|
+
}
|
|
139
|
+
static getAllFields(e, t) {
|
|
140
|
+
const s = t.metadata.results.map((r) => r.name), a = [];
|
|
141
|
+
for (const r of Object.keys(e))
|
|
142
|
+
s.indexOf(r) !== -1 && a.push({
|
|
143
|
+
key: r,
|
|
144
|
+
value: e[r],
|
|
145
|
+
isImage: this.checkIfImage(e[r])
|
|
146
|
+
});
|
|
147
|
+
return a;
|
|
148
|
+
}
|
|
149
|
+
static doesMapExist(e, t) {
|
|
150
|
+
return t.metadata.results.find((s) => s.result_card === e) !== void 0;
|
|
151
|
+
}
|
|
152
|
+
static getValueByKey(e, t, s) {
|
|
153
|
+
const a = s.metadata.results.find(
|
|
154
|
+
(n) => n.result_card === e
|
|
155
|
+
);
|
|
156
|
+
if (a === void 0)
|
|
157
|
+
return null;
|
|
158
|
+
const r = t[a.name];
|
|
159
|
+
return r === void 0 ? null : typeof r == "string" ? r : Array.isArray(r) ? r.join(", ") : null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
class W {
|
|
163
|
+
constructor(e, t) {
|
|
164
|
+
u(this, "url", "");
|
|
165
|
+
u(this, "relatedSearches", "");
|
|
166
|
+
u(this, "suggester", "");
|
|
167
|
+
u(this, "authHeader");
|
|
168
|
+
u(this, "authHeaderRelated");
|
|
169
|
+
u(this, "language", "en");
|
|
170
|
+
u(this, "trackApiKey", "");
|
|
171
|
+
u(this, "session", "");
|
|
172
|
+
u(this, "searchAdditionalArgs", "");
|
|
173
|
+
u(this, "searchAuthType");
|
|
174
|
+
u(this, "selectAuthToken");
|
|
175
|
+
u(this, "suggesterAuthToken");
|
|
176
|
+
u(this, "controllerSearch");
|
|
177
|
+
u(this, "signalSearch");
|
|
178
|
+
u(this, "controllerSuggest");
|
|
179
|
+
u(this, "signalSuggest");
|
|
180
|
+
u(this, "dataLayer");
|
|
181
|
+
this.dataLayer = t, this.url = e.searchURL, this.language = e.language, this.suggester = e.suggesterURL, this.trackApiKey = e.trackApiKey, this.session = e.sessionId, this.searchAuthType = e.authType, this.selectAuthToken = e.searchToken ?? "", this.suggesterAuthToken = e.suggesterToken ?? "", this.authHeader = new Headers(), this.authHeader.append("Accept", "application/json");
|
|
182
|
+
const s = this.searchAuthType === "token" ? `Token ${this.suggesterAuthToken}` : `Basic ${e.authenticationValue}`;
|
|
183
|
+
this.authHeader.append("Authorization", s), this.authHeaderRelated = new Headers(), this.authHeaderRelated.append("Accept", "application/json"), this.authHeaderRelated.append("Authorization", e.searchApiKey);
|
|
184
|
+
}
|
|
185
|
+
search(e, t, s) {
|
|
186
|
+
this.dataLayer.setSearchTerm(e), this.dataLayer.setLoading(!0), this.controllerSearch && this.controllerSearch.abort(), this.controllerSearch = new AbortController(), this.signalSearch = this.controllerSearch.signal;
|
|
187
|
+
const a = new Proxy(
|
|
188
|
+
new URLSearchParams(window.location.search),
|
|
189
|
+
{
|
|
190
|
+
get: (h, c) => h.get(c) ?? ""
|
|
191
|
+
}
|
|
192
|
+
), r = a.languageVariant ? (
|
|
193
|
+
//@ts-expect-error - this is a hack to get around the fact that the urlQueryParams is a proxy
|
|
194
|
+
"&fq=_language:" + a.languageVariant
|
|
195
|
+
) : "", n = this.url + "?q=" + encodeURIComponent(e.trim()) + this.toQueryString(s) + this.searchAdditionalArgs + "&language=" + this.language + r;
|
|
196
|
+
fetch(n, {
|
|
197
|
+
method: "GET",
|
|
198
|
+
headers: this.authHeader,
|
|
199
|
+
credentials: "same-origin",
|
|
200
|
+
signal: this.signalSearch
|
|
201
|
+
}).then((h) => h.json()).then((h) => {
|
|
202
|
+
this.dataLayer.setLoading(!1), t(h);
|
|
203
|
+
}).catch((h) => {
|
|
204
|
+
this.dataLayer.setLoading(!1), console.log(h);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
suggest(e, t, s) {
|
|
208
|
+
this.controllerSuggest && this.controllerSuggest.abort(), this.controllerSuggest = new AbortController(), this.signalSuggest = this.controllerSuggest.signal;
|
|
209
|
+
const a = this.suggester + "?q=" + e.trim() + this.toQueryString(s) + "&language=" + this.language;
|
|
210
|
+
fetch(a, {
|
|
211
|
+
method: "GET",
|
|
212
|
+
headers: this.authHeader,
|
|
213
|
+
credentials: "same-origin",
|
|
214
|
+
signal: this.signalSuggest
|
|
215
|
+
}).then((r) => r.json()).then((r) => {
|
|
216
|
+
t(r);
|
|
217
|
+
}).catch((r) => console.log(r));
|
|
218
|
+
}
|
|
219
|
+
fields() {
|
|
220
|
+
return this.fields;
|
|
221
|
+
}
|
|
222
|
+
toQueryString(e) {
|
|
223
|
+
return "&" + e.join("&");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
class F {
|
|
227
|
+
static getOrSetCookie(e) {
|
|
228
|
+
let t = this.getCookie(e);
|
|
229
|
+
return t == null && (t = this.makeid(25), this.setCookie(e, t, {
|
|
230
|
+
secure: !0,
|
|
231
|
+
"max-age": 3600
|
|
232
|
+
})), t;
|
|
233
|
+
}
|
|
234
|
+
static makeid(e) {
|
|
235
|
+
let t = "";
|
|
236
|
+
const s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", a = s.length;
|
|
237
|
+
for (let r = 0; r < e; r++)
|
|
238
|
+
t += s.charAt(Math.floor(Math.random() * a));
|
|
239
|
+
return t;
|
|
240
|
+
}
|
|
241
|
+
static getCookie(e) {
|
|
242
|
+
const t = document.cookie.match(
|
|
243
|
+
new RegExp(
|
|
244
|
+
"(?:^|; )" + e.replace(/([.$?*|{}()[\]\\/+^])/g, "\\$1") + "=([^;]*)"
|
|
245
|
+
)
|
|
246
|
+
);
|
|
247
|
+
return t ? decodeURIComponent(t[1]) : void 0;
|
|
248
|
+
}
|
|
249
|
+
static setCookie(e, t, s) {
|
|
250
|
+
const a = { path: "/", ...s };
|
|
251
|
+
s.expires instanceof Date && (a.expires = s.expires.toUTCString());
|
|
252
|
+
let r = encodeURIComponent(e) + "=" + encodeURIComponent(t);
|
|
253
|
+
for (const n in a) {
|
|
254
|
+
r += "; " + n;
|
|
255
|
+
const h = a[n];
|
|
256
|
+
h !== !0 && (r += "=" + h);
|
|
257
|
+
}
|
|
258
|
+
document.cookie = r;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
class D {
|
|
262
|
+
static trackClick(e) {
|
|
263
|
+
const t = {
|
|
264
|
+
key: e.trackApiKey,
|
|
265
|
+
query: e.searchTermValue,
|
|
266
|
+
shownHits: e.recordsPerPage,
|
|
267
|
+
totalHits: e.totalResults,
|
|
268
|
+
pageNo: e.currentPage,
|
|
269
|
+
latency: e.latencyVal,
|
|
270
|
+
session: e.session,
|
|
271
|
+
cDocId: e.result.uniqueId,
|
|
272
|
+
cDocTitle: e.result.title,
|
|
273
|
+
position: e.result.position,
|
|
274
|
+
language: e.language
|
|
275
|
+
};
|
|
276
|
+
_msq.push(["trackClick", t]);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/*!
|
|
280
|
+
* mustache.js - Logic-less {{mustache}} templates with JavaScript
|
|
281
|
+
* http://github.com/janl/mustache.js
|
|
282
|
+
*/
|
|
283
|
+
var _ = Object.prototype.toString, R = Array.isArray || function(e) {
|
|
284
|
+
return _.call(e) === "[object Array]";
|
|
285
|
+
};
|
|
286
|
+
function M(i) {
|
|
287
|
+
return typeof i == "function";
|
|
288
|
+
}
|
|
289
|
+
function $(i) {
|
|
290
|
+
return R(i) ? "array" : typeof i;
|
|
291
|
+
}
|
|
292
|
+
function V(i) {
|
|
293
|
+
return i.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
|
|
294
|
+
}
|
|
295
|
+
function B(i, e) {
|
|
296
|
+
return i != null && typeof i == "object" && e in i;
|
|
297
|
+
}
|
|
298
|
+
function N(i, e) {
|
|
299
|
+
return i != null && typeof i != "object" && i.hasOwnProperty && i.hasOwnProperty(e);
|
|
300
|
+
}
|
|
301
|
+
var z = RegExp.prototype.test;
|
|
302
|
+
function Q(i, e) {
|
|
303
|
+
return z.call(i, e);
|
|
304
|
+
}
|
|
305
|
+
var G = /\S/;
|
|
306
|
+
function X(i) {
|
|
307
|
+
return !Q(G, i);
|
|
308
|
+
}
|
|
309
|
+
var J = {
|
|
310
|
+
"&": "&",
|
|
311
|
+
"<": "<",
|
|
312
|
+
">": ">",
|
|
313
|
+
'"': """,
|
|
314
|
+
"'": "'",
|
|
315
|
+
"/": "/",
|
|
316
|
+
"`": "`",
|
|
317
|
+
"=": "="
|
|
318
|
+
};
|
|
319
|
+
function Y(i) {
|
|
320
|
+
return String(i).replace(/[&<>"'`=\/]/g, function(t) {
|
|
321
|
+
return J[t];
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
var Z = /\s*/, ee = /\s+/, O = /\s*=/, te = /\s*\}/, se = /#|\^|\/|>|\{|&|=|!/;
|
|
325
|
+
function ae(i, e) {
|
|
326
|
+
if (!i)
|
|
327
|
+
return [];
|
|
328
|
+
var t = !1, s = [], a = [], r = [], n = !1, h = !1, c = "", l = 0;
|
|
329
|
+
function p() {
|
|
330
|
+
if (n && !h)
|
|
331
|
+
for (; r.length; )
|
|
332
|
+
delete a[r.pop()];
|
|
333
|
+
else
|
|
334
|
+
r = [];
|
|
335
|
+
n = !1, h = !1;
|
|
336
|
+
}
|
|
337
|
+
var m, C, H;
|
|
338
|
+
function P(y) {
|
|
339
|
+
if (typeof y == "string" && (y = y.split(ee, 2)), !R(y) || y.length !== 2)
|
|
340
|
+
throw new Error("Invalid tags: " + y);
|
|
341
|
+
m = new RegExp(V(y[0]) + "\\s*"), C = new RegExp("\\s*" + V(y[1])), H = new RegExp("\\s*" + V("}" + y[1]));
|
|
342
|
+
}
|
|
343
|
+
P(e || g.tags);
|
|
344
|
+
for (var o = new T(i), b, f, v, S, x, k; !o.eos(); ) {
|
|
345
|
+
if (b = o.pos, v = o.scanUntil(m), v)
|
|
346
|
+
for (var w = 0, q = v.length; w < q; ++w)
|
|
347
|
+
S = v.charAt(w), X(S) ? (r.push(a.length), c += S) : (h = !0, t = !0, c += " "), a.push(["text", S, b, b + 1]), b += 1, S === `
|
|
348
|
+
` && (p(), c = "", l = 0, t = !1);
|
|
349
|
+
if (!o.scan(m))
|
|
350
|
+
break;
|
|
351
|
+
if (n = !0, f = o.scan(se) || "name", o.scan(Z), f === "=" ? (v = o.scanUntil(O), o.scan(O), o.scanUntil(C)) : f === "{" ? (v = o.scanUntil(H), o.scan(te), o.scanUntil(C), f = "&") : v = o.scanUntil(C), !o.scan(C))
|
|
352
|
+
throw new Error("Unclosed tag at " + o.pos);
|
|
353
|
+
if (f == ">" ? x = [f, v, b, o.pos, c, l, t] : x = [f, v, b, o.pos], l++, a.push(x), f === "#" || f === "^")
|
|
354
|
+
s.push(x);
|
|
355
|
+
else if (f === "/") {
|
|
356
|
+
if (k = s.pop(), !k)
|
|
357
|
+
throw new Error('Unopened section "' + v + '" at ' + b);
|
|
358
|
+
if (k[1] !== v)
|
|
359
|
+
throw new Error('Unclosed section "' + k[1] + '" at ' + b);
|
|
360
|
+
} else
|
|
361
|
+
f === "name" || f === "{" || f === "&" ? h = !0 : f === "=" && P(v);
|
|
362
|
+
}
|
|
363
|
+
if (p(), k = s.pop(), k)
|
|
364
|
+
throw new Error('Unclosed section "' + k[1] + '" at ' + o.pos);
|
|
365
|
+
return ie(re(a));
|
|
366
|
+
}
|
|
367
|
+
function re(i) {
|
|
368
|
+
for (var e = [], t, s, a = 0, r = i.length; a < r; ++a)
|
|
369
|
+
t = i[a], t && (t[0] === "text" && s && s[0] === "text" ? (s[1] += t[1], s[3] = t[3]) : (e.push(t), s = t));
|
|
370
|
+
return e;
|
|
371
|
+
}
|
|
372
|
+
function ie(i) {
|
|
373
|
+
for (var e = [], t = e, s = [], a, r, n = 0, h = i.length; n < h; ++n)
|
|
374
|
+
switch (a = i[n], a[0]) {
|
|
375
|
+
case "#":
|
|
376
|
+
case "^":
|
|
377
|
+
t.push(a), s.push(a), t = a[4] = [];
|
|
378
|
+
break;
|
|
379
|
+
case "/":
|
|
380
|
+
r = s.pop(), r[5] = a[2], t = s.length > 0 ? s[s.length - 1][4] : e;
|
|
381
|
+
break;
|
|
382
|
+
default:
|
|
383
|
+
t.push(a);
|
|
384
|
+
}
|
|
385
|
+
return e;
|
|
386
|
+
}
|
|
387
|
+
function T(i) {
|
|
388
|
+
this.string = i, this.tail = i, this.pos = 0;
|
|
389
|
+
}
|
|
390
|
+
T.prototype.eos = function() {
|
|
391
|
+
return this.tail === "";
|
|
392
|
+
};
|
|
393
|
+
T.prototype.scan = function(e) {
|
|
394
|
+
var t = this.tail.match(e);
|
|
395
|
+
if (!t || t.index !== 0)
|
|
396
|
+
return "";
|
|
397
|
+
var s = t[0];
|
|
398
|
+
return this.tail = this.tail.substring(s.length), this.pos += s.length, s;
|
|
399
|
+
};
|
|
400
|
+
T.prototype.scanUntil = function(e) {
|
|
401
|
+
var t = this.tail.search(e), s;
|
|
402
|
+
switch (t) {
|
|
403
|
+
case -1:
|
|
404
|
+
s = this.tail, this.tail = "";
|
|
405
|
+
break;
|
|
406
|
+
case 0:
|
|
407
|
+
s = "";
|
|
408
|
+
break;
|
|
409
|
+
default:
|
|
410
|
+
s = this.tail.substring(0, t), this.tail = this.tail.substring(t);
|
|
411
|
+
}
|
|
412
|
+
return this.pos += s.length, s;
|
|
413
|
+
};
|
|
414
|
+
function I(i, e) {
|
|
415
|
+
this.view = i, this.cache = { ".": this.view }, this.parent = e;
|
|
416
|
+
}
|
|
417
|
+
I.prototype.push = function(e) {
|
|
418
|
+
return new I(e, this);
|
|
419
|
+
};
|
|
420
|
+
I.prototype.lookup = function(e) {
|
|
421
|
+
var t = this.cache, s;
|
|
422
|
+
if (t.hasOwnProperty(e))
|
|
423
|
+
s = t[e];
|
|
424
|
+
else {
|
|
425
|
+
for (var a = this, r, n, h, c = !1; a; ) {
|
|
426
|
+
if (e.indexOf(".") > 0)
|
|
427
|
+
for (r = a.view, n = e.split("."), h = 0; r != null && h < n.length; )
|
|
428
|
+
h === n.length - 1 && (c = B(r, n[h]) || N(r, n[h])), r = r[n[h++]];
|
|
429
|
+
else
|
|
430
|
+
r = a.view[e], c = B(a.view, e);
|
|
431
|
+
if (c) {
|
|
432
|
+
s = r;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
a = a.parent;
|
|
436
|
+
}
|
|
437
|
+
t[e] = s;
|
|
438
|
+
}
|
|
439
|
+
return M(s) && (s = s.call(this.view)), s;
|
|
440
|
+
};
|
|
441
|
+
function d() {
|
|
442
|
+
this.templateCache = {
|
|
443
|
+
_cache: {},
|
|
444
|
+
set: function(e, t) {
|
|
445
|
+
this._cache[e] = t;
|
|
446
|
+
},
|
|
447
|
+
get: function(e) {
|
|
448
|
+
return this._cache[e];
|
|
449
|
+
},
|
|
450
|
+
clear: function() {
|
|
451
|
+
this._cache = {};
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
d.prototype.clearCache = function() {
|
|
456
|
+
typeof this.templateCache < "u" && this.templateCache.clear();
|
|
457
|
+
};
|
|
458
|
+
d.prototype.parse = function(e, t) {
|
|
459
|
+
var s = this.templateCache, a = e + ":" + (t || g.tags).join(":"), r = typeof s < "u", n = r ? s.get(a) : void 0;
|
|
460
|
+
return n == null && (n = ae(e, t), r && s.set(a, n)), n;
|
|
461
|
+
};
|
|
462
|
+
d.prototype.render = function(e, t, s, a) {
|
|
463
|
+
var r = this.getConfigTags(a), n = this.parse(e, r), h = t instanceof I ? t : new I(t, void 0);
|
|
464
|
+
return this.renderTokens(n, h, s, e, a);
|
|
465
|
+
};
|
|
466
|
+
d.prototype.renderTokens = function(e, t, s, a, r) {
|
|
467
|
+
for (var n = "", h, c, l, p = 0, m = e.length; p < m; ++p)
|
|
468
|
+
l = void 0, h = e[p], c = h[0], c === "#" ? l = this.renderSection(h, t, s, a, r) : c === "^" ? l = this.renderInverted(h, t, s, a, r) : c === ">" ? l = this.renderPartial(h, t, s, r) : c === "&" ? l = this.unescapedValue(h, t) : c === "name" ? l = this.escapedValue(h, t, r) : c === "text" && (l = this.rawValue(h)), l !== void 0 && (n += l);
|
|
469
|
+
return n;
|
|
470
|
+
};
|
|
471
|
+
d.prototype.renderSection = function(e, t, s, a, r) {
|
|
472
|
+
var n = this, h = "", c = t.lookup(e[1]);
|
|
473
|
+
function l(C) {
|
|
474
|
+
return n.render(C, t, s, r);
|
|
475
|
+
}
|
|
476
|
+
if (c) {
|
|
477
|
+
if (R(c))
|
|
478
|
+
for (var p = 0, m = c.length; p < m; ++p)
|
|
479
|
+
h += this.renderTokens(e[4], t.push(c[p]), s, a, r);
|
|
480
|
+
else if (typeof c == "object" || typeof c == "string" || typeof c == "number")
|
|
481
|
+
h += this.renderTokens(e[4], t.push(c), s, a, r);
|
|
482
|
+
else if (M(c)) {
|
|
483
|
+
if (typeof a != "string")
|
|
484
|
+
throw new Error("Cannot use higher-order sections without the original template");
|
|
485
|
+
c = c.call(t.view, a.slice(e[3], e[5]), l), c != null && (h += c);
|
|
486
|
+
} else
|
|
487
|
+
h += this.renderTokens(e[4], t, s, a, r);
|
|
488
|
+
return h;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
d.prototype.renderInverted = function(e, t, s, a, r) {
|
|
492
|
+
var n = t.lookup(e[1]);
|
|
493
|
+
if (!n || R(n) && n.length === 0)
|
|
494
|
+
return this.renderTokens(e[4], t, s, a, r);
|
|
495
|
+
};
|
|
496
|
+
d.prototype.indentPartial = function(e, t, s) {
|
|
497
|
+
for (var a = t.replace(/[^ \t]/g, ""), r = e.split(`
|
|
498
|
+
`), n = 0; n < r.length; n++)
|
|
499
|
+
r[n].length && (n > 0 || !s) && (r[n] = a + r[n]);
|
|
500
|
+
return r.join(`
|
|
501
|
+
`);
|
|
502
|
+
};
|
|
503
|
+
d.prototype.renderPartial = function(e, t, s, a) {
|
|
504
|
+
if (s) {
|
|
505
|
+
var r = this.getConfigTags(a), n = M(s) ? s(e[1]) : s[e[1]];
|
|
506
|
+
if (n != null) {
|
|
507
|
+
var h = e[6], c = e[5], l = e[4], p = n;
|
|
508
|
+
c == 0 && l && (p = this.indentPartial(n, l, h));
|
|
509
|
+
var m = this.parse(p, r);
|
|
510
|
+
return this.renderTokens(m, t, s, p, a);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
d.prototype.unescapedValue = function(e, t) {
|
|
515
|
+
var s = t.lookup(e[1]);
|
|
516
|
+
if (s != null)
|
|
517
|
+
return s;
|
|
518
|
+
};
|
|
519
|
+
d.prototype.escapedValue = function(e, t, s) {
|
|
520
|
+
var a = this.getConfigEscape(s) || g.escape, r = t.lookup(e[1]);
|
|
521
|
+
if (r != null)
|
|
522
|
+
return typeof r == "number" && a === g.escape ? String(r) : a(r);
|
|
523
|
+
};
|
|
524
|
+
d.prototype.rawValue = function(e) {
|
|
525
|
+
return e[1];
|
|
526
|
+
};
|
|
527
|
+
d.prototype.getConfigTags = function(e) {
|
|
528
|
+
return R(e) ? e : e && typeof e == "object" ? e.tags : void 0;
|
|
529
|
+
};
|
|
530
|
+
d.prototype.getConfigEscape = function(e) {
|
|
531
|
+
if (e && typeof e == "object" && !R(e))
|
|
532
|
+
return e.escape;
|
|
533
|
+
};
|
|
534
|
+
var g = {
|
|
535
|
+
name: "mustache.js",
|
|
536
|
+
version: "4.2.0",
|
|
537
|
+
tags: ["{{", "}}"],
|
|
538
|
+
clearCache: void 0,
|
|
539
|
+
escape: void 0,
|
|
540
|
+
parse: void 0,
|
|
541
|
+
render: void 0,
|
|
542
|
+
Scanner: void 0,
|
|
543
|
+
Context: void 0,
|
|
544
|
+
Writer: void 0,
|
|
545
|
+
/**
|
|
546
|
+
* Allows a user to override the default caching strategy, by providing an
|
|
547
|
+
* object with set, get and clear methods. This can also be used to disable
|
|
548
|
+
* the cache by setting it to the literal `undefined`.
|
|
549
|
+
*/
|
|
550
|
+
set templateCache(i) {
|
|
551
|
+
L.templateCache = i;
|
|
552
|
+
},
|
|
553
|
+
/**
|
|
554
|
+
* Gets the default or overridden caching object from the default writer.
|
|
555
|
+
*/
|
|
556
|
+
get templateCache() {
|
|
557
|
+
return L.templateCache;
|
|
558
|
+
}
|
|
559
|
+
}, L = new d();
|
|
560
|
+
g.clearCache = function() {
|
|
561
|
+
return L.clearCache();
|
|
562
|
+
};
|
|
563
|
+
g.parse = function(e, t) {
|
|
564
|
+
return L.parse(e, t);
|
|
565
|
+
};
|
|
566
|
+
g.render = function(e, t, s, a) {
|
|
567
|
+
if (typeof e != "string")
|
|
568
|
+
throw new TypeError('Invalid template! Template should be a "string" but "' + $(e) + '" was given as the first argument for mustache#render(template, view, partials)');
|
|
569
|
+
return L.render(e, t, s, a);
|
|
570
|
+
};
|
|
571
|
+
g.escape = Y;
|
|
572
|
+
g.Scanner = T;
|
|
573
|
+
g.Context = I;
|
|
574
|
+
g.Writer = d;
|
|
575
|
+
class ne {
|
|
576
|
+
constructor(e) {
|
|
577
|
+
u(this, "dataLayer");
|
|
578
|
+
u(this, "config");
|
|
579
|
+
u(this, "suggestAfterMinChars");
|
|
580
|
+
u(this, "hideBranding");
|
|
581
|
+
u(this, "containerId");
|
|
582
|
+
u(this, "currentInputValue", "");
|
|
583
|
+
u(this, "autosuggestResults");
|
|
584
|
+
u(this, "searchInput");
|
|
585
|
+
u(this, "actionButton");
|
|
586
|
+
u(this, "autosuggestContainer");
|
|
587
|
+
u(this, "buttonState", "search");
|
|
588
|
+
u(this, "selectedAutosuggestItem", -1);
|
|
589
|
+
u(this, "suggestTrigger");
|
|
590
|
+
u(this, "searchTrigger");
|
|
591
|
+
this.dataLayer = e.dataLayer, this.config = e.config, this.searchTrigger = e.searchTrigger, this.suggestTrigger = e.suggestTrigger, this.containerId = e.containerId, this.suggestAfterMinChars = e.config.suggestAfterMinChars, this.hideBranding = e.config.hideBranding, this.renderMainTemplate(), this.actionButtonInit(), this.updateActionButtonState("search"), this.searchInput && (this.createAutosuggestContainer(), this.attachSubscriptions());
|
|
592
|
+
}
|
|
593
|
+
renderMainTemplate() {
|
|
594
|
+
var r, n;
|
|
595
|
+
const e = document.getElementById(this.containerId);
|
|
596
|
+
if (!e)
|
|
597
|
+
throw new Error("Search input container not found");
|
|
598
|
+
const t = ((r = this.config.templates) == null ? void 0 : r.mainTemplate) || `
|
|
599
|
+
<div class="searchstax-search-input-container">
|
|
600
|
+
<div class="searchstax-search-input-wrapper">
|
|
601
|
+
<input type="text" id="searchstax-search-input" class="searchstax-search-input" placeholder="SEARCH FOR..." />
|
|
602
|
+
<button class="searchstax-spinner-icon" id="searchstax-search-input-action-button"></button>
|
|
603
|
+
</div>
|
|
604
|
+
</div>
|
|
605
|
+
`;
|
|
606
|
+
if (console.log(
|
|
607
|
+
"this.dataLayer.renderingEngineValue",
|
|
608
|
+
this.dataLayer.renderingEngineValue
|
|
609
|
+
), this.dataLayer.renderingEngineValue === "mustache") {
|
|
610
|
+
const h = g.render(t, {});
|
|
611
|
+
e.innerHTML = h;
|
|
612
|
+
}
|
|
613
|
+
const s = ((n = this.config.templates) == null ? void 0 : n.searchInputId) || "searchstax-search-input", a = document.querySelector(`#${s}`);
|
|
614
|
+
if (a)
|
|
615
|
+
this.searchInput = a, a.addEventListener("keyup", this.inputKeyupEvent.bind(this)), a.addEventListener("blur", this.hideAutosuggest.bind(this)), a.addEventListener("paste", this.inputPasteEvent.bind(this));
|
|
616
|
+
else
|
|
617
|
+
throw new Error("Input not found");
|
|
618
|
+
}
|
|
619
|
+
createAutosuggestContainer() {
|
|
620
|
+
var e;
|
|
621
|
+
this.autosuggestContainer = document.createElement("div"), this.autosuggestContainer.classList.add("searchstax-autosuggest-container"), this.autosuggestContainer.addEventListener("mouseleave", () => {
|
|
622
|
+
this.resetAutosuggestSelection(), this.markActiveAutosuggestItem();
|
|
623
|
+
}), (e = this.searchInput) == null || e.after(this.autosuggestContainer);
|
|
624
|
+
}
|
|
625
|
+
actionButtonInit() {
|
|
626
|
+
this.actionButton = document.getElementById(
|
|
627
|
+
"searchstax-search-input-action-button"
|
|
628
|
+
), this.actionButton && this.actionButton.addEventListener("click", () => {
|
|
629
|
+
var e;
|
|
630
|
+
this.buttonState === "search" ? this.executeSearch(((e = this.searchInput) == null ? void 0 : e.value) ?? "") : this.buttonState === "close" && this.searchInput && (this.searchInput.value = "", this.executeSearch(""));
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
attachSubscriptions() {
|
|
634
|
+
this.dataLayer.searchTermChangeObservable.subscribe(() => {
|
|
635
|
+
this.handleSearchTermChange();
|
|
636
|
+
}), this.dataLayer.loadingChangeObservable.subscribe(() => {
|
|
637
|
+
this.handleLoadingChange();
|
|
638
|
+
}), this.dataLayer.searchAutosuggestObservable.subscribe(
|
|
639
|
+
(e) => {
|
|
640
|
+
e && this.appendSuggestions(e);
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
handleLoadingChange() {
|
|
645
|
+
this.dataLayer.loadingValue ? this.updateActionButtonState("loading") : this.handleSearchTermChange();
|
|
646
|
+
}
|
|
647
|
+
handleSearchTermChange() {
|
|
648
|
+
var e;
|
|
649
|
+
this.dataLayer.searchTermValue === ((e = this.searchInput) == null ? void 0 : e.value) && this.searchInput.value !== "" ? this.updateActionButtonState("close") : this.updateActionButtonState("search");
|
|
650
|
+
}
|
|
651
|
+
updateActionButtonState(e) {
|
|
652
|
+
if (this.buttonState = e, this.actionButton)
|
|
653
|
+
switch (this.actionButton.classList.remove("searchstax-spinner-icon"), this.actionButton.classList.remove("searchstax-search-close"), this.actionButton.classList.remove("searchstax-search-icon"), e) {
|
|
654
|
+
case "loading":
|
|
655
|
+
this.actionButton.classList.add("searchstax-spinner-icon");
|
|
656
|
+
break;
|
|
657
|
+
case "search":
|
|
658
|
+
this.actionButton.classList.add("searchstax-search-icon");
|
|
659
|
+
break;
|
|
660
|
+
case "close":
|
|
661
|
+
this.actionButton.classList.add("searchstax-search-close");
|
|
662
|
+
break;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
selectPreviousAutosuggestItem() {
|
|
666
|
+
this.selectedAutosuggestItem > 0 ? this.selectedAutosuggestItem-- : this.selectedAutosuggestItem = this.autosuggestResults.suggestions.length - 1, this.markActiveAutosuggestItem();
|
|
667
|
+
}
|
|
668
|
+
selectNextAutosuggestItem() {
|
|
669
|
+
this.selectedAutosuggestItem < this.autosuggestResults.suggestions.length - 1 ? this.selectedAutosuggestItem++ : this.selectedAutosuggestItem = 0, this.markActiveAutosuggestItem();
|
|
670
|
+
}
|
|
671
|
+
resetAutosuggestSelection() {
|
|
672
|
+
this.selectedAutosuggestItem = -1, this.markActiveAutosuggestItem();
|
|
673
|
+
}
|
|
674
|
+
markActiveAutosuggestItem() {
|
|
675
|
+
const e = document.getElementsByClassName(
|
|
676
|
+
"searchstax-autosuggest-item"
|
|
677
|
+
);
|
|
678
|
+
for (let t = 0; t < e.length; t++) {
|
|
679
|
+
const s = e[t];
|
|
680
|
+
t === this.selectedAutosuggestItem ? s.classList.add("active") : s.classList.remove("active");
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
inputKeyupEvent(e) {
|
|
684
|
+
const t = e.key;
|
|
685
|
+
this.currentInputValue = e.target.value, t === "Enter" ? this.suggestionChosen() : t === "Escape" ? this.hideAutosuggest() : t === "ArrowUp" ? this.selectPreviousAutosuggestItem() : t === "ArrowDown" ? this.selectNextAutosuggestItem() : this.autosuggestHandling(e), this.handleSearchTermChange();
|
|
686
|
+
}
|
|
687
|
+
autosuggestHandling(e) {
|
|
688
|
+
e.target && e.target.value.length >= this.suggestAfterMinChars ? this.executeSuggest(e.target.value) : this.hideAutosuggest();
|
|
689
|
+
}
|
|
690
|
+
inputPasteEvent(e) {
|
|
691
|
+
setTimeout(() => {
|
|
692
|
+
this.autosuggestHandling(e), this.handleSearchTermChange();
|
|
693
|
+
}, 0);
|
|
694
|
+
}
|
|
695
|
+
executeSuggest(e) {
|
|
696
|
+
this.suggestTrigger(e);
|
|
697
|
+
}
|
|
698
|
+
executeSearch(e) {
|
|
699
|
+
this.hideAutosuggest(), this.searchTrigger(e === "" ? "*" : e);
|
|
700
|
+
}
|
|
701
|
+
suggestionChosen() {
|
|
702
|
+
this.selectedAutosuggestItem > -1 ? this.autosuggestItemClicked(
|
|
703
|
+
this.autosuggestResults.suggestions[this.selectedAutosuggestItem]
|
|
704
|
+
) : this.executeSearch(this.currentInputValue);
|
|
705
|
+
}
|
|
706
|
+
hideAutosuggest() {
|
|
707
|
+
this.autosuggestContainer && (this.autosuggestContainer.innerHTML = "", this.autosuggestContainer.classList.add("hidden")), this.resetAutosuggestSelection();
|
|
708
|
+
}
|
|
709
|
+
cleanSuggestionTerm(e) {
|
|
710
|
+
return e.replace(/(<([^>]+)>)/gi, "").trim();
|
|
711
|
+
}
|
|
712
|
+
autosuggestItemClicked(e) {
|
|
713
|
+
this.searchInput.value = this.cleanSuggestionTerm(e.term), this.executeSearch(this.cleanSuggestionTerm(e.term));
|
|
714
|
+
}
|
|
715
|
+
createAutosuggestItem(e) {
|
|
716
|
+
var a;
|
|
717
|
+
const t = document.createElement("div");
|
|
718
|
+
t.classList.add("searchstax-autosuggest-item"), t.addEventListener("click", () => {
|
|
719
|
+
this.autosuggestItemClicked(e);
|
|
720
|
+
}), t.addEventListener("mouseenter", () => {
|
|
721
|
+
var r;
|
|
722
|
+
this.selectedAutosuggestItem = ((r = this.autosuggestResults) == null ? void 0 : r.suggestions.indexOf(e)) || 0, this.markActiveAutosuggestItem();
|
|
723
|
+
});
|
|
724
|
+
const s = ((a = this.config.templates) == null ? void 0 : a.autosuggestItemTemplate) || '<div class="searchstax-autosuggest-item-term-container">{{{term}}}</div>';
|
|
725
|
+
return t.innerHTML = g.render(s, e), t;
|
|
726
|
+
}
|
|
727
|
+
appendSuggestions(e) {
|
|
728
|
+
if (this.autosuggestContainer) {
|
|
729
|
+
this.autosuggestContainer.innerHTML = "", this.autosuggestContainer.classList.remove("hidden");
|
|
730
|
+
for (const t in e.suggest)
|
|
731
|
+
if (Object.prototype.hasOwnProperty.call(e.suggest, t)) {
|
|
732
|
+
const s = e.suggest[t];
|
|
733
|
+
for (const a in s)
|
|
734
|
+
if (Object.prototype.hasOwnProperty.call(s, a)) {
|
|
735
|
+
const r = s[a];
|
|
736
|
+
this.autosuggestResults = r, r.numFound > 0 ? r.suggestions.forEach((n) => {
|
|
737
|
+
this.autosuggestContainer.appendChild(
|
|
738
|
+
this.createAutosuggestItem(n)
|
|
739
|
+
);
|
|
740
|
+
}) : this.autosuggestContainer.classList.add("hidden");
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
class ue {
|
|
747
|
+
constructor(e) {
|
|
748
|
+
u(this, "dataLayer");
|
|
749
|
+
u(this, "config");
|
|
750
|
+
u(this, "linkClickCallback");
|
|
751
|
+
u(this, "searchCallback");
|
|
752
|
+
u(this, "containerId");
|
|
753
|
+
u(this, "searchResultsMainContainer");
|
|
754
|
+
u(this, "searchResultsContainer");
|
|
755
|
+
u(this, "searchResultLinks", []);
|
|
756
|
+
this.linkClickCallback = e.linkClickCallback, this.searchCallback = e.searchTrigger, this.dataLayer = e.dataLayer, this.config = e.config, this.containerId = e.containerId;
|
|
757
|
+
const t = document.getElementById(this.containerId);
|
|
758
|
+
if (console.log("resultsContainer", t), t)
|
|
759
|
+
this.searchResultsMainContainer = t;
|
|
760
|
+
else
|
|
761
|
+
throw new Error(
|
|
762
|
+
`Search Results Main Container with id ${this.containerId} not found`
|
|
763
|
+
);
|
|
764
|
+
this.initializeSubscriptions(), this.renderMainTemplate();
|
|
765
|
+
}
|
|
766
|
+
initializeSubscriptions() {
|
|
767
|
+
this.dataLayer.searchResultsObservable.subscribe((e) => {
|
|
768
|
+
e && this.searchResultsContainer && this.renderResults(e);
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
renderNoResultsTemplate() {
|
|
772
|
+
var s, a, r;
|
|
773
|
+
const e = ((a = (s = this.config) == null ? void 0 : s.templates) == null ? void 0 : a.noSearchResultTemplate) || `
|
|
774
|
+
<div class="searchstax-no-results">
|
|
775
|
+
Showing <strong>no results</strong> for <strong>"{{ searchTerm }}"</strong>
|
|
776
|
+
<br>
|
|
777
|
+
{{#spellingSuggestion}}
|
|
778
|
+
<span> Did you mean <a href="#"
|
|
779
|
+
class="searchstax-suggestion-term">{{ spellingSuggestion }}</a>?</span>
|
|
780
|
+
{{/spellingSuggestion}}
|
|
781
|
+
</div>
|
|
782
|
+
<div>
|
|
783
|
+
<p>Try searching for search related terms or topics. We offer a wide variety of content to help you get the information you need.</p>
|
|
784
|
+
<p>Lost? Click on the ‘X” in the Search Box to reset your search.</p>
|
|
785
|
+
</div>
|
|
786
|
+
`, t = ((r = this.dataLayer.searchResultsMetadataValue) == null ? void 0 : r.spellingSuggestion) ?? "";
|
|
787
|
+
if (this.dataLayer.renderingEngineValue === "mustache" && this.searchResultsContainer && (this.searchResultsContainer.innerHTML = g.render(
|
|
788
|
+
e,
|
|
789
|
+
{
|
|
790
|
+
spellingSuggestion: t,
|
|
791
|
+
searchTerm: this.dataLayer.searchTermValue
|
|
792
|
+
}
|
|
793
|
+
)), t && this.searchResultsContainer) {
|
|
794
|
+
const n = this.searchResultsContainer.querySelector("a");
|
|
795
|
+
n && n.addEventListener("click", (h) => {
|
|
796
|
+
h.preventDefault(), h.stopPropagation(), this.searchCallback(t);
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
renderResults(e) {
|
|
801
|
+
var t, s;
|
|
802
|
+
if (this.dataLayer.renderingEngineValue === "mustache" && this.searchResultsContainer)
|
|
803
|
+
if (this.removeLinkClickEvents(), e.length === 0)
|
|
804
|
+
this.renderNoResultsTemplate();
|
|
805
|
+
else {
|
|
806
|
+
const a = ((s = (t = this.config) == null ? void 0 : t.templates) == null ? void 0 : s.searchResultTemplate) || `
|
|
807
|
+
<div class="searchstax-search-result">
|
|
808
|
+
{{#url}}
|
|
809
|
+
<a href="{{url}}" data-searchstax-unique-result-id="{{uniqueId}}" class="searchstax-result-item-link"></a>
|
|
810
|
+
{{/url}}
|
|
811
|
+
{{#ribbon}}
|
|
812
|
+
<div class="searchstax-search-result-ribbon">
|
|
813
|
+
{{ribbon}}
|
|
814
|
+
</div>
|
|
815
|
+
{{/ribbon}}
|
|
816
|
+
{{#thumbnail}}
|
|
817
|
+
<img :src="thumbnail" class="searchstax-thumbnail">
|
|
818
|
+
{{/thumbnail}}
|
|
819
|
+
<div class="searchstax-search-result-title-container">
|
|
820
|
+
<span class="searchstax-search-result-title">{{title}}</span>
|
|
821
|
+
</div>
|
|
822
|
+
{{#paths}}
|
|
823
|
+
<p class="searchstax-search-result-common">
|
|
824
|
+
{{paths}}
|
|
825
|
+
</p>
|
|
826
|
+
{{/paths}}
|
|
827
|
+
{{#description}}
|
|
828
|
+
<p class="searchstax-search-result-description searchstax-search-result-common">
|
|
829
|
+
{{description}}
|
|
830
|
+
</p>
|
|
831
|
+
{{/description}}
|
|
832
|
+
{{#unmappedFields}}
|
|
833
|
+
{{#isImage}}
|
|
834
|
+
<div class="searchstax-search-result-image-container">
|
|
835
|
+
<img :src="result[value]" class="searchstax-result-image">
|
|
836
|
+
</div>
|
|
837
|
+
{{/isImage}}
|
|
838
|
+
{{^isImage}}
|
|
839
|
+
<p class="searchstax-search-result-common">
|
|
840
|
+
{{value}}
|
|
841
|
+
</p>
|
|
842
|
+
{{/isImage}}
|
|
843
|
+
{{/unmappedFields}}
|
|
844
|
+
</div>`, r = e.map((n) => g.render(a, n));
|
|
845
|
+
this.searchResultsContainer.innerHTML = r.join(""), this.searchResultLinks = Array.from(
|
|
846
|
+
this.searchResultsContainer.querySelectorAll(
|
|
847
|
+
`[${this.uniqueIdAttribute}]`
|
|
848
|
+
)
|
|
849
|
+
), this.attachLinkClickEvents();
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
removeLinkClickEvents() {
|
|
853
|
+
this.searchResultLinks.forEach((e) => {
|
|
854
|
+
e.removeEventListener("click", () => {
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
get uniqueIdAttribute() {
|
|
859
|
+
return this.config.searchResultUniqueIdAttribute || "data-searchstax-unique-result-id";
|
|
860
|
+
}
|
|
861
|
+
attachLinkClickEvents() {
|
|
862
|
+
this.searchResultLinks.forEach((e) => {
|
|
863
|
+
e.addEventListener("click", (t) => {
|
|
864
|
+
t.preventDefault(), t.stopPropagation();
|
|
865
|
+
const s = e.getAttribute(this.uniqueIdAttribute) ?? "";
|
|
866
|
+
s && this.linkClickCallback(s);
|
|
867
|
+
});
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
renderMainTemplate() {
|
|
871
|
+
var t, s;
|
|
872
|
+
const e = ((s = (t = this.config) == null ? void 0 : t.templates) == null ? void 0 : s.mainTemplate) || `
|
|
873
|
+
<div class="searchstax-search-results-container">
|
|
874
|
+
<div class="searchstax-search-results"></div>
|
|
875
|
+
</div>
|
|
876
|
+
`;
|
|
877
|
+
this.dataLayer.renderingEngineValue === "mustache" && (this.searchResultsMainContainer.innerHTML = g.render(
|
|
878
|
+
e,
|
|
879
|
+
{}
|
|
880
|
+
)), setTimeout(() => {
|
|
881
|
+
var n, h;
|
|
882
|
+
const a = (n = this.config) != null && n.searchResultsContainerId ? (h = this.config) == null ? void 0 : h.searchResultsContainerId : "searchstax-search-results", r = document.getElementById(a);
|
|
883
|
+
if (r)
|
|
884
|
+
this.searchResultsContainer = r;
|
|
885
|
+
else
|
|
886
|
+
throw new Error(`Search Results Container with id ${a} not found`);
|
|
887
|
+
}, 0);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
class ce {
|
|
891
|
+
constructor(e = "mustache") {
|
|
892
|
+
u(this, "sessionId");
|
|
893
|
+
u(this, "searchstaxConfig");
|
|
894
|
+
u(this, "searchHelper");
|
|
895
|
+
u(this, "searchInputConfig");
|
|
896
|
+
u(this, "searchResultsConfig");
|
|
897
|
+
u(this, "searchInputWidget");
|
|
898
|
+
u(this, "searchResultsWidget");
|
|
899
|
+
u(this, "dataLayer", new j());
|
|
900
|
+
e && this.dataLayer.setRenderingEngine(e), this.sessionId = F.getOrSetCookie("searchstax_session_id"), this.handleHooks();
|
|
901
|
+
}
|
|
902
|
+
setRenderingEngine(e = "mustache") {
|
|
903
|
+
this.dataLayer.setRenderingEngine(e);
|
|
904
|
+
}
|
|
905
|
+
handleHooks() {
|
|
906
|
+
var e, t;
|
|
907
|
+
(t = (e = this.searchInputConfig) == null ? void 0 : e.hooks) != null && t.afterSearch && this.dataLayer.searchResultsObservable.subscribe((s) => {
|
|
908
|
+
this.searchInputConfig.hooks.afterSearch(s);
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
initialize(e) {
|
|
912
|
+
this.searchstaxConfig || (this.searchstaxConfig = e, this.searchHelper = new W(
|
|
913
|
+
{ ...e, sessionId: this.sessionId },
|
|
914
|
+
this.dataLayer
|
|
915
|
+
));
|
|
916
|
+
}
|
|
917
|
+
search(e, t) {
|
|
918
|
+
this.searchHelper && this.searchHelper.search(
|
|
919
|
+
e,
|
|
920
|
+
this.parseSearchResultsResponse.bind(this),
|
|
921
|
+
t
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
parseSearchResultsResponse(e) {
|
|
925
|
+
var s, a;
|
|
926
|
+
let t = E.combineResultsWithMetadata(e);
|
|
927
|
+
(a = (s = this.searchInputConfig) == null ? void 0 : s.hooks) != null && a.afterSearch && (t = this.searchInputConfig.hooks.afterSearch(t)), this.dataLayer.setSearchResults(t), this.dataLayer.setSearchResultsMetadata(
|
|
928
|
+
E.extractSearchResultsMetadata(e)
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
parseSuggestSuggestResponse(e) {
|
|
932
|
+
var s, a;
|
|
933
|
+
let t = e;
|
|
934
|
+
(a = (s = this.searchInputConfig) == null ? void 0 : s.hooks) != null && a.afterAutosuggest && (t = this.searchInputConfig.hooks.afterAutosuggest(e)), this.dataLayer.setSearchAutosuggest(t);
|
|
935
|
+
}
|
|
936
|
+
suggest(e, t) {
|
|
937
|
+
this.searchHelper && this.searchHelper.suggest(
|
|
938
|
+
e,
|
|
939
|
+
this.parseSuggestSuggestResponse.bind(this),
|
|
940
|
+
t
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
changeLanguage(e) {
|
|
944
|
+
this.searchHelper && (this.searchHelper.language = e);
|
|
945
|
+
}
|
|
946
|
+
addSearchInputWidget(e, t) {
|
|
947
|
+
this.searchInputConfig || (this.searchInputConfig = t, this.searchInputWidget = new ne({
|
|
948
|
+
containerId: e,
|
|
949
|
+
config: t,
|
|
950
|
+
searchTrigger: this.executeSearch.bind(this),
|
|
951
|
+
suggestTrigger: this.executeSuggest.bind(this),
|
|
952
|
+
dataLayer: this.dataLayer
|
|
953
|
+
}));
|
|
954
|
+
}
|
|
955
|
+
addSearchResultsWidget(e, t) {
|
|
956
|
+
this.searchResultsConfig || (this.searchResultsConfig = t, this.searchResultsWidget = new ue({
|
|
957
|
+
containerId: e,
|
|
958
|
+
linkClickCallback: this.executeLinkClick.bind(this),
|
|
959
|
+
searchTrigger: this.executeSearch.bind(this),
|
|
960
|
+
config: t,
|
|
961
|
+
dataLayer: this.dataLayer
|
|
962
|
+
}));
|
|
963
|
+
}
|
|
964
|
+
executeSearch(e) {
|
|
965
|
+
var s, a;
|
|
966
|
+
let t = { term: e, queryParams: [] };
|
|
967
|
+
(a = (s = this.searchInputConfig) == null ? void 0 : s.hooks) != null && a.beforeSearch && (t = this.searchInputConfig.hooks.beforeSearch(t)), t && t.term !== void 0 && t.queryParams !== void 0 && this.search(t.term, t.queryParams);
|
|
968
|
+
}
|
|
969
|
+
executeSuggest(e) {
|
|
970
|
+
var s, a;
|
|
971
|
+
let t = { term: e, queryParams: [] };
|
|
972
|
+
(a = (s = this.searchInputConfig) == null ? void 0 : s.hooks) != null && a.beforeAutosuggest && (t = this.searchInputConfig.hooks.beforeAutosuggest(t)), t && t.term !== void 0 && t.queryParams !== void 0 && this.suggest(t.term, t.queryParams);
|
|
973
|
+
}
|
|
974
|
+
executeLinkClick(e) {
|
|
975
|
+
var s, a, r, n;
|
|
976
|
+
let t = E.findResultByUniqueId(
|
|
977
|
+
e,
|
|
978
|
+
this.dataLayer.searchResultsValue ?? []
|
|
979
|
+
);
|
|
980
|
+
t && ((a = (s = this.searchResultsConfig) == null ? void 0 : s.hooks) != null && a.afterLinkClick && (t = this.searchResultsConfig.hooks.afterLinkClick(t)), t && (console.log("foundResult", t), this.dataLayer.searchResultsMetadataValue && D.trackClick({
|
|
981
|
+
result: t,
|
|
982
|
+
searchTermValue: this.dataLayer.searchTermValue,
|
|
983
|
+
trackApiKey: ((r = this.searchstaxConfig) == null ? void 0 : r.trackApiKey) ?? "",
|
|
984
|
+
session: this.sessionId,
|
|
985
|
+
language: ((n = this.searchHelper) == null ? void 0 : n.language) ?? "",
|
|
986
|
+
recordsPerPage: this.dataLayer.searchResultsMetadataValue.recordsPerPageValue,
|
|
987
|
+
totalResults: this.dataLayer.searchResultsMetadataValue.totalResultsValue,
|
|
988
|
+
currentPage: this.dataLayer.currentPageValue,
|
|
989
|
+
latencyVal: this.dataLayer.searchResultsMetadataValue.latency
|
|
990
|
+
})));
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
export {
|
|
994
|
+
ce as Searchstax
|
|
995
|
+
};
|