@worksafevictoria/wcl7.5 1.7.3 → 1.8.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,10 +6,10 @@
6
6
  </div>
7
7
  </template>
8
8
  <template v-else>
9
+ ELSE :- searchType :- {{ searchType }}
9
10
  <b-input-group>
10
11
  <label class="visually-hidden" for="site-search"
11
- >Search by keyword (Typed keyword automatically filters below
12
- results)</label
12
+ >Search by keyword (Typed keyword automatically filters below results)</label
13
13
  >
14
14
  <b-form-input
15
15
  id="site-search"
@@ -19,7 +19,7 @@
19
19
  autocomplete="off"
20
20
  trim
21
21
  @update="searchType !== 'googlerest' ? onChange : () => {}"
22
- @keyup.enter="onChange"
22
+ @keyup.enter="searchType === 'googlerest' ? onChange : () => {}"
23
23
  ></b-form-input>
24
24
  <template #append>
25
25
  <b-button size="sm" class="search-button" @click="onSearch"
@@ -28,6 +28,7 @@
28
28
  /></b-button>
29
29
  </template>
30
30
  </b-input-group>
31
+ searchType:- {{ searchType }} <br />
31
32
  <search-listing
32
33
  v-if="loadSearchList && (searchResults || isLoading)"
33
34
  :class="{
@@ -43,6 +44,7 @@
43
44
  :offset="searchResults && searchResults.offset"
44
45
  :page-limit="pageLimit"
45
46
  :content-parser="contentParser"
47
+ :is-selectable="searchType === 'googlerest' ? false : true"
46
48
  :is-card-title-selectable="searchType === 'googlerest' ? true : false"
47
49
  @selected="$emit('selected')"
48
50
  @pageChanged="pageChanged"
@@ -52,11 +54,10 @@
52
54
  </template>
53
55
 
54
56
  <script>
55
- import axios from 'axios'
56
- import searchIcon from '../../../assets/icons/search.svg?url'
57
- import SearchListing from './SearchListing/index.vue'
58
- import { BButton, BInputGroup, BFormInput } from 'bootstrap-vue-next'
59
-
57
+ import axios from "axios";
58
+ import searchIcon from "../../../assets/icons/search.svg?url";
59
+ import SearchListing from "./SearchListing/index.vue";
60
+ import { BButton, BInputGroup, BFormInput } from "bootstrap-vue-next";
60
61
 
61
62
  export default {
62
63
  components: { SearchListing, BButton, BInputGroup, BFormInput },
@@ -75,11 +76,11 @@ export default {
75
76
  },
76
77
  initialSearchQuery: {
77
78
  type: String,
78
- default: '',
79
+ default: "",
79
80
  },
80
81
  googleSearchFlag: {
81
82
  type: String,
82
- default: 'solar',
83
+ default: "solar",
83
84
  },
84
85
  visibleSearchList: {
85
86
  type: Boolean,
@@ -89,39 +90,39 @@ export default {
89
90
  data() {
90
91
  return {
91
92
  searchIcon,
92
- searchQuery: '',
93
+ searchQuery: "",
93
94
  searchResults: null,
94
95
  isLoading: false,
95
- field_language: '8671',
96
+ field_language: "8671",
96
97
  searchType: this.googleSearchFlag,
97
98
  googleSearchScript: false,
98
99
  loadSearchList: this.visibleSearchList,
99
- }
100
+ };
100
101
  },
101
102
  computed: {
102
103
  searchClass() {
103
104
  return {
104
- 'wcl-search': true,
105
- 'wcl-search__google': this.searchType !== 'solar',
106
- }
105
+ "wcl-search": true,
106
+ "wcl-search__google": this.searchType !== "solar",
107
+ };
107
108
  },
108
109
  },
109
110
  mounted() {
110
- if (this.searchType === 'google') {
111
- this.setupGoogleStyle()
111
+ if (this.searchType === "google") {
112
+ this.setupGoogleStyle();
112
113
  } else {
113
114
  if (this.initialSearchQuery) {
114
- this.searchQuery = this.initialSearchQuery
115
- this.onSearch()
115
+ this.searchQuery = this.initialSearchQuery;
116
+ this.onSearch();
116
117
  }
117
118
  if (this.isTypeahead && window) {
118
- window.document.addEventListener('click', this.closeSearchResults)
119
+ window.document.addEventListener("click", this.closeSearchResults);
119
120
  }
120
121
  }
121
122
  },
122
123
  beforeDestroy() {
123
124
  if (this.isTypeahead && window && document) {
124
- window.document.removeEventListener('click', this.closeSearchResults)
125
+ window.document.removeEventListener("click", this.closeSearchResults);
125
126
  }
126
127
  },
127
128
  methods: {
@@ -136,54 +137,54 @@ export default {
136
137
  q: query,
137
138
  start: start,
138
139
  },
139
- },
140
- )
141
- return response
140
+ }
141
+ );
142
+ return response;
142
143
  } catch (error) {
143
- console.error('Error fetching search results:', error)
144
- return []
144
+ console.error("Error fetching search results:", error);
145
+ return [];
145
146
  }
146
147
  },
147
148
  async onGoogleSearch(pageNr = 1, searchQuery) {
148
- this.$emit('loading', true)
149
- this.isLoading = true
149
+ this.$emit("loading", true);
150
+ this.isLoading = true;
150
151
 
151
- const apiKey = 'AIzaSyD76GAmQQ6DuxKWf-aLXPZ9pwdz4nOvs2c'
152
- const searchEngineId = '53b1506aa03c64160'
152
+ const apiKey = "AIzaSyD76GAmQQ6DuxKWf-aLXPZ9pwdz4nOvs2c";
153
+ const searchEngineId = "53b1506aa03c64160";
153
154
 
154
- const start = (pageNr - 1) * this.pageLimit
155
+ const start = (pageNr - 1) * this.pageLimit;
155
156
  let response = await this.fetchSearchResults(
156
157
  apiKey,
157
158
  searchEngineId,
158
159
  searchQuery,
159
- start,
160
- )
161
- let items = []
162
- let suggest = response?.data?.spelling?.correctedQuery || ''
160
+ start
161
+ );
162
+ let items = [];
163
+ let suggest = response?.data?.spelling?.correctedQuery || "";
163
164
  if (response?.data?.spelling?.correctedQuery) {
164
165
  response = await this.fetchSearchResults(
165
166
  apiKey,
166
167
  searchEngineId,
167
168
  response?.data?.spelling?.correctedQuery,
168
- start,
169
- )
170
- items = response?.data?.items
169
+ start
170
+ );
171
+ items = response?.data?.items;
171
172
  } else if (response?.data?.items) {
172
- items = response?.data?.items
173
+ items = response?.data?.items;
173
174
  }
174
175
  if (items.length > 0) {
175
- const totalResults = response?.data?.searchInformation?.totalResults
176
+ const totalResults = response?.data?.searchInformation?.totalResults;
176
177
  // Loop through each item in the items array
177
178
  const modifiedResults = items.map((item) => {
178
179
  // Update the title using the handleSearchResultLinkTitle function
179
- const modifiedTitle = this.handleSearchResultLinkTitle(item.title)
180
+ const modifiedTitle = this.handleSearchResultLinkTitle(item.title);
180
181
 
181
182
  // Return the modified item with the updated title
182
183
  return {
183
184
  ...item,
184
185
  title: modifiedTitle,
185
- }
186
- })
186
+ };
187
+ });
187
188
 
188
189
  this.searchResults = {
189
190
  offset: Number(pageNr === 1 ? pageNr - 1 : pageNr),
@@ -191,19 +192,19 @@ export default {
191
192
  query: this.searchQuery,
192
193
  results: modifiedResults,
193
194
  suggestion: suggest,
194
- }
195
+ };
195
196
  } else {
196
197
  this.searchResults = {
197
198
  offset: 0,
198
199
  numFound: 0,
199
- query: this.searchQuery ?? '',
200
+ query: this.searchQuery ?? "",
200
201
  results: [],
201
202
  suggestion: suggest,
202
- }
203
+ };
203
204
  }
204
- this.$emit('loading', false)
205
- this.isLoading = false
206
- this.$emit('results', this.searchResults)
205
+ this.$emit("loading", false);
206
+ this.isLoading = false;
207
+ this.$emit("results", this.searchResults);
207
208
 
208
209
  // wait for the page title to be updated and then fire the search event
209
210
  setTimeout(() => {
@@ -211,87 +212,83 @@ export default {
211
212
  pageTitle: document.title,
212
213
  pageURL: this.$route?.fullPath,
213
214
  location:
214
- this.$route?.path === '/'
215
- ? 'Homepage'
216
- : this.$route?.path === '/search'
217
- ? 'Search Page'
218
- : this.$route?.path,
215
+ this.$route?.path === "/"
216
+ ? "Homepage"
217
+ : this.$route?.path === "/search"
218
+ ? "Search Page"
219
+ : this.$route?.path,
219
220
  label: this.searchQuery,
220
221
  results: this.searchResults.numFound,
221
- }
222
+ };
222
223
  if (this.$gtm) {
223
- this.$gtm.push({ event: 'custom.search.site.submit', ...attrs })
224
+ this.$gtm.push({ event: "custom.search.site.submit", ...attrs });
224
225
  }
225
- }, 300)
226
+ }, 300);
226
227
  },
227
228
  pageChanged(newPageNumber) {
228
- if (this.searchType === 'solar') {
229
+ if (this.searchType === "solar") {
229
230
  // Reset search results before fetching new results
230
- this.resetSearchResults()
231
- this.performSearch(newPageNumber, this.searchQuery, this.pageLimit)
231
+ this.resetSearchResults();
232
+ this.performSearch(newPageNumber, this.searchQuery, this.pageLimit);
232
233
  } else {
233
234
  // Fetch new search results with the updated page number
234
- this.onGoogleSearch(newPageNumber, this.searchQuery)
235
+ this.onGoogleSearch(newPageNumber, this.searchQuery);
235
236
  }
236
237
  },
237
238
  onSearch(e) {
238
- // debugger
239
- const { path } = this.$route || {}
239
+ debugger;
240
+ console.log("this.searchType:- ", this.searchType);
240
241
 
241
-
242
+ const { path } = this.$route || {};
242
243
 
243
244
  // Home page
244
245
  if (
245
- (e?.type === 'click' || e?.key == 'Enter') &&
246
+ (e?.type === "click" || e?.key == "Enter") &&
246
247
  this.searchQuery &&
247
248
  this.searchQuery.length > 2 &&
248
- path === '/'
249
+ path === "/"
249
250
  ) {
250
251
  // Search page
251
- const searchQuery = encodeURIComponent(this.searchQuery)
252
- const origin = window.location.origin
253
- const hash = window.location.hash
254
- const pathname = 'search'
255
- const URL = `${origin}/${pathname}${hash}?q=${searchQuery}`
252
+ const searchQuery = encodeURIComponent(this.searchQuery);
253
+ const origin = window.location.origin;
254
+ const hash = window.location.hash;
255
+ const pathname = "search";
256
+ const URL = `${origin}/${pathname}${hash}?q=${searchQuery}`;
256
257
 
257
258
  // Uncomment below commented code when goes live
258
- window.location.assign(URL)
259
+ window.location.assign(URL);
259
260
  } else {
260
- this.resetSearchResults()
261
- this.$emit('query', this.searchQuery)
261
+ this.resetSearchResults();
262
+ this.$emit("query", this.searchQuery);
262
263
 
263
- if (this.searchType === 'solar') {
264
- this.performSearch(1, this.searchQuery, this.pageLimit)
264
+ if (this.searchType === "solar") {
265
+ this.performSearch(1, this.searchQuery, this.pageLimit);
265
266
  } else {
266
- this.onGoogleSearch(1, this.searchQuery)
267
+ this.onGoogleSearch(1, this.searchQuery);
267
268
  }
268
269
  }
269
270
  },
270
271
  resetSearchResults() {
271
- this.searchResults = null
272
+ this.searchResults = null;
272
273
  },
273
274
  closeSearchResults(ev) {
274
- if (
275
- this.isTypeahead &&
276
- this.searchResults &&
277
- ev?.target?.id !== 'site-search'
278
- ) {
279
- this.resetSearchResults()
280
- this.searchQuery = null
281
- this.$emit('query', null)
275
+ if (this.isTypeahead && this.searchResults && ev?.target?.id !== "site-search") {
276
+ this.resetSearchResults();
277
+ this.searchQuery = null;
278
+ this.$emit("query", null);
282
279
  }
283
280
  },
284
281
  onChange(e) {
285
282
  //debugger
286
-
283
+
287
284
  if (this.searchQuery && this.searchQuery.length > 2) {
288
- this.onSearch(e)
285
+ this.onSearch(e);
289
286
  }
290
287
  },
291
288
  performSearch(pageNr = 1, searchQuery, pageLimit) {
292
289
  if (searchQuery) {
293
- this.$emit('loading', true)
294
- this.isLoading = true
290
+ this.$emit("loading", true);
291
+ this.isLoading = true;
295
292
  this.contentParser({
296
293
  query: searchQuery,
297
294
  start: pageNr > 1 ? (pageNr - 1) * pageLimit : 0,
@@ -305,100 +302,100 @@ export default {
305
302
  query: searchQuery,
306
303
  results: res.results,
307
304
  suggestion: null,
308
- }
305
+ };
309
306
  } else {
310
307
  this.searchResults = {
311
308
  offset: 0,
312
309
  numFound: 0,
313
- query: this.searchQuery ?? '',
310
+ query: this.searchQuery ?? "",
314
311
  results: [],
315
312
  suggestion: null,
316
- }
313
+ };
317
314
  }
318
- this.$emit('loading', false)
319
- this.isLoading = false
320
- this.$emit('results', this.searchResults)
315
+ this.$emit("loading", false);
316
+ this.isLoading = false;
317
+ this.$emit("results", this.searchResults);
321
318
  // wait for the page title to be updated and then fire the search event
322
319
  setTimeout(() => {
323
320
  const attrs = {
324
321
  pageTitle: document.title,
325
322
  pageURL: this.$route?.fullPath,
326
323
  location:
327
- this.$route?.path === '/'
328
- ? 'Homepage'
329
- : this.$route?.path === '/search'
330
- ? 'Search Page'
331
- : this.$route?.path,
324
+ this.$route?.path === "/"
325
+ ? "Homepage"
326
+ : this.$route?.path === "/search"
327
+ ? "Search Page"
328
+ : this.$route?.path,
332
329
  label: this.searchQuery,
333
330
  results: this.searchResults.numFound,
334
- }
331
+ };
335
332
  if (this.$gtm) {
336
- this.$gtm.push({ event: 'custom.search.site.submit', ...attrs })
333
+ this.$gtm.push({ event: "custom.search.site.submit", ...attrs });
337
334
  }
338
- }, 300)
339
- })
335
+ }, 300);
336
+ });
340
337
  }
341
338
  },
342
339
 
343
340
  // Method to customize google search style
344
341
  setupGoogleStyle() {
345
342
  if (this.googleSearchScript === false) {
346
- const script = document.createElement('script')
347
- script.async = true
343
+ const script = document.createElement("script");
344
+ script.async = true;
348
345
  script.src = this.$config
349
346
  ? this.$config.public.googleSearch
350
- : process.env.GOOGLE__URL
351
- document.head.appendChild(script)
352
- this.googleSearchScript = true
347
+ : process.env.GOOGLE__URL;
348
+ document.head.appendChild(script);
349
+ this.googleSearchScript = true;
353
350
 
354
351
  // Create a new style element
355
- const style = document.createElement('style')
356
- style.id = 'searchStyle' // Assign an ID to the style element
352
+ const style = document.createElement("style");
353
+ style.id = "searchStyle"; // Assign an ID to the style element
357
354
  // The CSS we are going to inject
358
- const cssVar = 'table.gssb_c {display: none !important;}'
355
+ const cssVar = "table.gssb_c {display: none !important;}";
359
356
  // Inject the style element into the head
360
- document.head.appendChild(style)
357
+ document.head.appendChild(style);
361
358
  // Set the text content of the style element to the CSS text
362
- style.textContent = cssVar
359
+ style.textContent = cssVar;
363
360
  }
364
361
  },
365
362
 
366
363
  // function to handle search result link titles
367
364
  handleSearchResultLinkTitle(title) {
368
365
  // Split the title by the '|' character
369
- const titleParts = title.split('|')
366
+ const titleParts = title.split("|");
370
367
 
371
368
  // Remove any leading or trailing whitespace from each part
372
- const cleanedTitleParts = titleParts.map((part) => part.trim())
369
+ const cleanedTitleParts = titleParts.map((part) => part.trim());
373
370
 
374
371
  // Join the cleaned title parts back together without the text after the '|' character
375
- const modifiedTitle = cleanedTitleParts[0] // Take only the first part before '|'
372
+ const modifiedTitle = cleanedTitleParts[0]; // Take only the first part before '|'
376
373
 
377
- return modifiedTitle
374
+ return modifiedTitle;
378
375
  },
379
376
 
380
377
  handleKeyUp(event) {
381
- if (event.key === 'Enter' || event.type === 'click') {
378
+ if (event.key === "Enter" || event.type === "click") {
382
379
  let keyword = event.key
383
380
  ? event.target.value
384
- : document.querySelector('input[name="search"]').value
381
+ : document.querySelector('input[name="search"]').value;
385
382
 
386
383
  // Check if the URL does not contain "/search"
387
- if (keyword && !window.location.href.includes('/search')) {
388
- let origin = window.location.origin
389
- let hash = window.location.hash
390
- let pathname = 'search'
391
- let URL = origin + '/' + pathname + hash
384
+ if (keyword && !window.location.href.includes("/search")) {
385
+ let origin = window.location.origin;
386
+ let hash = window.location.hash;
387
+ let pathname = "search";
388
+ let URL = origin + "/" + pathname + hash;
392
389
  }
393
390
 
394
- this.setupPaginationEvent()
391
+ this.setupPaginationEvent();
395
392
  }
396
393
  },
397
394
  },
398
- }
395
+ };
399
396
  </script>
400
397
  <style lang="scss" scoped>
401
- @import '../../../includes/scss/all';
398
+ @import "../../../includes/scss/all";
402
399
 
403
400
  .wcl-search {
404
401
  position: relative;
@@ -456,7 +453,7 @@ export default {
456
453
  }
457
454
  }
458
455
 
459
- @include mq('xs') {
456
+ @include mq("xs") {
460
457
  .not-extra-small-screen {
461
458
  display: none;
462
459
  }
@@ -546,7 +543,7 @@ export default {
546
543
  padding-left: 32px;
547
544
 
548
545
  &:before {
549
- content: 'Search';
546
+ content: "Search";
550
547
  }
551
548
 
552
549
  @media screen and (max-width: 767px) {
@@ -626,7 +623,7 @@ export default {
626
623
  padding: 0;
627
624
 
628
625
  &::after {
629
- content: ' ';
626
+ content: " ";
630
627
  position: absolute;
631
628
  height: 16px;
632
629
  width: 11px;
@@ -733,7 +730,7 @@ export default {
733
730
  }
734
731
 
735
732
  /* search list end */
736
- @include mq('xs') {
733
+ @include mq("xs") {
737
734
  .not-extra-small-screen {
738
735
  display: none;
739
736
  }
@@ -746,4 +743,4 @@ export default {
746
743
  width: 85% !important;
747
744
  }
748
745
  }
749
- </style>
746
+ </style>