@bridgeline-digital/hawksearch-handlebars-ui 1.0.0-beta.0 → 1.0.0-beta.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/package.json +3 -1
- package/src/components/facet-types/checkbox-list-facet/checkbox-list-facet.component.ts +3 -3
- package/src/components/facet-types/color-facet/color-facet.component.ts +11 -4
- package/src/components/facet-types/linked-list-facet/link-list-facet.component.ts +13 -6
- package/src/components/facet-types/size-facet/size-facet.component.ts +13 -6
- package/src/components/index.ts +18 -18
- package/src/components/query-suggestions/query-suggestions.component.ts +1 -1
- package/src/components/search-results/search-results.component.ts +17 -17
- package/src/components/search-results-list/search-results-list.component.hbs +13 -15
- package/src/components/search-results-list/search-results-list.component.ts +5 -1
- package/src/components/tabs/tabs.component.hbs +5 -7
- package/src/components/tabs/tabs.component.ts +1 -3
- package/src/index.ts +125 -125
- package/src/models/global.models.ts +78 -78
- package/src/services/search.service.ts +754 -754
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgeline-digital/hawksearch-handlebars-ui",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"lint": "npm run eslint && npm run prettier",
|
|
16
16
|
"prepare": "husky install",
|
|
17
17
|
"prettier": "prettier --write .",
|
|
18
|
+
"publish": "npm run version && npm run build && npm publish",
|
|
18
19
|
"serve": "webpack serve --open",
|
|
20
|
+
"version": "npm version patch",
|
|
19
21
|
"watch": "webpack --watch"
|
|
20
22
|
},
|
|
21
23
|
"keywords": [],
|
|
@@ -3,11 +3,11 @@ import { BaseFacetComponent } from '../base-facet.component';
|
|
|
3
3
|
import defaultHtml from './checkbox-list-facet.component.hbs';
|
|
4
4
|
import checkboxListPartialHtml from './checkbox-list.partial.hbs';
|
|
5
5
|
|
|
6
|
-
interface
|
|
6
|
+
interface CheckboxListFacetValue extends FacetValue {
|
|
7
7
|
visible: boolean;
|
|
8
8
|
toggled: boolean;
|
|
9
9
|
hasChildren: boolean;
|
|
10
|
-
children?: Array<
|
|
10
|
+
children?: Array<CheckboxListFacetValue>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export class CheckboxListFacetComponent extends BaseFacetComponent {
|
|
@@ -39,7 +39,7 @@ export class CheckboxListFacetComponent extends BaseFacetComponent {
|
|
|
39
39
|
return value.children?.some((v) => filtered(v)) || false;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
const getValues = (values: Array<FacetValue> | undefined, parent:
|
|
42
|
+
const getValues = (values: Array<FacetValue> | undefined, parent: CheckboxListFacetValue | undefined): Array<CheckboxListFacetValue> | undefined => {
|
|
43
43
|
return values?.map((v, i) => {
|
|
44
44
|
const valueWithState = {
|
|
45
45
|
...v,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { FacetValue } from '@models';
|
|
1
2
|
import { BaseFacetComponent } from '../base-facet.component';
|
|
2
3
|
import defaultHtml from './color-facet.component.hbs';
|
|
3
4
|
|
|
5
|
+
interface ColorFacetValue extends FacetValue {
|
|
6
|
+
visible: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export class ColorFacetComponent extends BaseFacetComponent {
|
|
5
10
|
protected customTemplatePropertyName = 'colorFacet';
|
|
6
11
|
protected defaultHtml = defaultHtml;
|
|
@@ -12,10 +17,12 @@ export class ColorFacetComponent extends BaseFacetComponent {
|
|
|
12
17
|
|
|
13
18
|
const html = template({
|
|
14
19
|
values:
|
|
15
|
-
this.data.values?.map(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
this.data.values?.map(
|
|
21
|
+
(v, i): ColorFacetValue => ({
|
|
22
|
+
...v,
|
|
23
|
+
visible: this.state.toggled || !this.data?.truncateThreshold || i < this.data?.truncateThreshold
|
|
24
|
+
})
|
|
25
|
+
) ?? [],
|
|
19
26
|
showToggle: !!this.data.truncateThreshold && (this.data.values?.length ?? 0) > this.data.truncateThreshold,
|
|
20
27
|
toggleText: this.state.toggled ? 'Show fewer' : 'Show more',
|
|
21
28
|
expanded: this.state.toggled
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { FacetValue } from '@models';
|
|
1
2
|
import { BaseFacetComponent } from '../base-facet.component';
|
|
2
3
|
import defaultHtml from './link-list-facet.component.hbs';
|
|
3
4
|
|
|
5
|
+
interface LinkListFacetValue extends FacetValue {
|
|
6
|
+
visible: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export class LinkListFacetComponent extends BaseFacetComponent {
|
|
5
10
|
protected customTemplatePropertyName = 'linkListFacet';
|
|
6
11
|
protected defaultHtml = defaultHtml;
|
|
@@ -16,12 +21,14 @@ export class LinkListFacetComponent extends BaseFacetComponent {
|
|
|
16
21
|
id: this.data.id,
|
|
17
22
|
field: this.data.field,
|
|
18
23
|
values:
|
|
19
|
-
this.data.values?.map(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
this.data.values?.map(
|
|
25
|
+
(v, i): LinkListFacetValue => ({
|
|
26
|
+
...v,
|
|
27
|
+
visible:
|
|
28
|
+
(!filterRegex && (this.state.toggled || !this.data!.truncateThreshold || i < this.data!.truncateThreshold!)) ||
|
|
29
|
+
(!!filterRegex && filterRegex.test(v.title ?? ''))
|
|
30
|
+
})
|
|
31
|
+
) ?? [],
|
|
25
32
|
showToggle: !!this.data.truncateThreshold && (this.data.values?.length ?? 0) > this.data.truncateThreshold && !this.state.filter,
|
|
26
33
|
toggleText: this.state.toggled ? 'Show fewer' : 'Show more',
|
|
27
34
|
expanded: this.state.toggled
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { FacetValue } from '@models';
|
|
1
2
|
import { BaseFacetComponent } from '../base-facet.component';
|
|
2
3
|
import defaultHtml from './size-facet.component.hbs';
|
|
3
4
|
|
|
5
|
+
interface SizeFacetValue extends FacetValue {
|
|
6
|
+
visible: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export class SizeFacetComponent extends BaseFacetComponent {
|
|
5
10
|
protected customTemplatePropertyName = 'colorFacet';
|
|
6
11
|
protected defaultHtml = defaultHtml;
|
|
@@ -14,12 +19,14 @@ export class SizeFacetComponent extends BaseFacetComponent {
|
|
|
14
19
|
|
|
15
20
|
const html = template({
|
|
16
21
|
values:
|
|
17
|
-
this.data.values?.map(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
this.data.values?.map(
|
|
23
|
+
(v, i): SizeFacetValue => ({
|
|
24
|
+
...v,
|
|
25
|
+
visible:
|
|
26
|
+
(!filterRegex && (this.state.toggled || !this.data!.truncateThreshold || i < this.data!.truncateThreshold!)) ||
|
|
27
|
+
(!!filterRegex && filterRegex.test(v.title ?? ''))
|
|
28
|
+
})
|
|
29
|
+
) ?? [],
|
|
23
30
|
showToggle: !!this.data.truncateThreshold && (this.data.values?.length ?? 0) > this.data.truncateThreshold,
|
|
24
31
|
toggleText: this.state.toggled ? 'Show fewer' : 'Show more',
|
|
25
32
|
expanded: this.state.toggled
|
package/src/components/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export * from './autocomplete/autocomplete.component';
|
|
2
|
-
export * from './facet-types';
|
|
3
|
-
export * from './facet-wrapper/facet-wrapper.component';
|
|
4
|
-
export * from './facets-list/facets-list.component';
|
|
5
|
-
export * from './icon/icon.component';
|
|
6
|
-
export * from './modified-query/modified-query.component';
|
|
7
|
-
export * from './page-size/page-size.component';
|
|
8
|
-
export * from './pagination/pagination.component';
|
|
9
|
-
export * from './query-suggestions/query-suggestions.component';
|
|
10
|
-
export * from './range-slider/range-slider.component';
|
|
11
|
-
export * from './search/search.component';
|
|
12
|
-
export * from './search-results-item/search-results-item.component';
|
|
13
|
-
export * from './search-results-list/search-results-list.component';
|
|
14
|
-
export * from './search-results/search-results.component';
|
|
15
|
-
export * from './selected-facets/selected-facets.component';
|
|
16
|
-
export * from './sorting/sorting.component';
|
|
17
|
-
export * from './tabs/tabs.component';
|
|
18
|
-
export * from './tooltip/tooltip.component';
|
|
1
|
+
export * from './autocomplete/autocomplete.component';
|
|
2
|
+
export * from './facet-types';
|
|
3
|
+
export * from './facet-wrapper/facet-wrapper.component';
|
|
4
|
+
export * from './facets-list/facets-list.component';
|
|
5
|
+
export * from './icon/icon.component';
|
|
6
|
+
export * from './modified-query/modified-query.component';
|
|
7
|
+
export * from './page-size/page-size.component';
|
|
8
|
+
export * from './pagination/pagination.component';
|
|
9
|
+
export * from './query-suggestions/query-suggestions.component';
|
|
10
|
+
export * from './range-slider/range-slider.component';
|
|
11
|
+
export * from './search/search.component';
|
|
12
|
+
export * from './search-results-item/search-results-item.component';
|
|
13
|
+
export * from './search-results-list/search-results-list.component';
|
|
14
|
+
export * from './search-results/search-results.component';
|
|
15
|
+
export * from './selected-facets/selected-facets.component';
|
|
16
|
+
export * from './sorting/sorting.component';
|
|
17
|
+
export * from './tabs/tabs.component';
|
|
18
|
+
export * from './tooltip/tooltip.component';
|
|
@@ -16,7 +16,7 @@ export class QuerySuggestionsComponent extends BaseComponent<QuerySuggestionsDat
|
|
|
16
16
|
|
|
17
17
|
this.handlebars.registerHelper('query-suggestions', function (querySuggestions: Array<string>): SafeString {
|
|
18
18
|
function linkFunction(query: string): string {
|
|
19
|
-
return `<a hawksearch-query="${encodeURIComponent(query)}">${query}</a>`;
|
|
19
|
+
return `<a hawksearch-query="${encodeURIComponent(query)}" class="query-suggestions__link">${query}</a>`;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (querySuggestions.length <= 2) {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { SearchResponse } from '@models';
|
|
2
|
-
import { BaseComponent } from '../base.component';
|
|
3
|
-
import defaultHtml from './search-results.component.hbs';
|
|
4
|
-
|
|
5
|
-
export class SearchResultsComponent extends BaseComponent<SearchResponse> {
|
|
6
|
-
protected bindEvent = 'hawksearch:bind-search-results';
|
|
7
|
-
protected customTemplatePropertyName = 'searchResults';
|
|
8
|
-
protected defaultHtml = defaultHtml;
|
|
9
|
-
|
|
10
|
-
protected getContentHtml(template: HandlebarsTemplateDelegate): string {
|
|
11
|
-
const html = template({
|
|
12
|
-
data: this.data
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
return html;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
import { SearchResponse } from '@models';
|
|
2
|
+
import { BaseComponent } from '../base.component';
|
|
3
|
+
import defaultHtml from './search-results.component.hbs';
|
|
4
|
+
|
|
5
|
+
export class SearchResultsComponent extends BaseComponent<SearchResponse> {
|
|
6
|
+
protected bindEvent = 'hawksearch:bind-search-results';
|
|
7
|
+
protected customTemplatePropertyName = 'searchResults';
|
|
8
|
+
protected defaultHtml = defaultHtml;
|
|
9
|
+
|
|
10
|
+
protected getContentHtml(template: HandlebarsTemplateDelegate): string {
|
|
11
|
+
const html = template({
|
|
12
|
+
data: this.data
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return html;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
{{#
|
|
4
|
-
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
</div>
|
|
15
|
-
{{/if}}
|
|
1
|
+
<div class='row'>
|
|
2
|
+
{{#each items}}
|
|
3
|
+
{{#if (eq type 'content')}}
|
|
4
|
+
<div class='column column--12'>
|
|
5
|
+
<hawksearch-results-item></hawksearch-results-item>
|
|
6
|
+
</div>
|
|
7
|
+
{{else}}
|
|
8
|
+
<div class='column column--12 column-sm--6 column-lg--4'>
|
|
9
|
+
<hawksearch-results-item></hawksearch-results-item>
|
|
10
|
+
</div>
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{/each}}
|
|
13
|
+
</div>
|
|
@@ -9,8 +9,12 @@ export class SearchResultsListComponent extends BaseComponent<Array<SearchResult
|
|
|
9
9
|
protected defaultHtml = defaultHtml;
|
|
10
10
|
|
|
11
11
|
protected getContentHtml(template: HandlebarsTemplateDelegate): string {
|
|
12
|
+
if (!this.data?.length) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
const html = template({
|
|
13
|
-
items: this.data
|
|
17
|
+
items: this.data
|
|
14
18
|
});
|
|
15
19
|
|
|
16
20
|
return html;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
{{
|
|
2
|
-
|
|
3
|
-
{{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
</ul>
|
|
7
|
-
{{/if}}
|
|
1
|
+
<ul class='tabs{{attribute " tabs--list" (gt values.length 4)}}'>
|
|
2
|
+
{{#each values}}
|
|
3
|
+
<li class='tabs__item{{attribute " tabs__item--selected" selected}}' hawksearch-tab-value={{value}}>{{title}} ({{count}})</li>
|
|
4
|
+
{{/each}}
|
|
5
|
+
</ul>
|
package/src/index.ts
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import * as Handlebars from 'handlebars/dist/handlebars';
|
|
3
|
-
import {
|
|
4
|
-
AutocompleteComponent,
|
|
5
|
-
CheckboxListFacetComponent,
|
|
6
|
-
ColorFacetComponent,
|
|
7
|
-
FacetWrapperComponent,
|
|
8
|
-
FacetsListComponent,
|
|
9
|
-
IconComponent,
|
|
10
|
-
LinkListFacetComponent,
|
|
11
|
-
ModifiedQueryComponent,
|
|
12
|
-
PageSizeComponent,
|
|
13
|
-
PaginationComponent,
|
|
14
|
-
QuerySuggestionsComponent,
|
|
15
|
-
RangeSliderComponent,
|
|
16
|
-
RangeSliderFacetComponent,
|
|
17
|
-
SearchComponent,
|
|
18
|
-
SearchResultsComponent,
|
|
19
|
-
SearchResultsItemComponent,
|
|
20
|
-
SearchResultsListComponent,
|
|
21
|
-
SearchWithinFacetComponent,
|
|
22
|
-
SelectedFacetsComponent,
|
|
23
|
-
SizeFacetComponent,
|
|
24
|
-
SortingComponent,
|
|
25
|
-
TabsComponent,
|
|
26
|
-
TooltipComponent
|
|
27
|
-
} from './components';
|
|
28
|
-
import { HawksearchGlobal, HawksearchState, PageType } from './models';
|
|
29
|
-
import { searchService, trackingService } from './services';
|
|
30
|
-
|
|
31
|
-
declare let Hawksearch: HawksearchGlobal;
|
|
32
|
-
|
|
33
|
-
if (!Hawksearch) {
|
|
34
|
-
Hawksearch = {} as HawksearchGlobal;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
Hawksearch.service = searchService;
|
|
38
|
-
Hawksearch.handlebars = Handlebars.noConflict();
|
|
39
|
-
|
|
40
|
-
Hawksearch.handlebars.registerHelper('add', function (value1: number, value2: number): number {
|
|
41
|
-
return value1 + value2;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
Hawksearch.handlebars.registerHelper('attribute', function (attribute: string, condition: any): string {
|
|
45
|
-
return condition ? attribute : '';
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
Hawksearch.handlebars.registerHelper('eq', function (value1: any, value2: any): boolean {
|
|
49
|
-
return value1 === value2;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
Hawksearch.handlebars.registerHelper('exclude', function (options): any {
|
|
53
|
-
return options.fn();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
Hawksearch.handlebars.registerHelper('html', function (html: string): Handlebars.SafeString {
|
|
57
|
-
return new Hawksearch.handlebars.SafeString(html);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
Hawksearch.handlebars.registerHelper('if-else', function (condition: any, trueValue: any, falseValue: any): any {
|
|
61
|
-
return condition ? trueValue : falseValue;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
Hawksearch.handlebars.registerHelper('lt', function (value1: any, value2: any): boolean {
|
|
65
|
-
return value1 < value2;
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
Hawksearch.handlebars.registerHelper('lte', function (value1: any, value2: any): boolean {
|
|
69
|
-
return value1 <= value2;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
Hawksearch.handlebars.registerHelper('gt', function (value1: any, value2: any): boolean {
|
|
73
|
-
return value1 > value2;
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
Hawksearch.handlebars.registerHelper('gte', function (value1: any, value2: any): boolean {
|
|
77
|
-
return value1 >= value2;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
Hawksearch.handlebars.registerHelper('or', function (...values: Array<any>): boolean {
|
|
81
|
-
return values.slice(0, -1).some((v) => !!v); // Omit last argument as that is Handlebars options which would always resolve to true
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
Hawksearch.handlebars.registerHelper('subtract', function (value1: number, value2: number): number {
|
|
85
|
-
return value1 - value2;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
customElements.define('hawksearch-autocomplete', AutocompleteComponent);
|
|
89
|
-
customElements.define('hawksearch-checkbox-list-facet', CheckboxListFacetComponent);
|
|
90
|
-
customElements.define('hawksearch-color-facet', ColorFacetComponent);
|
|
91
|
-
customElements.define('hawksearch-facet-wrapper', FacetWrapperComponent);
|
|
92
|
-
customElements.define('hawksearch-facets-list', FacetsListComponent);
|
|
93
|
-
customElements.define('hawksearch-icon', IconComponent);
|
|
94
|
-
customElements.define('hawksearch-link-list-facet', LinkListFacetComponent);
|
|
95
|
-
customElements.define('hawksearch-modified-query', ModifiedQueryComponent);
|
|
96
|
-
customElements.define('hawksearch-page-size', PageSizeComponent);
|
|
97
|
-
customElements.define('hawksearch-pagination', PaginationComponent);
|
|
98
|
-
customElements.define('hawksearch-query-suggestions', QuerySuggestionsComponent);
|
|
99
|
-
customElements.define('hawksearch-results', SearchResultsComponent);
|
|
100
|
-
customElements.define('hawksearch-range-slider', RangeSliderComponent);
|
|
101
|
-
customElements.define('hawksearch-range-slider-facet', RangeSliderFacetComponent);
|
|
102
|
-
customElements.define('hawksearch-results-list', SearchResultsListComponent);
|
|
103
|
-
customElements.define('hawksearch-results-item', SearchResultsItemComponent);
|
|
104
|
-
customElements.define('hawksearch-search', SearchComponent);
|
|
105
|
-
customElements.define('hawksearch-search-within-facet', SearchWithinFacetComponent);
|
|
106
|
-
customElements.define('hawksearch-selected-facets', SelectedFacetsComponent);
|
|
107
|
-
customElements.define('hawksearch-size-facet', SizeFacetComponent);
|
|
108
|
-
customElements.define('hawksearch-sorting', SortingComponent);
|
|
109
|
-
customElements.define('hawksearch-tabs', TabsComponent);
|
|
110
|
-
customElements.define('hawksearch-tooltip', TooltipComponent);
|
|
111
|
-
|
|
112
|
-
addEventListener('popstate', (event) => {
|
|
113
|
-
const state: HawksearchState = event.state;
|
|
114
|
-
|
|
115
|
-
Hawksearch.searchRequest = state.searchRequest;
|
|
116
|
-
Hawksearch.searchResponse = state.searchResponse;
|
|
117
|
-
|
|
118
|
-
searchService.bindComponents(state.searchResponse);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
trackingService.trackPageLoad(PageType.Custom);
|
|
122
|
-
|
|
123
|
-
const searchRequest = searchService.getRequestFromUrl();
|
|
124
|
-
|
|
125
|
-
searchService.search(searchRequest);
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as Handlebars from 'handlebars/dist/handlebars';
|
|
3
|
+
import {
|
|
4
|
+
AutocompleteComponent,
|
|
5
|
+
CheckboxListFacetComponent,
|
|
6
|
+
ColorFacetComponent,
|
|
7
|
+
FacetWrapperComponent,
|
|
8
|
+
FacetsListComponent,
|
|
9
|
+
IconComponent,
|
|
10
|
+
LinkListFacetComponent,
|
|
11
|
+
ModifiedQueryComponent,
|
|
12
|
+
PageSizeComponent,
|
|
13
|
+
PaginationComponent,
|
|
14
|
+
QuerySuggestionsComponent,
|
|
15
|
+
RangeSliderComponent,
|
|
16
|
+
RangeSliderFacetComponent,
|
|
17
|
+
SearchComponent,
|
|
18
|
+
SearchResultsComponent,
|
|
19
|
+
SearchResultsItemComponent,
|
|
20
|
+
SearchResultsListComponent,
|
|
21
|
+
SearchWithinFacetComponent,
|
|
22
|
+
SelectedFacetsComponent,
|
|
23
|
+
SizeFacetComponent,
|
|
24
|
+
SortingComponent,
|
|
25
|
+
TabsComponent,
|
|
26
|
+
TooltipComponent
|
|
27
|
+
} from './components';
|
|
28
|
+
import { HawksearchGlobal, HawksearchState, PageType } from './models';
|
|
29
|
+
import { searchService, trackingService } from './services';
|
|
30
|
+
|
|
31
|
+
declare let Hawksearch: HawksearchGlobal;
|
|
32
|
+
|
|
33
|
+
if (!Hawksearch) {
|
|
34
|
+
Hawksearch = {} as HawksearchGlobal;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Hawksearch.service = searchService;
|
|
38
|
+
Hawksearch.handlebars = Handlebars.noConflict();
|
|
39
|
+
|
|
40
|
+
Hawksearch.handlebars.registerHelper('add', function (value1: number, value2: number): number {
|
|
41
|
+
return value1 + value2;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
Hawksearch.handlebars.registerHelper('attribute', function (attribute: string, condition: any): string {
|
|
45
|
+
return condition ? attribute : '';
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
Hawksearch.handlebars.registerHelper('eq', function (value1: any, value2: any): boolean {
|
|
49
|
+
return value1 === value2;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
Hawksearch.handlebars.registerHelper('exclude', function (options): any {
|
|
53
|
+
return options.fn();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
Hawksearch.handlebars.registerHelper('html', function (html: string): Handlebars.SafeString {
|
|
57
|
+
return new Hawksearch.handlebars.SafeString(html);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
Hawksearch.handlebars.registerHelper('if-else', function (condition: any, trueValue: any, falseValue: any): any {
|
|
61
|
+
return condition ? trueValue : falseValue;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
Hawksearch.handlebars.registerHelper('lt', function (value1: any, value2: any): boolean {
|
|
65
|
+
return value1 < value2;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
Hawksearch.handlebars.registerHelper('lte', function (value1: any, value2: any): boolean {
|
|
69
|
+
return value1 <= value2;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
Hawksearch.handlebars.registerHelper('gt', function (value1: any, value2: any): boolean {
|
|
73
|
+
return value1 > value2;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
Hawksearch.handlebars.registerHelper('gte', function (value1: any, value2: any): boolean {
|
|
77
|
+
return value1 >= value2;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
Hawksearch.handlebars.registerHelper('or', function (...values: Array<any>): boolean {
|
|
81
|
+
return values.slice(0, -1).some((v) => !!v); // Omit last argument as that is Handlebars options which would always resolve to true
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
Hawksearch.handlebars.registerHelper('subtract', function (value1: number, value2: number): number {
|
|
85
|
+
return value1 - value2;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
customElements.define('hawksearch-autocomplete', AutocompleteComponent);
|
|
89
|
+
customElements.define('hawksearch-checkbox-list-facet', CheckboxListFacetComponent);
|
|
90
|
+
customElements.define('hawksearch-color-facet', ColorFacetComponent);
|
|
91
|
+
customElements.define('hawksearch-facet-wrapper', FacetWrapperComponent);
|
|
92
|
+
customElements.define('hawksearch-facets-list', FacetsListComponent);
|
|
93
|
+
customElements.define('hawksearch-icon', IconComponent);
|
|
94
|
+
customElements.define('hawksearch-link-list-facet', LinkListFacetComponent);
|
|
95
|
+
customElements.define('hawksearch-modified-query', ModifiedQueryComponent);
|
|
96
|
+
customElements.define('hawksearch-page-size', PageSizeComponent);
|
|
97
|
+
customElements.define('hawksearch-pagination', PaginationComponent);
|
|
98
|
+
customElements.define('hawksearch-query-suggestions', QuerySuggestionsComponent);
|
|
99
|
+
customElements.define('hawksearch-results', SearchResultsComponent);
|
|
100
|
+
customElements.define('hawksearch-range-slider', RangeSliderComponent);
|
|
101
|
+
customElements.define('hawksearch-range-slider-facet', RangeSliderFacetComponent);
|
|
102
|
+
customElements.define('hawksearch-results-list', SearchResultsListComponent);
|
|
103
|
+
customElements.define('hawksearch-results-item', SearchResultsItemComponent);
|
|
104
|
+
customElements.define('hawksearch-search', SearchComponent);
|
|
105
|
+
customElements.define('hawksearch-search-within-facet', SearchWithinFacetComponent);
|
|
106
|
+
customElements.define('hawksearch-selected-facets', SelectedFacetsComponent);
|
|
107
|
+
customElements.define('hawksearch-size-facet', SizeFacetComponent);
|
|
108
|
+
customElements.define('hawksearch-sorting', SortingComponent);
|
|
109
|
+
customElements.define('hawksearch-tabs', TabsComponent);
|
|
110
|
+
customElements.define('hawksearch-tooltip', TooltipComponent);
|
|
111
|
+
|
|
112
|
+
addEventListener('popstate', (event) => {
|
|
113
|
+
const state: HawksearchState = event.state;
|
|
114
|
+
|
|
115
|
+
Hawksearch.searchRequest = state.searchRequest;
|
|
116
|
+
Hawksearch.searchResponse = state.searchResponse;
|
|
117
|
+
|
|
118
|
+
searchService.bindComponents(state.searchResponse);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
trackingService.trackPageLoad(PageType.Custom);
|
|
122
|
+
|
|
123
|
+
const searchRequest = searchService.getRequestFromUrl();
|
|
124
|
+
|
|
125
|
+
searchService.search(searchRequest);
|