@worksafevictoria/wcl7.5 1.1.0-beta.2 → 1.1.0

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.
@@ -12,8 +12,7 @@ const config = {
12
12
  options: {}
13
13
  },
14
14
  docs: {
15
- autodocs: 'tag',
16
- defaultName: 'Documentation'
15
+ autodocs: 'tag'
17
16
  }
18
17
  }
19
18
  export default config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worksafevictoria/wcl7.5",
3
- "version": "1.1.0-beta.2",
3
+ "version": "1.1.0",
4
4
  "main": "src/index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,10 +1,8 @@
1
1
  <template>
2
- <div>
3
- <h1>Form Instance</h1>
2
+ <h1>Form Instance</h1>
4
3
  <p>
5
4
  The .vue and .stories.js files for SubComponents/FormInstance (displayed in Storybook under Form) must be copied from current Storybook 6 branch when time to upgrade them. They are causing errors preventing Storybook from being rendered and therefore tested.
6
5
  </p>
7
- </div>
8
6
  </template>
9
7
 
10
8
  <script>
@@ -0,0 +1,8 @@
1
+ import GoogleSearch from './index.vue'
2
+
3
+ export default {
4
+ title: 'SubComponents/GoogleSearch',
5
+ component: GoogleSearch
6
+ }
7
+
8
+ export const Default = {}
@@ -0,0 +1,405 @@
1
+ <template>
2
+ <div class="wcl-search">
3
+ <div class="gcse-search"></div>
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ export default {
9
+ mounted() {
10
+ // console.log('Component mounted')
11
+ this.setupCustomeStyle()
12
+
13
+ // Introduce a delay before setting up addEventListener
14
+ setTimeout(() => {
15
+ this.setupCustomAttr()
16
+ this.handleSearchResultLinkTitle()
17
+ }, 2000) // Adjust the delay time as needed
18
+ },
19
+
20
+ beforeDestroy() {
21
+ // Remove event listeners before the component is destroyed
22
+ const targetNode = document.querySelector('input[name="search"]')
23
+ const buttonNode = document.querySelector('button.gsc-search-button')
24
+
25
+ if (targetNode) {
26
+ // Add keyup.enter event listener
27
+ targetNode.removeEventListener('keyup', this.handleKeyUp)
28
+ buttonNode.removeEventListener('click', this.handleKeyUp)
29
+ }
30
+ const paginationNodes = document.querySelectorAll('.gsc-cursor-page')
31
+ paginationNodes.forEach((paginationNode) => {
32
+ paginationNode.removeEventListener('click', this.handleSearchResultTitle)
33
+ })
34
+ },
35
+
36
+ methods: {
37
+ // Method to customize google search style
38
+ setupCustomeStyle() {
39
+ const script = document.createElement('script')
40
+ script.async = true
41
+ script.src = 'https://cse.google.com/cse.js?cx=53b1506aa03c64160'
42
+ document.head.appendChild(script)
43
+
44
+ // Create a new style element
45
+ const style = document.createElement('style')
46
+ style.id = 'searchStyle' // Assign an ID to the style element
47
+ // The CSS we are going to inject
48
+ const cssVar = 'table.gssb_c {display: none !important;}'
49
+ // Inject the style element into the head
50
+ document.head.appendChild(style)
51
+ // Set the text content of the style element to the CSS text
52
+ style.textContent = cssVar
53
+ },
54
+
55
+ // Method to add google search input attributes
56
+ setupCustomAttr() {
57
+ console.log('setupCustomInputAttr ...')
58
+
59
+ const targetNode = document.querySelector('input[name="search"]')
60
+ const buttonNode = document.querySelector('button.gsc-search-button')
61
+
62
+ if (targetNode) {
63
+ // Add keyup.enter event listener
64
+ targetNode.addEventListener('keyup', this.handleKeyUp)
65
+ buttonNode.addEventListener('click', this.handleKeyUp)
66
+ }
67
+
68
+ this.setupPaginationEvent()
69
+ },
70
+
71
+ setupPaginationEvent() {
72
+ console.log('setupPaginationEvent ....')
73
+ // Introduce a delay before setting up addEventListener on pagination
74
+ setTimeout(() => {
75
+ this.handleSearchResultLinkTitle()
76
+ const paginationNodes = document.querySelectorAll('.gsc-cursor-page')
77
+ console.log('paginationNodes length ..', paginationNodes.length)
78
+
79
+ if (paginationNodes && paginationNodes.length > 0) {
80
+ console.log('FOUND PAGINATION ....', paginationNodes)
81
+
82
+ // Loop through each element and add a click event listener
83
+ paginationNodes.forEach((paginationNode) => {
84
+ // Check if the click event listener has already been added
85
+ if (!paginationNode.clickEventListenerAdded) {
86
+ // Add a click event listener
87
+ paginationNode.addEventListener(
88
+ 'click',
89
+ this.handleSearchResultTitle
90
+ )
91
+ // Mark that the click event listener has been added
92
+ paginationNode.clickEventListenerAdded = true
93
+ console.log('Adding a click event listener')
94
+ }
95
+ })
96
+ }
97
+ }, 2000) // Adjust the delay time as needed
98
+ },
99
+
100
+ // Method to trim text after '|'
101
+ handleSearchResultTitle() {
102
+ //alert('handleSearchResultTitle ....')
103
+ this.setupPaginationEvent()
104
+ },
105
+
106
+ handleSearchResultLinkTitle() {
107
+ //alert('handleSearchResultLinkTitle ....')
108
+ // Get all targetNodes with class "a.gs-title"
109
+ var targetNodes = document.querySelectorAll('a.gs-title')
110
+ console.log('search list title targetNodes :- ', targetNodes)
111
+
112
+ // Loop through each element and hide the text after the "|"
113
+ targetNodes.forEach(function(element) {
114
+ // Get the text content
115
+ var text = element.textContent || element.innerText
116
+
117
+ // Find the index of the "|" symbol
118
+ var pipeIndex = text.indexOf('|')
119
+ console.log('text :- ', text)
120
+ // If the "|" symbol is found, update the text content to display only the part before "|"
121
+ if (pipeIndex !== -1) {
122
+ element.textContent = text.substring(0, pipeIndex).trim()
123
+ }
124
+ })
125
+ },
126
+
127
+ handleKeyUp(event) {
128
+ if (event.key === 'Enter' || event.type === 'click') {
129
+ let keyword = event.key
130
+ ? event.target.value
131
+ : document.querySelector('input[name="search"]').value
132
+
133
+ // console.log('Enter key pressed. Value:', keyword)
134
+
135
+ // Check if the URL does not contain "/search"
136
+ if (keyword && !window.location.href.includes('/search')) {
137
+ let origin = window.location.origin
138
+ let hash = window.location.hash
139
+ let pathname = 'search'
140
+ let URL = origin + '/' + pathname + hash
141
+ // console.log('URL does not contains "/search" ...', URL)
142
+ window.location.assign(URL)
143
+ }
144
+
145
+ this.setupPaginationEvent
146
+ }
147
+ }
148
+ }
149
+ }
150
+ </script>
151
+ <style lang="scss" scoped>
152
+ @import '../../../includes/scss/all';
153
+
154
+ .wcl-search {
155
+ :deep(form.gsc-search-box) {
156
+ position: relative;
157
+ display: -ms-flexbox;
158
+ display: flex;
159
+ -ms-flex-wrap: wrap;
160
+ flex-wrap: wrap;
161
+ -ms-flex-align: stretch;
162
+ align-items: stretch;
163
+ width: 100%;
164
+ }
165
+ :deep(.gsib_a) {
166
+ padding: 0 !important;
167
+ height: 56px;
168
+ }
169
+ :deep(.gsib_b) {
170
+ position: absolute;
171
+ right: 5px;
172
+ top: 15px;
173
+ }
174
+ :deep(.gcsc-more-maybe-branding-root) {
175
+ display: none;
176
+ }
177
+ :deep(table.gsc-input) {
178
+ position: relative;
179
+ }
180
+ :deep(td.gsc-input) {
181
+ border: none;
182
+ padding: 0;
183
+ width: 100%;
184
+ }
185
+ :deep(.gsc-input-box) {
186
+ border: none;
187
+ }
188
+ :deep(input.gsc-input) {
189
+ border-radius: 8px 0px 0px 8px;
190
+ border: 1px solid $gray !important;
191
+ border-right: 0 !important;
192
+ background: none !important;
193
+ color: #495057;
194
+ height: 56px !important;
195
+ position: relative;
196
+ -ms-flex: 1 1 auto;
197
+ flex: 1 1 auto;
198
+ padding: 0.375rem 0.75rem !important;
199
+
200
+ @media screen and (max-width: 320px) {
201
+ width: 220px;
202
+ }
203
+
204
+ &:focus {
205
+ box-shadow: none;
206
+ }
207
+ }
208
+ :deep(.gsc-search-button) {
209
+ display: -ms-flexbox;
210
+ display: flex;
211
+ margin-left: 0px;
212
+ height: 56px;
213
+ margin-top: 0px;
214
+ }
215
+ :deep(button.gsc-search-button) {
216
+ background: $orange;
217
+ border: none;
218
+ border-radius: 0px 8px 8px 0px;
219
+ color: $black;
220
+ display: flex;
221
+ align-items: center;
222
+ height: 56px !important;
223
+ font-size: 16px;
224
+ font-weight: 700;
225
+ padding-right: 32px;
226
+ padding-left: 32px;
227
+
228
+ &:before {
229
+ content: 'Search';
230
+ }
231
+ @media screen and (max-width: 767px) {
232
+ margin-top: 6px;
233
+ }
234
+ @media screen and (max-width: 320px) {
235
+ padding-right: 16px;
236
+ padding-left: 16px;
237
+ }
238
+
239
+ svg {
240
+ fill: black;
241
+ height: 18px;
242
+ width: 18px;
243
+ margin-left: 10px;
244
+ }
245
+
246
+ :focus {
247
+ box-shadow: 0px;
248
+ }
249
+ }
250
+
251
+ :deep(.gsst_a .gscb_a) {
252
+ color: #191919;
253
+ }
254
+ :deep(.gsc-result-info) {
255
+ color: #191919;
256
+ font-size: 16px;
257
+ font-weight: 400;
258
+ }
259
+ :deep(.gsc-above-wrapper-area) {
260
+ padding: 20px 0;
261
+ border-bottom: none;
262
+ }
263
+ /* search list start */
264
+ :deep(.gsc-url-top) {
265
+ display: none;
266
+ }
267
+ :deep(.gsc-table-result) {
268
+ line-height: 1.6;
269
+ padding: 0 5px;
270
+ font-size: 16px;
271
+ font-weight: 400;
272
+ width: 80%;
273
+ b {
274
+ color: #191919;
275
+ font-size: 16px;
276
+ font-weight: normal;
277
+ }
278
+ }
279
+ :deep(.gsc-resultsRoot.gsc-tabData) {
280
+ width: 100%;
281
+ margin-left: auto;
282
+ margin-right: auto;
283
+ padding-left: 15px;
284
+ padding-right: 15px;
285
+
286
+ &:hover {
287
+ border: none;
288
+ }
289
+ }
290
+ :deep(.gs-bidi-start-align.gs-snippet) {
291
+ color: #191919 !important;
292
+ line-height: 24px;
293
+ }
294
+ :deep(.gsc-thumbnail-inside) {
295
+ position: relative;
296
+ padding: 0;
297
+
298
+ &::after {
299
+ content: ' ';
300
+ position: absolute;
301
+ height: 16px;
302
+ width: 11px;
303
+ top: 5px;
304
+ right: 16px;
305
+ background-repeat: no-repeat;
306
+ background-image: url(../../../assets/icons/chev-right.svg);
307
+ background-size: 100%;
308
+ }
309
+ div.gs-title {
310
+ width: 90%;
311
+ margin-bottom: 12px;
312
+ overflow: visible;
313
+ }
314
+ a.gs-title {
315
+ color: #191919 !important;
316
+ font-weight: 700;
317
+ line-height: 24px;
318
+ font-size: 20px;
319
+ border: 3px solid transparent;
320
+ padding-left: 5px;
321
+ padding-right: 5px;
322
+ text-decoration: underline;
323
+
324
+ &:hover {
325
+ border: 3px solid #da47ff;
326
+ color: #006bff !important;
327
+ b {
328
+ color: #006bff !important;
329
+ }
330
+ }
331
+
332
+ b {
333
+ color: #191919 !important;
334
+ font-size: 20px;
335
+ }
336
+ }
337
+ }
338
+ :deep(.gsc-orderby-label) {
339
+ font-size: 16px;
340
+ font-weight: 700;
341
+ color: #191919;
342
+ }
343
+ :deep(.gsc-selected-option-container) {
344
+ background-color: white;
345
+ border-radius: 10px;
346
+ margin-top: 0px;
347
+ padding-top: 6px;
348
+ margin-right: 0;
349
+ margin-left: 4px;
350
+ padding-left: 20px;
351
+ padding-bottom: 6px;
352
+ height: 40px;
353
+ .gsc-selected-option {
354
+ font-size: 16px;
355
+ font-weight: 400;
356
+ line-height: 24px;
357
+ margin-right: 20px;
358
+ }
359
+ }
360
+ :deep(.gsc-control-cse .gsc-option-selector) {
361
+ margin-top: 0;
362
+ margin-right: 10px;
363
+ }
364
+ :deep(.gsc-expansionArea > .gsc-webResult.gsc-result) {
365
+ border: 0;
366
+ flex: 0 0 100%;
367
+ max-width: 100%;
368
+ padding: 0;
369
+ &:first-child {
370
+ border-top: 1px solid #bababa;
371
+ }
372
+ > div {
373
+ border-bottom: 1px solid #bababa;
374
+ padding: 32px 0;
375
+ }
376
+ }
377
+
378
+ :deep(.gsc-results .gsc-cursor-box .gsc-cursor-current-page) {
379
+ background-color: lightgrey;
380
+ }
381
+ :deep(.gsc-results .gsc-cursor-box .gsc-cursor-page) {
382
+ border: 1px solid grey;
383
+ color: #333333;
384
+ padding: 10px 12px;
385
+ border-radius: 5px;
386
+ font-size: 16px;
387
+ font-weight: 400;
388
+ }
389
+ :deep(.gsc-results .gsc-cursor-box) {
390
+ margin-top: 50px;
391
+ }
392
+
393
+ /* search list end */
394
+ @include mq('xs') {
395
+ .not-extra-small-screen {
396
+ display: none;
397
+ }
398
+ }
399
+ }
400
+ @media screen and (max-width: 767px) {
401
+ :deep(.gssb_c) {
402
+ width: 85% !important;
403
+ }
404
+ }
405
+ </style>
@@ -1,32 +1,22 @@
1
1
  <template>
2
2
  <div class="app-search-result">
3
- <div v-if="isLoading" class="app-search-result__loader"></div>
3
+ <div v-if="isLoading" class="app-search-result__loader" ></div>
4
4
  <p
5
5
  v-if="!(isTypeahead && numFound > 0) && !isLoading"
6
6
  class="app-search-result__found"
7
7
  >
8
- <span
9
- >{{ numFound }} results found for
10
- {{ !suggestion ? query : suggestion }}</span
11
- >
12
- </p>
13
- <p
14
- v-if="results && results.length > 0 && suggestion"
15
- class="app-search-result__suggestion"
16
- >
17
- Showing results for <span class="suggestion">{{ suggestion }}</span>
8
+ <span>{{ numFound }} results found for {{ query }}</span>
18
9
  </p>
19
10
  <card-grid
20
11
  v-if="results && results.length > 0 && !isLoading"
21
12
  :force-lg-columns-per-row="1"
22
13
  :force-md-columns-per-row="1"
23
14
  :cards="results"
24
- :is-selectable="false"
15
+ :is-selectable="true"
25
16
  :size="'full'"
26
17
  :row-spacing="'none'"
27
18
  :no-padding-top="true"
28
19
  @selected="onSelectResult"
29
- @selected-title="onSelectCardTitle"
30
20
  >
31
21
  <template v-slot:cardItem="{ card }">
32
22
  <card-grid-item
@@ -39,7 +29,7 @@
39
29
  :description="
40
30
  !isTypeahead && card.description
41
31
  ? truncate(card.description, 144)
42
- : card.htmlSnippet || ''
32
+ : ''
43
33
  "
44
34
  :strip-description-html="true"
45
35
  :taxonomies="{
@@ -47,7 +37,6 @@
47
37
  topic: card.topic,
48
38
  language: card.language
49
39
  }"
50
- :is-card-title-selectable="isCardTitleSelectable"
51
40
  />
52
41
  </template>
53
42
  <template
@@ -69,6 +58,7 @@
69
58
  :aria-label="'search result pagination'"
70
59
  :rows="pageLimit"
71
60
  :offset="offset"
61
+ :max-pages="4"
72
62
  :total="numFound"
73
63
  :align="'start'"
74
64
  @prev="(pg) => $emit('pageChanged', pg.currentPage)"
@@ -123,14 +113,6 @@ export default {
123
113
  isLoading: {
124
114
  type: Boolean,
125
115
  required: false
126
- },
127
- suggestion: {
128
- type: String,
129
- default: null
130
- },
131
- isCardTitleSelectable: {
132
- type: Boolean,
133
- default: false
134
116
  }
135
117
  },
136
118
  methods: {
@@ -143,18 +125,6 @@ export default {
143
125
  }
144
126
  return value
145
127
  },
146
- onSelectCardTitle(card) {
147
- navigateToPath.call(
148
- this,
149
- card?.selectedCard?.link,
150
- card?.ev?.ctrlKey === true || card?.ev?.metaKey === true
151
- )
152
- this.$nextTick(() => this.$emit('selected-title'))
153
-
154
- if (this.$gtm) {
155
- this.fireGTM(card)
156
- }
157
- },
158
128
  onSelectResult(card) {
159
129
  navigateToPath.call(
160
130
  this,
@@ -162,12 +132,6 @@ export default {
162
132
  card?.ev?.ctrlKey === true || card?.ev?.metaKey === true
163
133
  )
164
134
  this.$nextTick(() => this.$emit('selected'))
165
-
166
- if (this.$gtm) {
167
- this.fireGTM(card)
168
- }
169
- },
170
- fireGTM(card) {
171
135
  let attrs = {
172
136
  location:
173
137
  this.$route?.path === '/'
@@ -185,7 +149,9 @@ export default {
185
149
  topic: card?.selectedCard?.topic,
186
150
  language: card?.selectedCard?.language
187
151
  }
188
- this.$gtm.push({ event: 'custom.search.site.result', ...attrs })
152
+ if (this.$gtm) {
153
+ this.$gtm.push({ event: 'custom.search.site.result', ...attrs })
154
+ }
189
155
  },
190
156
  showMoreResults() {
191
157
  if (this.$nuxt) {
@@ -199,13 +165,8 @@ export default {
199
165
  <style lang="scss" scoped>
200
166
  @import '../../../../includes/scss/all';
201
167
  .app-search-result {
202
- &__found,
203
- &__suggestion {
168
+ &__found {
204
169
  margin: 40px 16px;
205
- .suggestion {
206
- font-weight: bold;
207
- color: #006bff;
208
- }
209
170
  }
210
171
 
211
172
  :deep(.card-grid-item__card) {
@@ -253,25 +214,4 @@ export default {
253
214
  }
254
215
  }
255
216
  }
256
-
257
- .wcl-search__google {
258
- .app-search-result {
259
- :deep(.card-grid-item__card) {
260
- border-radius: 0 !important;
261
- border-bottom: solid $gray-alt 1px;
262
- &:hover {
263
- background-color: transparent !important;
264
- }
265
- }
266
- :deep(.card-title) {
267
- text-decoration: underline;
268
- border: 3px solid transparent;
269
- width: auto;
270
- &:hover {
271
- border: 3px solid #da47ff;
272
- color: #006bff !important;
273
- }
274
- }
275
- }
276
- }
277
217
  </style>
@@ -15,32 +15,29 @@ const contentParser = () => {
15
15
 
16
16
  export default {
17
17
  title: 'SubComponents/Search',
18
- component: { Search },
19
- tags: ['autodocs'],
18
+ component: Search,
20
19
  argTypes: {
20
+ pageLimit: {
21
+ control: 'number'
22
+ },
21
23
  contentParser: {
24
+ control: 'function',
22
25
  table: { disable: true }
26
+ },
27
+ isTypeahead: {
28
+ control: 'boolean'
29
+ },
30
+ initialSearchQuery: {
31
+ control: 'text'
23
32
  }
24
- },
33
+ }
34
+ }
35
+
36
+ export const Default = {
25
37
  args: {
26
38
  pageLimit: 5,
27
39
  contentParser: contentParser,
28
40
  isTypeahead: false,
29
- initialSearchQuery: 'Metal',
30
- googleSearchFlag: 'solar',
31
- visibleSearchList: true
41
+ initialSearchQuery: 'Metal'
32
42
  }
33
43
  }
34
-
35
- const DefaultSearch = (args) => ({
36
- components: { Search },
37
- setup () {
38
- return { args }
39
- },
40
- template: `<search
41
- v-bind="args"
42
- ref="solrsearch" />`
43
- })
44
-
45
- export const Default = DefaultSearch.bind({})
46
-