wickes-css2 2.117.0-gift-cards.2 → 2.117.1-develop.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.
Files changed (102) hide show
  1. package/Readme.md +1 -0
  2. package/build/css/category-main.css +1 -1
  3. package/build/css/components/checkout-payment-details-v2.css +1 -1
  4. package/build/css/homepage-main.css +1 -1
  5. package/build/css/kitchen-plp-main.css +1 -1
  6. package/build/css/main.css +1 -1
  7. package/build/css/my-account-main-v2.css +1 -1
  8. package/build/css/my-account-main.css +1 -1
  9. package/build/css/pages/checkout-new.css +1 -1
  10. package/build/css/pages/checkout.css +1 -1
  11. package/build/css/pages/page_my-order.css +1 -1
  12. package/build/css/pages/page_wismo-details.css +1 -1
  13. package/build/css/pdp-main-before-combine.css +1 -1
  14. package/build/css/pdp-main-critical.css +1 -1
  15. package/build/css/pdp-main-non-critical.css +1 -1
  16. package/build/css/pdp-main.css +1 -1
  17. package/build/css/plp-main.css +1 -1
  18. package/build/css/store-locator-main.css +1 -1
  19. package/build/js/account-members.min.js +1 -1
  20. package/build/js/add-project-list-id.min.js +1 -1
  21. package/build/js/address-book.min.js +1 -1
  22. package/build/js/basket.min.js +2 -2
  23. package/build/js/bundle.min.js +1 -1
  24. package/build/js/change-password.min.js +1 -1
  25. package/build/js/checkout.min.js +2 -2
  26. package/build/js/emulation.min.js +83 -425
  27. package/build/js/general.bundle.min.js +1 -1
  28. package/build/js/gift-cards.min.js +1 -1
  29. package/build/js/merged-checkout.min.js +2 -2
  30. package/build/js/page/bloomreach-widget/bloomreach-widget-core.js +3 -1
  31. package/build/js/page/checkout-payment-details.js +10 -114
  32. package/build/js/page/components/gift-cards.js +115 -524
  33. package/build/js/page/ripple/bulk-add.js +2 -2
  34. package/build/js/page/ripple/thumb-gallery.js +8 -14
  35. package/build/js/page/utils/validation.js +1 -54
  36. package/build/js/pdp.bundle.min.js +2 -2
  37. package/build/js/personal-details.min.js +1 -1
  38. package/build/js/plp.bundle.min.js +1 -1
  39. package/build/js/postcode-checker.min.js +1 -1
  40. package/build/js/project-list.min.js +2 -57
  41. package/build/js/quiz.min.js +1 -1
  42. package/build/js/track-my-order.min.js +1 -1
  43. package/package.json +1 -5
  44. package/src/components/checkout-payment-details-v2.hbs +0 -1
  45. package/src/components/checkout_order-summary-new.hbs +0 -6
  46. package/src/components/checkout_payment-new.hbs +8 -35
  47. package/src/components/gift-cards.hbs +15 -8
  48. package/src/components/payments.hbs +6 -7
  49. package/src/components/wismo-payment.hbs +0 -10
  50. package/src/data/data_delivery-address-v2.json +0 -4
  51. package/src/data/data_payments-checkout.json +0 -4
  52. package/src/data/data_wismo.json +1 -46
  53. package/src/data/footer_menu.json +0 -4
  54. package/src/elements/input.hbs +1 -3
  55. package/src/js/components/general/footer.js +56 -63
  56. package/src/js/emulation/checkout-payment-details.js +0 -2
  57. package/src/js/emulation/gift-cards.js +1 -23
  58. package/src/js/emulation/mock.js +20 -21
  59. package/src/js/emulation/postcode-checker.js +1 -1
  60. package/src/js/page/bloomreach-widget/bloomreach-widget-core.js +3 -1
  61. package/src/js/page/checkout-payment-details.js +10 -114
  62. package/src/js/page/components/gift-cards.js +115 -524
  63. package/src/js/page/ripple/bulk-add.js +2 -2
  64. package/src/js/page/ripple/thumb-gallery.js +8 -14
  65. package/src/js/page/utils/validation.js +1 -54
  66. package/src/page_product-details-billie.html +0 -2
  67. package/src/page_product-details-clearpay.html +0 -1
  68. package/src/scss/common/_CTAs.scss +0 -4
  69. package/src/scss/components/_gift-cards.scss +9 -66
  70. package/src/scss/components/_payments-checkout.scss +2 -2
  71. package/src/scss/components/_payments-v2.scss +7 -5
  72. package/src/scss/components/checkout-payment-details-v2.scss +0 -1
  73. package/src/scss/helpers/_CTAs.scss +0 -26
  74. package/src/scss/helpers/_variables.scss +0 -2
  75. package/src/scss/pages/_checkout-confirmation-new.scss +3 -96
  76. package/src/scss/pages/page_wismo-details.scss +0 -29
  77. package/src/sitemap.html +0 -24
  78. package/build/img/payment/checkout/giftcard.svg +0 -28
  79. package/build/img/payment/footer/giftcard.svg +0 -28
  80. package/build/js/page/components/postcode-lookup/postcode-lookup-api.js +0 -56
  81. package/build/js/page/components/postcode-lookup/postcode-lookup-render.js +0 -98
  82. package/build/js/page/components/postcode-lookup/postcode-lookup-validation.js +0 -81
  83. package/build/js/page/components/postcode-lookup.js +0 -503
  84. package/build/js/page/utils/address-utils.js +0 -32
  85. package/src/components/order-address.hbs +0 -28
  86. package/src/components/postcode-lookup-v2.hbs +0 -85
  87. package/src/components/wismo-giftcard-payment-item.hbs +0 -29
  88. package/src/data/data_checkout-giftcards.json +0 -7
  89. package/src/data/data_postcode-lookup.json +0 -200
  90. package/src/img/payment/checkout/giftcard.svg +0 -28
  91. package/src/img/payment/footer/giftcard.svg +0 -28
  92. package/src/js/emulation/postcode-lookup.js +0 -122
  93. package/src/js/page/components/postcode-lookup/postcode-lookup-api.js +0 -56
  94. package/src/js/page/components/postcode-lookup/postcode-lookup-render.js +0 -98
  95. package/src/js/page/components/postcode-lookup/postcode-lookup-validation.js +0 -81
  96. package/src/js/page/components/postcode-lookup.js +0 -503
  97. package/src/js/page/utils/address-utils.js +0 -32
  98. package/src/page_checkout_confirmation-gift-card-split-payment.html +0 -339
  99. package/src/page_checkout_confirmation-gift-card.html +0 -339
  100. package/src/page_my_account_payment_info_gift_cards.html +0 -96
  101. package/src/page_my_account_payment_info_gift_cards_split_payment.html +0 -96
  102. package/src/scss/components/_postcode-lookup-v2.scss +0 -164
@@ -1,7 +1,6 @@
1
1
  import { initializeInputToggle } from '../utils/show-hide-input';
2
2
  import { updateOrderSummary } from './order-summary';
3
- import { createPostcodeLookup } from './postcode-lookup';
4
- import { hideLoader, showLoader } from '../utils/loader';
3
+ import { hideLoader, showLoader, appendLoader } from '../utils/loader';
5
4
  import {
6
5
  ADD_GIFT_CARD,
7
6
  buildHintContext,
@@ -21,18 +20,7 @@ import {
21
20
  DEFAULT_PAY_ERROR_MESSAGE,
22
21
  } from '../utils/gift-cards-utils';
23
22
 
24
- import {
25
- bindBlurValidation,
26
- clearErrorText,
27
- isAntiXssValid,
28
- isElementInViewport,
29
- removeErrorStyling,
30
- resetBlurValidation,
31
- validateExactDigits,
32
- validateFieldByRule,
33
- } from '../utils/validation';
34
- import errorMessages from '../utils/errorMesages';
35
- import { scrollToElement } from '../utils/helpers';
23
+ import { clearErrorText, validateExactDigits } from '../utils/validation';
36
24
  import {
37
25
  createGcNumberInputHandler,
38
26
  digitsOnlyKeypress,
@@ -54,13 +42,6 @@ const notificationTpl = require('../../../elements/notifications.hbs');
54
42
 
55
43
  var Wick = window.Wick || {};
56
44
 
57
- const ORDER_NAME_RULES = {
58
- orderFirstName: { required: true, validate: isAntiXssValid, message: errorMessages.errorName },
59
- orderSurname: { required: true, validate: isAntiXssValid, message: errorMessages.errorSurname },
60
- };
61
- const ORDER_ADDRESS_SCROLL_OFFSET = 100;
62
- const ORDER_ADDRESS_LOOKUP_CONTEXT = 'order-address';
63
-
64
45
  Wick.GiftCard = {
65
46
  ADD_GIFT_CARD,
66
47
  REMOVE_GIFT_CARD,
@@ -133,19 +114,6 @@ Wick.GiftCard = {
133
114
  '[data-apple-pay],[data-google-pay],[data-paypal],[data-klarna],[data-billie],[data-clearpay],[data-existing-card]',
134
115
  hiddenCard: 'checkout-payment-details__card-details_hidden',
135
116
  cardDetails: '.checkout-payment-details__card-details',
136
- orderAddress: '[data-order-address]',
137
- orderFirstName: '#order-first-name',
138
- orderSurname: '#order-surname',
139
- paymentMethodCheckedSel: 'input[name="payment-method"]:checked',
140
- paymentMethodCardValue: 'card',
141
- paypageIframeWrapSel: '.hop-iframe__wrapper',
142
- cardValidationErrorRowSel: '.form-row_validation-error',
143
- cardValidationErrorRowClass: 'form-row_validation-error',
144
- cardValidationErrorTextSel: '.form-row__error',
145
- paypageFormSel: '#hopPostForm',
146
- paypageIframeSel: '#hopIframe',
147
- paypageCardDetailsSel: '.checkout-payment-details__card-details',
148
- wrapper: '.giftcard__wrapper',
149
117
  },
150
118
 
151
119
  messages: {
@@ -155,17 +123,12 @@ Wick.GiftCard = {
155
123
  ctaGiftcardText: 'Pay with Gift Card',
156
124
  },
157
125
 
158
- collapseTargets: [
159
- '.billing-address input, .billing-address select, .billing-address textarea',
160
- '.billing-address [data-finder], .billing-address [data-manually]',
161
- ].join(','),
162
-
163
126
  maxChips: 3,
164
127
  successTimer: null,
128
+ pendingServerGiftCards: null,
165
129
  altPaymentInfosLocked: false,
166
130
  altPaymentPanelsLocked: false,
167
131
  summaryTotal: null,
168
- orderAddressLookup: null,
169
132
 
170
133
  resetPinToggle($root) {
171
134
  const {
@@ -203,90 +166,6 @@ Wick.GiftCard = {
203
166
  $pinInput.trigger(passwordToggleEvent);
204
167
  },
205
168
 
206
- isPanelOpen($root) {
207
- const $panel = $root.find(this.el.panel);
208
- return $panel.length ? $panel.prop('hidden') === false : false;
209
- },
210
-
211
- openPaypage($container) {
212
- const {
213
- paypageFormSel,
214
- paypageIframeSel,
215
- paypageIframeWrapSel,
216
- paypageCardDetailsSel,
217
- hiddenCard,
218
- } = this.el;
219
-
220
- const $cardDetails = $container.find(paypageCardDetailsSel);
221
- const $wrap = $container.find(paypageIframeWrapSel);
222
-
223
- $cardDetails.removeClass(hiddenCard).show();
224
- $wrap.show();
225
-
226
- const $form = $container.find(paypageFormSel);
227
-
228
- const form = $form.get(0);
229
- if (!form) return;
230
-
231
- const $oldIframe = $container.find(paypageIframeSel);
232
- if ($oldIframe.length) {
233
- const old = $oldIframe.get(0);
234
- const newIframe = old.cloneNode(true);
235
-
236
- newIframe.src = old.getAttribute('src') || newIframe.src || '';
237
- old.parentNode.replaceChild(newIframe, old);
238
-
239
- const iframeName = newIframe.getAttribute('name') || newIframe.name;
240
- if (iframeName) form.setAttribute('target', iframeName);
241
- }
242
- },
243
-
244
- getAppliedChipsCount($root) {
245
- const { giftcardRow, chipList, chip } = this.el;
246
- const $row = $root.closest(giftcardRow);
247
- return $row.length ? $row.find(`${chipList} ${chip}`).length : 0;
248
- },
249
-
250
- collapseKeepValues($root) {
251
- const { toggle, panel, hint, expandedAttr } = this.el;
252
-
253
- $root.find(panel).prop('hidden', true);
254
- $root.find(toggle).attr(expandedAttr, 'false').show();
255
-
256
- const zeroTotal = this.summaryTotal != null ? isZeroAmount(this.summaryTotal) : false;
257
- $root.find(hint)[zeroTotal ? 'hide' : 'show']();
258
- },
259
-
260
- handleCollapseTrigger(e) {
261
- const $target = $(e.target);
262
-
263
- const isCheckbox = $target.is('#chb-payment-details-card');
264
- const isInBilling = $target.closest('.billing-address').length > 0;
265
-
266
- if (!isCheckbox && !isInBilling) return;
267
-
268
- const $container = $target.closest(this.el.checkoutContainer);
269
- if (!$container.length) return;
270
-
271
- const $giftcard = $container.find(this.el.block).first();
272
- if (!$giftcard.length) return;
273
-
274
- if (!this.isPanelOpen($giftcard)) return;
275
-
276
- const chipsCount = this.getAppliedChipsCount($giftcard);
277
-
278
- const { panel, toggle, expandedAttr } = this.el;
279
-
280
- if (chipsCount > 0) {
281
- this.updateHintVisibility($giftcard);
282
- this.collapseGiftcardPanel($container, { hideIfHasChips: true });
283
- $giftcard.find(panel).prop('hidden', true).hide();
284
- $giftcard.find(toggle).attr(expandedAttr, 'false');
285
- return;
286
- }
287
- this.collapseKeepValues($giftcard);
288
- },
289
-
290
169
  resetForm($root) {
291
170
  const { number, pin, note } = this.el;
292
171
  const $num = $root.find(number);
@@ -316,102 +195,71 @@ Wick.GiftCard = {
316
195
 
317
196
  open($root) {
318
197
  const { toggle, panel, hint, pin, expandedAttr, passwordToggleEvent } = this.el;
198
+ this.hideBanner($root);
319
199
  $root.show();
320
200
 
321
- $root.find(panel).prop('hidden', false).show();
201
+ $root.find(panel).prop('hidden', false);
322
202
  $root.find(toggle).attr(expandedAttr, 'true').hide();
323
203
  $root.find(hint).hide();
324
204
  $root.find(pin).trigger(passwordToggleEvent);
325
205
  },
326
206
 
327
207
  close($root) {
328
- const { toggle, panel, expandedAttr, giftcardRow, chipList, chip, hint } = this.el;
208
+ const { toggle, panel, loader, expandedAttr } = this.el;
329
209
  const $toggle = $root.find(toggle);
330
210
  const $panel = $root.find(panel);
331
- const $pageLoader = this.getPageLoader();
211
+ const $loader = $root.find(loader);
332
212
 
333
- showLoader($pageLoader);
213
+ showLoader($loader);
334
214
 
335
215
  setTimeout(() => {
336
- hideLoader($pageLoader);
216
+ hideLoader($loader);
337
217
 
338
218
  $panel.prop('hidden', true);
339
219
  $toggle.attr(expandedAttr, 'false').show().trigger('focus');
340
-
341
- const $row = $root.closest(giftcardRow);
342
- const count = $row.find(`${chipList} ${chip}`).length;
343
- const zeroTotal = this.summaryTotal != null ? isZeroAmount(this.summaryTotal) : false;
344
-
345
- if (count === 0) {
346
- $root.find(hint)[zeroTotal ? 'hide' : 'show']();
347
- return;
348
- }
349
-
350
220
  this.updateHintVisibility($root);
351
221
  }, 1000);
352
222
  },
353
223
 
354
224
  showSubmitSpinner($root) {
355
225
  const { panel, toggle, hint, expandedAttr } = this.el;
356
-
357
226
  $root.find(panel).prop('hidden', true);
358
227
  $root.find(toggle).attr(expandedAttr, 'false').show().trigger('focus');
359
228
  $root.find(hint).show();
360
-
361
- this.lockPaymentsForSuccess($root);
362
-
363
229
  this.showSuccess($root);
364
230
  },
365
231
 
366
232
  handleToggleClick(e) {
367
233
  e.preventDefault();
368
-
369
- const $root = $(e.currentTarget).closest(this.el.block);
370
- const $container = $root.closest(this.el.checkoutContainer);
371
-
372
- if (
373
- $container.length &&
374
- this.isCardMethodSelected($container) &&
375
- this.isPaypageOpen($container)
376
- ) {
377
- this.clearPaypageAndCollapse($container);
378
- }
379
-
380
- this.open($root);
381
- this.updateCtaButton($root);
234
+ this.open($(e.currentTarget).closest(this.el.$blocks));
382
235
  },
383
236
 
384
237
  handleCloseClick(e) {
385
238
  e.preventDefault();
386
- const $root = $(e.currentTarget).closest(this.el.block);
239
+ const $root = $(e.currentTarget).closest(this.el.$blocks);
387
240
  this.resetForm($root);
388
241
  this.close($root);
389
242
  },
390
243
 
391
244
  finalizeSuccess($root, $success) {
245
+ let { panel, toggle, hint, expandedAttr } = this.el;
246
+
392
247
  if ($success && $success.length) {
393
248
  $success.attr('hidden', 'hidden').removeClass('fade show').off('transitionend');
394
249
  }
395
250
 
396
251
  this.resetForm($root);
397
- this.updateHintVisibility($root);
398
-
399
- this.successTimer = null;
400
- },
401
-
402
- lockPaymentsForSuccess($root) {
403
- const $giftcard = $root.closest(this.el.block);
404
- const $container = $giftcard.closest(this.el.checkoutContainer);
405
-
406
- this.toggleAltPayments($giftcard, false);
407
- this.toggleAltPaymentInfos($giftcard, false);
408
-
409
- $container.find(this.el.billingAddress).show();
252
+ $root.find(panel).prop('hidden', true);
253
+ $root.find(toggle).attr(expandedAttr, 'false').show();
254
+ $root.find(hint).show();
410
255
 
411
- $container.find(this.el.altPaymentRowsAttr).closest(this.el.formRow).hide();
256
+ if (this.pendingServerGiftCards) {
257
+ this.renderGiftCardsFromList($root, this.pendingServerGiftCards);
258
+ this.pendingServerGiftCards = null;
259
+ }
412
260
 
413
- this.altPaymentPanelsLocked = true;
414
- this.altPaymentInfosLocked = true;
261
+ this.updateHintVisibility($root);
262
+ this.successTimer = null;
415
263
  },
416
264
 
417
265
  showSuccess($root) {
@@ -430,16 +278,15 @@ Wick.GiftCard = {
430
278
 
431
279
  this.successTimer = setTimeout(() => {
432
280
  $success.removeClass('show');
433
-
434
281
  const handler = () => this.finalizeSuccess($root, $success);
435
- $success.on('transitionend', handler);
436
282
 
283
+ $success.on('transitionend', handler);
437
284
  setTimeout(handler, 200);
438
- }, 1500);
285
+ }, 3000);
439
286
  },
440
287
 
441
288
  handleFormSubmit(e) {
442
- const { number, block } = this.el;
289
+ const { number, block, giftcardRow, loaderChip } = this.el;
443
290
  e.preventDefault();
444
291
 
445
292
  const $root = $(e.currentTarget).closest(block);
@@ -451,50 +298,48 @@ Wick.GiftCard = {
451
298
  const $numInput = $root.find(this.el.number);
452
299
  const $pinInput = $root.find(this.el.pin);
453
300
 
301
+ const numberBlurOpts = {
302
+ fieldSelector: this.el.field,
303
+ errorTextSelector: this.el.errorText,
304
+ errorClass: this.el.fieldError,
305
+ ariaInvalidAttr: this.el.ariaInvalidAttr,
306
+ numberMessage: this.messages.numberMessage,
307
+ };
308
+
309
+ const pinBlurOpts = {
310
+ fieldSelector: this.el.field,
311
+ errorTextSelector: this.el.errorText,
312
+ errorClass: this.el.fieldError,
313
+ ariaInvalidAttr: this.el.ariaInvalidAttr,
314
+ pinMessage: this.messages.pinMessage,
315
+ };
316
+
454
317
  const okNumber = validateExactDigits($numInput, 16, this.messages.numberMessage, this.el);
455
318
  const okPin = validateExactDigits($pinInput, 8, this.messages.pinMessage, this.el);
456
319
 
457
320
  if (!(okNumber && okPin)) {
458
- handleGcNumberBlur(
459
- { currentTarget: $numInput[0] },
460
- {
461
- fieldSelector: this.el.field,
462
- errorTextSelector: this.el.errorText,
463
- errorClass: this.el.fieldError,
464
- ariaInvalidAttr: this.el.ariaInvalidAttr,
465
- numberMessage: this.messages.numberMessage,
466
- }
467
- );
468
-
469
- handleGcPinBlur(
470
- { currentTarget: $pinInput[0] },
471
- {
472
- fieldSelector: this.el.field,
473
- errorTextSelector: this.el.errorText,
474
- errorClass: this.el.fieldError,
475
- ariaInvalidAttr: this.el.ariaInvalidAttr,
476
- pinMessage: this.messages.pinMessage,
477
- }
478
- );
479
-
321
+ handleGcNumberBlur({ currentTarget: $numInput[0] }, numberBlurOpts);
322
+ handleGcPinBlur({ currentTarget: $pinInput[0] }, pinBlurOpts);
480
323
  (!okNumber ? $numInput : $pinInput).trigger('focus');
481
324
  return;
482
325
  }
483
326
 
484
327
  const giftCardNumber = this.getNumberValue($root);
485
328
  const pin = this.getPinValue($root);
329
+ const $row = $root.closest(giftcardRow);
486
330
 
487
- const $pageLoader = this.getPageLoader();
488
- showLoader($pageLoader);
331
+ let $loader = $row.children(loaderChip);
332
+
333
+ if (!$loader.length) {
334
+ appendLoader({ wrapper: $row });
335
+ $loader = $row.children(loaderChip).last();
336
+ }
489
337
 
490
- verifyGiftCard($pageLoader, giftCardNumber, pin)
338
+ verifyGiftCard($loader, giftCardNumber, pin)
491
339
  .then((res) => this.handleVerifyResponse($root, res))
492
340
  .catch((err) => {
493
341
  const msg = this.getErrorMessage(err);
494
342
  this.showBannerError($root, msg);
495
- })
496
- .finally(() => {
497
- hideLoader($pageLoader);
498
343
  });
499
344
  },
500
345
 
@@ -505,20 +350,18 @@ Wick.GiftCard = {
505
350
  return;
506
351
  }
507
352
 
508
- let summaryData;
509
- if (res.orderTotal != null || res.giftCardTotal != null) {
510
- summaryData = { total: res.orderTotal, giftCardApplied: res.giftCardTotal };
353
+ this.pendingServerGiftCards = res.giftCards.slice();
511
354
 
512
- updateOrderSummary(summaryData, buildSummaryEqualMap(summaryData), true);
355
+ if (res.orderTotal != null || res.giftCardTotal != null) {
356
+ const data = { total: res.orderTotal, giftCardApplied: res.giftCardTotal };
357
+ updateOrderSummary(data, buildSummaryEqualMap(data), true);
513
358
  this.summaryTotal = res.orderTotal;
514
-
515
359
  this.toggleBillingDescrForZero($root);
516
360
  this.updateCtaButton($root);
517
361
  }
518
362
 
519
363
  this.resetForm($root);
520
364
  this.showSubmitSpinner($root);
521
- this.renderGiftCardsFromList($root, res.giftCards);
522
365
  return;
523
366
  }
524
367
 
@@ -526,9 +369,10 @@ Wick.GiftCard = {
526
369
  this.showBannerError($root, msg);
527
370
  },
528
371
 
529
- updateHintVisibility($root, opts = {}) {
372
+ updateHintVisibility($root) {
530
373
  const {
531
374
  chipList,
375
+ giftcardRow,
532
376
  hint,
533
377
  panel,
534
378
  toggle,
@@ -538,63 +382,61 @@ Wick.GiftCard = {
538
382
  chip,
539
383
  block,
540
384
  body,
541
- fieldError,
542
385
  } = this.el;
543
386
 
544
- const { skipResetForm = false } = opts;
545
-
546
- const $giftcard = $root.closest(block).length ? $root.closest(block) : $root;
547
- const $summary = this.ensureSummaryContainer($giftcard);
548
- const count = $summary.find(`${chipList} ${chip}`).length;
549
-
387
+ const $row = $root.closest(giftcardRow);
388
+ const $giftcard = $row.find(block).first();
389
+ const count = $row.find(`${chipList} ${chip}`).length;
550
390
  const limit = this.maxChips || 3;
391
+
551
392
  const zeroTotal = this.summaryTotal != null ? isZeroAmount(this.summaryTotal) : false;
552
393
 
553
394
  this.toggleAltPayments($giftcard, count === 0);
554
395
  this.toggleAltPaymentInfos($giftcard, count === 0);
555
- const panelOpen = this.isPanelOpen($giftcard);
556
396
 
557
- if (count === 0) {
558
- $summary.hide();
559
-
560
- $giftcard.show();
561
-
562
- if (!skipResetForm) {
563
- this.resetForm($giftcard);
397
+ if (count > 0) {
398
+ if (!this.altPaymentPanelsLocked) {
399
+ this.showOnlyBillingAddress($giftcard);
400
+ this.altPaymentPanelsLocked = true;
401
+ } else {
402
+ this.showOnlyBillingAddress($giftcard);
564
403
  }
565
-
566
- if (panelOpen) {
567
- this.open($giftcard);
404
+ } else {
405
+ if (!this.altPaymentPanelsLocked) {
406
+ this.toggleAltPayments($giftcard, true);
407
+ this.toggleAltPaymentInfos($giftcard, true);
568
408
  } else {
569
- $giftcard.find(panel).prop('hidden', true);
570
- $giftcard.find(toggle).attr(expandedAttr, 'false').show();
571
- $giftcard.find(hint)[zeroTotal ? 'hide' : 'show']();
409
+ this.showOnlyBillingAddress($giftcard);
572
410
  }
411
+ }
412
+
413
+ const $summary = this.ensureSummaryContainer($giftcard);
573
414
 
415
+ if (count === 0) {
416
+ $summary.hide();
417
+ $giftcard.show();
418
+ this.resetForm($giftcard);
419
+ $giftcard.find(panel).prop('hidden', true);
420
+ $giftcard.find(toggle).attr(expandedAttr, 'false').show();
421
+ $giftcard.find(hint)[zeroTotal ? 'hide' : 'show']();
574
422
  this.updateCtaButton($giftcard);
575
423
  return;
576
424
  }
577
425
 
578
426
  this.setBillingLabelToCard($giftcard);
579
-
580
427
  $summary.show();
428
+ $giftcard.hide();
581
429
  $giftcard.find(hint).hide();
582
- const hasError = $giftcard.find(`.${fieldError}`).length > 0;
583
-
584
- const shouldHideGiftcard = count > 0 && !panelOpen && !hasError;
585
-
586
- $giftcard.toggle(!shouldHideGiftcard);
587
430
 
588
431
  const ctx = buildHintContext(count, limit, zeroTotal);
589
432
  const html = giftCardsHint(ctx);
590
-
591
433
  const $old = $summary.find(summaryHint).first();
592
434
  const $new = $(html);
593
435
 
594
436
  if ($old.length) $old.replaceWith($new);
595
437
  else $summary.append($new);
596
438
 
597
- if (zeroTotal || panelOpen) {
439
+ if (zeroTotal) {
598
440
  $summary.find(summaryHint).hide();
599
441
  }
600
442
 
@@ -610,21 +452,18 @@ Wick.GiftCard = {
610
452
  },
611
453
 
612
454
  toggleAltPaymentInfos($root, show) {
613
- const { checkoutContainer, billieInfo, klarnaInfo, paymentMethodCheckedSel } = this.el;
614
-
455
+ const { checkoutContainer, billieInfo, klarnaInfo } = this.el;
615
456
  const $container = $root.closest(checkoutContainer);
616
457
 
617
458
  if (this.altPaymentInfosLocked) {
618
459
  show = false;
619
460
  }
620
461
 
621
- const currentMethod = $container.find(paymentMethodCheckedSel).val();
622
-
623
- const showBillie = show && currentMethod === 'billie';
624
- const showKlarna = show && currentMethod === 'klarna';
625
-
626
- $container.find(billieInfo)[showBillie ? 'show' : 'hide']();
627
- $container.find(klarnaInfo)[showKlarna ? 'show' : 'hide']();
462
+ [$container.find(billieInfo), $container.find(klarnaInfo)].forEach(($panel) => {
463
+ if ($panel && $panel.length) {
464
+ $panel[show ? 'show' : 'hide']();
465
+ }
466
+ });
628
467
 
629
468
  if (!show) this.altPaymentInfosLocked = true;
630
469
  },
@@ -693,48 +532,16 @@ Wick.GiftCard = {
693
532
 
694
533
  handleAddAnotherClick(e) {
695
534
  e.preventDefault();
696
-
697
- const {
698
- giftcardRow,
699
- chipList,
700
- chip,
701
- block,
702
- number,
703
- pin,
704
- summaryHint,
705
- checkoutContainer,
706
- fieldError,
707
- notificationRoot,
708
- } = this.el;
535
+ const { giftcardRow, chipList, chip, block, number, summaryHint } = this.el;
709
536
 
710
537
  const $row = $(e.currentTarget).closest(giftcardRow);
711
-
712
- const $container = $row.closest(checkoutContainer);
713
- if (
714
- $container.length &&
715
- this.isCardMethodSelected($container) &&
716
- this.isPaypageOpen($container)
717
- ) {
718
- this.clearPaypageAndCollapse($container);
719
- }
720
-
721
538
  const count = $row.find(`${chipList} ${chip}`).length;
722
539
  if (count >= this.maxChips) return;
723
540
 
724
541
  const $giftcard = $row.find(block).first();
725
-
726
- const hasDraft =
727
- String($giftcard.find(number).val() || '').trim().length > 0 ||
728
- String($giftcard.find(pin).val() || '').trim().length > 0;
729
-
730
- const hasFieldError = $giftcard.find(`.${fieldError}`).length > 0;
731
- const hasBannerError = $giftcard.find(notificationRoot).length > 0;
732
-
733
- if (!hasDraft && !hasFieldError && !hasBannerError) {
734
- this.resetForm($giftcard);
735
- }
736
-
542
+ this.resetForm($giftcard);
737
543
  this.open($giftcard);
544
+
738
545
  $row.find(summaryHint).hide();
739
546
 
740
547
  setTimeout(() => {
@@ -742,43 +549,6 @@ Wick.GiftCard = {
742
549
  }, 0);
743
550
  },
744
551
 
745
- isCardMethodSelected($container) {
746
- const { paymentMethodCheckedSel, paymentMethodCardValue } = this.el;
747
-
748
- const $checked = $container.find(paymentMethodCheckedSel);
749
- return $checked.length && $checked.val() === paymentMethodCardValue;
750
- },
751
-
752
- isPaypageOpen($container) {
753
- const { paypageIframeWrapSel } = this.el;
754
-
755
- const $wrap = $container.find(paypageIframeWrapSel);
756
- return $wrap.length ? $wrap.is(':visible') : false;
757
- },
758
-
759
- clearPaypageAndCollapse($container) {
760
- const {
761
- cardDetails,
762
- hiddenCard,
763
- paypageIframeWrapSel,
764
- cardValidationErrorRowSel,
765
- cardValidationErrorRowClass,
766
- cardValidationErrorTextSel,
767
- } = this.el;
768
-
769
- const $cardDetails = $container.find(cardDetails);
770
- if (!$cardDetails.length) return;
771
-
772
- $cardDetails.addClass(hiddenCard).hide();
773
- $cardDetails.find(paypageIframeWrapSel).hide();
774
-
775
- $cardDetails
776
- .find(cardValidationErrorRowSel)
777
- .removeClass(cardValidationErrorRowClass)
778
- .find(cardValidationErrorTextSel)
779
- .remove();
780
- },
781
-
782
552
  getErrorMessage(payload) {
783
553
  const code =
784
554
  payload && (typeof payload.code === 'number' || typeof payload.code === 'string')
@@ -790,8 +560,7 @@ Wick.GiftCard = {
790
560
 
791
561
  handleChipCloseClick(e) {
792
562
  e.preventDefault();
793
-
794
- const { chip, giftcardRow, block, giftcardChipClose, chipList } = this.el;
563
+ const { chip, giftcardRow, block, giftcardChipClose, chipList, loaderChip } = this.el;
795
564
 
796
565
  const $clickedChip = $(e.currentTarget).closest(chip);
797
566
  const $row = $clickedChip.closest(giftcardRow);
@@ -802,19 +571,22 @@ Wick.GiftCard = {
802
571
  const index = $chips.index($clickedChip);
803
572
  if (index < 0) return;
804
573
 
805
- $row.find(giftcardChipClose).css('pointer-events', 'none').attr('aria-disabled', 'true');
574
+ let $loader = $row.children(loaderChip);
575
+ if (!$loader.length) {
576
+ appendLoader({ wrapper: $row });
577
+ $loader = $row.children(loaderChip).last();
578
+ }
806
579
 
807
- const $pageLoader = this.getPageLoader();
808
- showLoader($pageLoader);
580
+ $row.find(giftcardChipClose).css('pointer-events', 'none').attr('aria-disabled', 'true');
809
581
 
810
- removeGiftCard($pageLoader, index)
582
+ removeGiftCard($loader, index)
811
583
  .then((res) => this.handleRemoveResponse($giftcard, res))
812
584
  .catch((err) => {
813
585
  const msg = this.getErrorMessage(err);
814
586
  this.showBannerError($giftcard, msg);
815
587
  })
816
588
  .finally(() => {
817
- hideLoader($pageLoader);
589
+ hideLoader($loader);
818
590
  $row.find(giftcardChipClose).css('pointer-events', '').removeAttr('aria-disabled');
819
591
  });
820
592
  },
@@ -825,10 +597,7 @@ Wick.GiftCard = {
825
597
  const data = { total: res.orderTotal, giftCardApplied: res.giftCardTotal };
826
598
  this.summaryTotal = res.orderTotal;
827
599
 
828
- this.renderGiftCardsFromList($giftcard, giftCardsList, {
829
- ...data,
830
- skipResetForm: true,
831
- });
600
+ this.renderGiftCardsFromList($giftcard, giftCardsList, data);
832
601
 
833
602
  if (res.orderTotal != null || res.giftCardTotal != null) {
834
603
  updateOrderSummary(data, buildSummaryEqualMap(data), true);
@@ -856,14 +625,14 @@ Wick.GiftCard = {
856
625
  },
857
626
 
858
627
  getPageLoader() {
859
- const $pageLoader = $(this.el.pageLoader);
860
- if (!$pageLoader.parent().is('body')) $pageLoader.appendTo('body');
861
- return $pageLoader;
628
+ const $pl = $(this.el.pageLoader);
629
+ if (!$pl.parent().is('body')) $pl.appendTo('body');
630
+ return $pl;
862
631
  },
863
632
 
864
633
  showPageLoader() {
865
- const $pageLoader = this.getPageLoader();
866
- showLoader($pageLoader);
634
+ const $pl = this.getPageLoader();
635
+ showLoader($pl);
867
636
  },
868
637
 
869
638
  updateCtaButton($scope) {
@@ -888,67 +657,13 @@ Wick.GiftCard = {
888
657
  }
889
658
  },
890
659
 
891
- toggleOrderAddress($scope, show) {
892
- const $container = $scope.closest(this.el.checkoutContainer);
893
- const $orderAddress = $container.find(this.el.orderAddress);
894
- if (!$orderAddress.length) return;
895
-
896
- const wasShown = !$orderAddress.hasClass('d-none');
897
- if (wasShown === show) return;
898
-
899
- $orderAddress.toggleClass('d-none', !show);
900
-
901
- if (this.orderAddressLookup) this.orderAddressLookup.setShown(show);
902
- },
903
-
904
- validateOrderNames() {
905
- let $firstInvalid = null;
906
-
907
- Object.keys(ORDER_NAME_RULES).forEach((key) => {
908
- const $field = $(this.el[key]);
909
- const isValid = validateFieldByRule($field, ORDER_NAME_RULES[key]);
910
-
911
- if (!isValid && !$firstInvalid) $firstInvalid = $field;
912
- });
913
-
914
- return $firstInvalid;
915
- },
916
-
917
- isOrderAddressValid() {
918
- const $invalidName = this.validateOrderNames();
919
- const isLookupValid =
920
- !this.orderAddressLookup ||
921
- this.orderAddressLookup.validate({ shouldScroll: !$invalidName });
922
-
923
- if ($invalidName) {
924
- const $row = $invalidName.closest(this.el.formRow);
925
- if (!isElementInViewport($row)) scrollToElement($row, ORDER_ADDRESS_SCROLL_OFFSET);
926
- }
927
-
928
- return !$invalidName && isLookupValid;
929
- },
930
-
931
- resetOrderAddress() {
932
- Object.keys(ORDER_NAME_RULES).forEach((key) => {
933
- const $field = $(this.el[key]);
934
- $field.val('');
935
- removeErrorStyling($field.closest(this.el.formRow));
936
- resetBlurValidation($field);
937
- });
938
-
939
- if (this.orderAddressLookup) this.orderAddressLookup.reset();
940
- },
941
-
942
660
  toggleBillingDescrForZero($scope) {
943
661
  const $container = $scope.closest(this.el.checkoutContainer);
944
662
  const $descr = $container.find(this.el.checkoutPaymentFields);
945
- const isFullyCovered = isZeroAmount(this.summaryTotal);
946
-
947
- this.toggleOrderAddress($scope, isFullyCovered);
948
-
949
663
  if (!$descr.length) return;
950
664
 
951
- $descr[isFullyCovered ? 'hide' : 'show']();
665
+ const shouldHide = isZeroAmount(this.summaryTotal);
666
+ $descr[shouldHide ? 'hide' : 'show']();
952
667
  },
953
668
 
954
669
  getNumberValue($root) {
@@ -975,8 +690,6 @@ Wick.GiftCard = {
975
690
  e.stopPropagation();
976
691
  e.stopImmediatePropagation();
977
692
 
978
- if (!self.isOrderAddressValid()) return;
979
-
980
693
  const $scope = $btn.closest(self.el.checkoutContainer).find(self.el.block).first();
981
694
  const $root = $scope.length ? $scope : $(self.el.block).first();
982
695
 
@@ -1006,8 +719,8 @@ Wick.GiftCard = {
1006
719
  }
1007
720
  })
1008
721
  .finally(() => {
1009
- const $pageLoader = self.getPageLoader();
1010
- hideLoader($pageLoader);
722
+ const $pl = self.getPageLoader();
723
+ hideLoader($pl);
1011
724
  });
1012
725
  });
1013
726
  },
@@ -1029,32 +742,6 @@ Wick.GiftCard = {
1029
742
  $inline.find(inlineHeader).after(html);
1030
743
  },
1031
744
 
1032
- clearErrorsOnly($root) {
1033
- const { number, pin, note, field, errorText, fieldError, ariaInvalidAttr } = this.el;
1034
-
1035
- const $num = $root.find(number);
1036
- const $pin = $root.find(pin);
1037
-
1038
- clearErrorText($num, field, errorText, fieldError, ariaInvalidAttr);
1039
- clearErrorText($pin, field, errorText, fieldError, ariaInvalidAttr);
1040
-
1041
- $root.find(note).remove();
1042
-
1043
- this.hideBanner($root);
1044
- },
1045
-
1046
- clearErrorsIfEmptyOnInit($root) {
1047
- const rawNum = String($root.find(this.el.number).val() || '');
1048
- const rawPin = String($root.find(this.el.pin).val() || '');
1049
-
1050
- const digitsNum = rawNum.replace(/\D/g, '');
1051
- const digitsPin = rawPin.replace(/\D/g, '');
1052
-
1053
- if (digitsNum || digitsPin) return;
1054
-
1055
- this.clearErrorsOnly($root);
1056
- },
1057
-
1058
745
  hideBanner($root) {
1059
746
  const { notification } = this.el;
1060
747
  $root.find(notification).remove();
@@ -1080,7 +767,7 @@ Wick.GiftCard = {
1080
767
  $list.children(`${chip}:not(${loaderChip})`).remove();
1081
768
 
1082
769
  const html = (giftCards || [])
1083
- .map((giftCard) => this.renderChipHTML(this.mapGiftToChipData($root, giftCard)))
770
+ .map((g) => this.renderChipHTML(this.mapGiftToChipData($root, g)))
1084
771
  .join('');
1085
772
 
1086
773
  if (html) {
@@ -1118,22 +805,9 @@ Wick.GiftCard = {
1118
805
 
1119
806
  showOnlyBillingAddress($root) {
1120
807
  const { checkoutContainer, billingAddress, altPaymentRowsAttr, hiddenCard } = this.el;
1121
-
1122
808
  const $container = $root.closest(checkoutContainer);
1123
- if (!$container.length) {
1124
- return;
1125
- }
1126
-
1127
- $container.find(billingAddress).removeClass(hiddenCard).show();
1128
-
809
+ $container.find(billingAddress).removeClass(hiddenCard);
1129
810
  $container.find(altPaymentRowsAttr).addClass(hiddenCard);
1130
-
1131
- if (this.isCardMethodSelected($container)) {
1132
- this.clearPaypageAndCollapse($container);
1133
- } else {
1134
- $container.find(this.el.cardDetails).addClass(hiddenCard);
1135
- }
1136
-
1137
811
  this.toggleAltPaymentInfos($root, false);
1138
812
  },
1139
813
 
@@ -1167,77 +841,12 @@ Wick.GiftCard = {
1167
841
  });
1168
842
  },
1169
843
 
1170
- collapseGiftcardPanel($container, opts = {}) {
1171
- const { hideIfHasChips = false } = opts;
1172
- const { panel, toggle, expandedAttr, checkoutContainer, block } = this.el;
1173
-
1174
- const $ctx = $container && $container.length ? $container : $(checkoutContainer).first();
1175
- const $giftcard = $ctx.find(block).first();
1176
- if (!$giftcard.length) return;
1177
-
1178
- $giftcard.find(panel).prop('hidden', true).hide();
1179
- $giftcard.find(toggle).attr(expandedAttr, 'false');
1180
-
1181
- this.updateHintVisibility($giftcard, { skipResetForm: true });
1182
-
1183
- if (hideIfHasChips) {
1184
- const hasChips = this.getAppliedChipsCount($giftcard) > 0;
1185
- if (hasChips) {
1186
- $giftcard.hide();
1187
- $giftcard.find(toggle).hide();
1188
- } else {
1189
- $giftcard.show();
1190
- $giftcard.find(toggle).show();
1191
- }
1192
- } else {
1193
- $giftcard.find(toggle).show();
1194
- }
1195
- },
1196
-
1197
- bindCtaCardCollapse() {
1198
- const sel = this.el.btnEnterDetails;
1199
-
1200
- $(document).off('click.giftcardCardCollapse', sel);
1201
-
1202
- $(document).on('click.giftcardCardCollapse', sel, (e) => {
1203
- const $btn = $(e.currentTarget);
1204
- const mode = $btn.attr('data-mode');
1205
- if (mode !== 'card') return;
1206
-
1207
- const $container = $btn.closest(this.el.checkoutContainer);
1208
-
1209
- console.log('[GC] CTA click', {
1210
- mode,
1211
- btnFound: $(e.currentTarget).length,
1212
- container: $btn.closest(this.el.checkoutContainer).length,
1213
- });
1214
-
1215
- if (!$container.length) return;
1216
-
1217
- e.preventDefault();
1218
-
1219
- this.collapseGiftcardPanel($container, { hideIfHasChips: true });
1220
-
1221
- this.openPaypage($container);
1222
- });
1223
- },
1224
-
1225
844
  bindEvents() {
1226
845
  const { number, pin, toggle, closeBtn, giftcardBtn, jsGiftcardAdd, giftcardChipClose } =
1227
846
  this.el;
1228
847
 
1229
848
  $(document).off('.giftcard');
1230
849
 
1231
- $(document).off('focusin.giftcard', this.collapseTargets);
1232
- $(document).on('focusin.giftcard', this.collapseTargets, (e) =>
1233
- this.handleCollapseTrigger(e)
1234
- );
1235
-
1236
- $(document).off('change.giftcard', '#chb-payment-details-card');
1237
- $(document).on('change.giftcard', '#chb-payment-details-card', (e) =>
1238
- this.handleCollapseTrigger(e)
1239
- );
1240
-
1241
850
  const handleNumberInput = createGcNumberInputHandler({
1242
851
  fieldSelector: this.el.field,
1243
852
  fieldErrorClass: this.el.fieldError,
@@ -1289,25 +898,10 @@ Wick.GiftCard = {
1289
898
  .on('click.giftcard', giftcardChipClose, this.handleChipCloseClick.bind(this));
1290
899
 
1291
900
  this.bindGiftcardCtaHandler();
1292
- this.bindCtaCardCollapse();
1293
- this.bindOrderNameValidation();
1294
- },
1295
-
1296
- bindOrderNameValidation() {
1297
- Object.keys(ORDER_NAME_RULES).forEach((key) => {
1298
- bindBlurValidation(
1299
- this.el[key],
1300
- (field) => validateFieldByRule($(field), ORDER_NAME_RULES[key]),
1301
- { namespace: '.giftcard' }
1302
- );
1303
- });
1304
901
  },
1305
902
 
1306
903
  init(payload = {}) {
1307
904
  const { field, pin, $blocks } = this.el;
1308
- if (!this.orderAddressLookup) {
1309
- this.orderAddressLookup = createPostcodeLookup(ORDER_ADDRESS_LOOKUP_CONTEXT);
1310
- }
1311
905
  this.bindEvents();
1312
906
  this.bindSplitPaymentFailedListener();
1313
907
  if ($blocks && $blocks.length) {
@@ -1324,10 +918,7 @@ Wick.GiftCard = {
1324
918
  }
1325
919
 
1326
920
  $blocks.each((index, block) => {
1327
- const $block = $(block);
1328
- this.clearErrorsIfEmptyOnInit($block);
1329
-
1330
- const $pinField = $block.find(pin).closest(field);
921
+ const $pinField = $(block).find(pin).closest(field);
1331
922
  if ($pinField.length) {
1332
923
  initializeInputToggle($pinField);
1333
924
  }