wickes-css2 2.113.0-ripple.7 → 2.113.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.
Files changed (265) hide show
  1. package/build/css/category-main.css +1 -1
  2. package/build/css/components/global-search.css +1 -1
  3. package/build/css/components/kitchen/strip-stickers.css +1 -0
  4. package/build/css/components/price-block-v2-critical.css +1 -1
  5. package/build/css/components/price-block-v2.css +1 -1
  6. package/build/css/components/store-locator-facilities.css +1 -1
  7. package/build/css/components/store-locator-lookup.css +1 -1
  8. package/build/css/components/strip-stickers.css +1 -0
  9. package/build/css/components/tile-calculator.css +1 -1
  10. package/build/css/homepage-main.css +1 -1
  11. package/build/css/kitchen-plp-main.css +1 -1
  12. package/build/css/main.css +1 -1
  13. package/build/css/my-account-main-v2.css +1 -1
  14. package/build/css/my-account-main.css +1 -1
  15. package/build/css/pages/checkout-new.css +1 -1
  16. package/build/css/pages/checkout.css +1 -1
  17. package/build/css/pages/my-account-v2.css +1 -1
  18. package/build/css/pages/my-account.css +1 -1
  19. package/build/css/pages/page_address-book.css +1 -1
  20. package/build/css/pages/page_checkout_delivery-new.css +1 -1
  21. package/build/css/pages/page_default-store.css +1 -1
  22. package/build/css/pages/page_discount.css +1 -1
  23. package/build/css/pages/page_fi.css +1 -1
  24. package/build/css/pages/page_in-store-checkout.css +1 -1
  25. package/build/css/pages/page_merged-basket.css +1 -1
  26. package/build/css/pages/page_my-order.css +1 -1
  27. package/build/css/pages/page_my-orders.css +1 -1
  28. package/build/css/pages/page_product-details-critical.css +1 -1
  29. package/build/css/pages/page_product-details-v2-critical.css +1 -1
  30. package/build/css/pages/page_product-details-v2.css +1 -1
  31. package/build/css/pages/page_product-details.css +1 -1
  32. package/build/css/pages/page_shopping-cart-v2.css +1 -1
  33. package/build/css/pages/page_store-locator-details.css +1 -1
  34. package/build/css/pages/page_store-locator.css +1 -1
  35. package/build/css/pages/page_ti.css +1 -1
  36. package/build/css/pages/tradePro-discount.css +1 -1
  37. package/build/css/pages/tradePro-rewards-old.css +1 -1
  38. package/build/css/pages/tradePro-rewards.css +1 -1
  39. package/build/css/pdp-main-before-combine.css +1 -1
  40. package/build/css/pdp-main-critical.css +1 -1
  41. package/build/css/pdp-main-non-critical.css +1 -1
  42. package/build/css/pdp-main.css +1 -1
  43. package/build/css/plp-main.css +1 -1
  44. package/build/css/shopping-list-pdf.css +1 -1
  45. package/build/css/store-locator-main.css +1 -1
  46. package/build/img/emulation/low-trees.png +0 -0
  47. package/build/img/emulation/overhead-power-cables.png +0 -0
  48. package/build/img/emulation/parked-vehicles.png +0 -0
  49. package/build/img/emulation/traffic-access-issues.png +0 -0
  50. package/build/img/emulation/walls-or-fences.png +0 -0
  51. package/build/js/account-members.min.js +1 -1
  52. package/build/js/add-project-list-id.min.js +1 -1
  53. package/build/js/address-book.min.js +1 -1
  54. package/build/js/basket.min.js +2 -2
  55. package/build/js/bloomreach-widget.min.js +1 -1
  56. package/build/js/bundle.min.js +1 -1
  57. package/build/js/change-password.min.js +1 -1
  58. package/build/js/checkout.min.js +2 -2
  59. package/build/js/emulation.min.js +408 -3318
  60. package/build/js/general.bundle.min.js +1 -1
  61. package/build/js/gift-cards.min.js +1 -1
  62. package/build/js/kitchen/kitchen-plp.min.js +1 -1
  63. package/build/js/merged-checkout.min.js +2 -2
  64. package/build/js/page/bloomreach-widget/bloomreach-recommendation-carousel-widget.js +318 -0
  65. package/build/js/page/bloomreach-widget/bloomreach-widget-core.js +370 -0
  66. package/build/js/page/bloomreach-widget/bloomreach-widget-tracking.js +16 -13
  67. package/build/js/page/bloomreach-widget/bloomreach-widget.js +8 -237
  68. package/build/js/page/bloomreach-widget/complete-your-project/cards.js +308 -0
  69. package/build/js/page/bloomreach-widget/complete-your-project/config.js +60 -0
  70. package/build/js/page/bloomreach-widget/complete-your-project/model.js +140 -0
  71. package/build/js/page/bloomreach-widget/complete-your-project/presenter.js +69 -0
  72. package/build/js/page/bloomreach-widget/complete-your-project/quantity.js +80 -0
  73. package/build/js/page/bloomreach-widget/complete-your-project/view.js +179 -0
  74. package/build/js/page/bloomreach-widget/complete-your-project/widget.js +185 -0
  75. package/build/js/page/bloomreach-widget/dont-forget-widget.js +15 -0
  76. package/build/js/page/bloomreach-widget/why-not-add-widget.js +10 -228
  77. package/build/js/page/plp-load-more.js +66 -81
  78. package/build/js/page/utils/validation.js +1 -1
  79. package/build/js/pdp.bundle.min.js +2 -2
  80. package/build/js/personal-details.min.js +1 -1
  81. package/build/js/plp.bundle.min.js +1 -1
  82. package/build/js/project-list.min.js +2 -2
  83. package/build/js/quiz.min.js +1 -1
  84. package/build/js/track-my-order.min.js +1 -1
  85. package/package.json +4 -6
  86. package/src/badges.html +18 -9
  87. package/src/components/base/button.hbs +7 -0
  88. package/src/components/bloomreach/complete-your-project-skeleton.hbs +21 -0
  89. package/src/components/bloomreach/complete-your-project.hbs +6 -21
  90. package/src/components/bloomreach/why-not-add-card-skeleton.hbs +2 -2
  91. package/src/components/bloomreach/why-not-add-card.hbs +79 -60
  92. package/src/components/bloomreach/why-not-add-content.hbs +3 -3
  93. package/src/components/bloomreach/why-not-add.hbs +1 -1
  94. package/src/components/date-selection.hbs +19 -10
  95. package/src/components/fulfilment-accordions.hbs +1 -1
  96. package/src/components/heavy-banners-wrapper.hbs +21 -0
  97. package/src/components/kitchen/price.hbs +29 -49
  98. package/src/components/kitchen/strip-stickers.hbs +3 -9
  99. package/src/components/pdp-price-actions.hbs +0 -17
  100. package/src/components/price-badges.hbs +10 -12
  101. package/src/components/price-block-v2.hbs +203 -273
  102. package/src/components/product-main-info-v2.hbs +0 -2
  103. package/src/data/data_heavy-banner.json +29 -0
  104. package/src/data/my-account/data_my-account.json +1 -1
  105. package/src/data/my-account/data_my-order.json +1 -1
  106. package/src/data/my-account/data_my-orders.json +1 -1
  107. package/src/img/emulation/low-trees.png +0 -0
  108. package/src/img/emulation/overhead-power-cables.png +0 -0
  109. package/src/img/emulation/parked-vehicles.png +0 -0
  110. package/src/img/emulation/traffic-access-issues.png +0 -0
  111. package/src/img/emulation/walls-or-fences.png +0 -0
  112. package/src/js/components/banner-placement-manager.js +10 -33
  113. package/src/js/components/general/cart-slider.js +41 -4
  114. package/src/js/emulation/banner-placement-manager.js +188 -219
  115. package/src/js/emulation/complete-your-project-loading.js +16 -0
  116. package/src/js/emulation/custom-slider-emulation.js +21 -8
  117. package/src/js/emulation/date-selection.js +2 -2
  118. package/src/js/emulation/dont-forget-loading.js +36 -0
  119. package/src/js/emulation/just-added-scenarios-emulation.js +131 -0
  120. package/src/js/emulation/mini-basket.js +34 -34
  121. package/src/js/emulation/mock.js +429 -4
  122. package/src/js/emulation/plp-load-more.js +4 -13
  123. package/src/js/emulation/why-not-add-loading.js +14 -3
  124. package/src/js/emulation/why-not-add.js +12 -14
  125. package/src/js/page/bloomreach-widget/bloomreach-recommendation-carousel-widget.js +318 -0
  126. package/src/js/page/bloomreach-widget/bloomreach-widget-core.js +370 -0
  127. package/src/js/page/bloomreach-widget/bloomreach-widget-tracking.js +16 -13
  128. package/src/js/page/bloomreach-widget/bloomreach-widget.js +8 -237
  129. package/src/js/page/bloomreach-widget/complete-your-project/cards.js +308 -0
  130. package/src/js/page/bloomreach-widget/complete-your-project/config.js +60 -0
  131. package/src/js/page/bloomreach-widget/complete-your-project/model.js +140 -0
  132. package/src/js/page/bloomreach-widget/complete-your-project/presenter.js +69 -0
  133. package/src/js/page/bloomreach-widget/complete-your-project/quantity.js +80 -0
  134. package/src/js/page/bloomreach-widget/complete-your-project/view.js +179 -0
  135. package/src/js/page/bloomreach-widget/complete-your-project/widget.js +185 -0
  136. package/src/js/page/bloomreach-widget/dont-forget-widget.js +15 -0
  137. package/src/js/page/bloomreach-widget/why-not-add-widget.js +10 -228
  138. package/src/js/page/plp-load-more.js +66 -81
  139. package/src/js/page/utils/validation.js +1 -1
  140. package/src/page_checkout_big-bulky-delivery-details.html +272 -0
  141. package/src/page_checkout_premium-delivery-details.html +2 -2
  142. package/src/page_product-details-banner.html +3 -1
  143. package/src/page_product-details-big-wins-disabled-delivery.html +3 -1
  144. package/src/page_product-details-big-wins-non-registered.html +3 -1
  145. package/src/page_product-details-big-wins-out-nearest.html +3 -1
  146. package/src/page_product-details-big-wins-unhappy.html +3 -1
  147. package/src/page_product-details-big-wins.html +3 -1
  148. package/src/page_product-details-billie.html +3 -1
  149. package/src/page_product-details-calculator.html +3 -1
  150. package/src/page_product-details-cashback-v2.html +3 -1
  151. package/src/page_product-details-clearpay.html +3 -1
  152. package/src/page_product-details-cnc-error-notification.html +3 -1
  153. package/src/page_product-details-cnc-success-notification-vat.html +4 -1
  154. package/src/page_product-details-cnc-success-notification.html +3 -1
  155. package/src/page_product-details-default-store.html +3 -1
  156. package/src/page_product-details-energy-efficiency.html +3 -1
  157. package/src/page_product-details-flooring-with-pr-placeholder.html +3 -1
  158. package/src/page_product-details-flooring.html +3 -1
  159. package/src/page_product-details-gallery-actual.html +3 -1
  160. package/src/page_product-details-mfe-calculator.html +3 -1
  161. package/src/page_product-details-mtm-doors.html +3 -1
  162. package/src/page_product-details-only-clearpay.html +3 -1
  163. package/src/page_product-details-paint-mixing.html +3 -1
  164. package/src/page_product-details-saved-pl.html +3 -1
  165. package/src/page_product-details-tile-steps-klarna-widget-with-method-ids.html +3 -1
  166. package/src/page_product-details-tile-steps-logout.html +3 -1
  167. package/src/page_product-details-tile-steps-no-new-project-list.html +3 -1
  168. package/src/page_product-details-tile-steps-with-klarna.html +3 -1
  169. package/src/page_product-details-tile-steps.html +3 -1
  170. package/src/page_product-details-v2.html +3 -1
  171. package/src/page_product-details-vat.html +3 -1
  172. package/src/page_product-details-wisdom-mcfc-registered.html +3 -1
  173. package/src/page_product-details-wisdom-mcfc.html +3 -1
  174. package/src/page_product-details-wisdom-oos-registered.html +3 -1
  175. package/src/page_product-details-wisdom-oos.html +3 -1
  176. package/src/page_product-details-wisdom-registered.html +3 -1
  177. package/src/page_product-details-wisdom.html +3 -1
  178. package/src/page_product-details-with-favourite.html +3 -1
  179. package/src/page_product-details-with-global-search-v2.html +7 -7
  180. package/src/page_product-details-with-why-not-add-single.html +1 -1
  181. package/src/page_product-details_no-previous-default.html +3 -1
  182. package/src/scss/components/_cards-slider.scss +3 -1
  183. package/src/scss/components/_checkout_order.scss +2 -1
  184. package/src/scss/components/_date-selection-add-new-styles.scss +0 -29
  185. package/src/scss/components/_heavy-banners.scss +216 -0
  186. package/src/scss/components/_kitchen-card.scss +0 -1
  187. package/src/scss/components/_price-badges-critical.scss +0 -10
  188. package/src/scss/components/_price-badges.scss +0 -10
  189. package/src/scss/components/_price-block-critical.scss +0 -1
  190. package/src/scss/components/_price-block.scss +0 -1
  191. package/src/scss/components/_sticky-element-appearance.scss +6 -2
  192. package/src/scss/components/bloomreach/_bloomreach.scss +1 -0
  193. package/src/scss/components/bloomreach/_card-shared.scss +24 -0
  194. package/src/scss/components/bloomreach/_complete-card.scss +1 -9
  195. package/src/scss/components/bloomreach/_reviews.scss +0 -2
  196. package/src/scss/components/bloomreach/_why-not-add-card.scss +137 -10
  197. package/src/scss/components/bloomreach/_why-not-add.scss +31 -2
  198. package/src/scss/components/energy-efficiency.scss +2 -2
  199. package/src/scss/components/global-search.scss +6 -2
  200. package/src/scss/components/kitchen/_price.scss +0 -10
  201. package/src/scss/components/kitchen/strip-stickers.scss +18 -0
  202. package/src/scss/components/my-account/_active-orders.scss +9 -9
  203. package/src/scss/components/price-block-v2-critical.scss +0 -54
  204. package/src/scss/components/price-block-v2.scss +0 -54
  205. package/src/scss/components/strip-stickers.scss +18 -0
  206. package/src/scss/helpers/helpers-pdp-critical/_helpers-critical-pdp.scss +13 -8
  207. package/src/scss/libs/_bootstrap-extracted.scss +5 -0
  208. package/src/scss/main.scss +1 -0
  209. package/src/scss/pages/iframe-paypage.scss +9 -11
  210. package/src/scss/pages/page_checkout_delivery-new.scss +4 -0
  211. package/src/scss/pages/page_cms_homepage.scss +10 -4
  212. package/src/scss/pages/page_installation.scss +2 -2
  213. package/src/scss/pages/page_online-exclusive.scss +7 -3
  214. package/src/scss/pages/page_product-details-v2-critical.scss +109 -216
  215. package/src/scss/pages/page_product-details-v2.scss +107 -168
  216. package/src/scss/pages/page_product-details.scss +0 -11
  217. package/src/scss/pages/page_top-rated.scss +38 -23
  218. package/src/scss/pdp-main-critical.scss +0 -1
  219. package/src/scss/pdp-main.scss +0 -6
  220. package/src/scss/plp-main.scss +0 -5
  221. package/src/sitemap.html +2 -13
  222. package/build/js/package-bulk-add.min.js +0 -1
  223. package/build/js/page/bloomreach-widget/complete-your-project-widget.js +0 -1100
  224. package/build/js/page/ripple/bulk-add.js +0 -71
  225. package/build/js/page/ripple/package-bulk-add.js +0 -43
  226. package/build/js/page/ripple/postcode-checker.js +0 -83
  227. package/build/js/page/ripple/thumb-gallery.js +0 -168
  228. package/build/js/postcode-checker.min.js +0 -1
  229. package/src/badges-ripple.html +0 -120
  230. package/src/components/image-accordion.hbs +0 -18
  231. package/src/components/package-card.hbs +0 -30
  232. package/src/components/postcode-checker.hbs +0 -24
  233. package/src/components/suite-includes.hbs +0 -66
  234. package/src/components/suite-product-card.hbs +0 -47
  235. package/src/components/thumb-gallery.hbs +0 -23
  236. package/src/data/data_badges.json +0 -143
  237. package/src/data/data_bathroom-plp.json +0 -814
  238. package/src/data/data_suite-includes-products.json +0 -134
  239. package/src/js/components/general/image-accordion.js +0 -54
  240. package/src/js/components/package-card.js +0 -69
  241. package/src/js/components/store-locator-cards.js +0 -76
  242. package/src/js/emulation/postcode-checker.js +0 -11
  243. package/src/js/page/bloomreach-widget/complete-your-project-widget.js +0 -1100
  244. package/src/js/page/ripple/bulk-add.js +0 -71
  245. package/src/js/page/ripple/package-bulk-add.js +0 -43
  246. package/src/js/page/ripple/postcode-checker.js +0 -83
  247. package/src/js/page/ripple/thumb-gallery.js +0 -168
  248. package/src/page_bathroom-plp-vat.html +0 -81
  249. package/src/page_bathroom-plp-without-load-more.html +0 -83
  250. package/src/page_bathroom-plp.html +0 -98
  251. package/src/page_product-details-ripple-gallery.html +0 -121
  252. package/src/page_product-details-suite-includes-banners.html +0 -139
  253. package/src/page_product-details-suite-includes-billie.html +0 -128
  254. package/src/page_product-details-suite-includes-klarna.html +0 -120
  255. package/src/page_product-details-suite-includes-vat.html +0 -126
  256. package/src/page_product-details-suite-includes.html +0 -122
  257. package/src/scss/components/_image-accordion.scss +0 -54
  258. package/src/scss/components/_package-card.scss +0 -63
  259. package/src/scss/components/_package-plp.scss +0 -88
  260. package/src/scss/components/_postcode-checker.scss +0 -115
  261. package/src/scss/components/_suite-includes.scss +0 -141
  262. package/src/scss/components/_suite-product-card.scss +0 -98
  263. package/src/scss/components/_thumb-gallery-critical.scss +0 -34
  264. package/src/scss/components/_thumb-gallery.scss +0 -192
  265. package/src/scss/components/kitchen/_strip-stickers.scss +0 -46
@@ -0,0 +1,318 @@
1
+ import { createLoadingButton } from '../utils/create-loading-button';
2
+ import { createBloomreachWidget } from './bloomreach-widget-core';
3
+
4
+ const Handlebars = require('hbsfy/runtime');
5
+
6
+ Handlebars.registerPartial('loader', require('../../../elements/loader.hbs'));
7
+ Handlebars.registerPartial('button', require('../../../components/base/button.hbs'));
8
+ Handlebars.registerPartial(
9
+ 'bloomreach/why-not-add-card',
10
+ require('../../../components/bloomreach/why-not-add-card.hbs')
11
+ );
12
+ Handlebars.registerPartial('reviews-rating', require('../../../components/reviews-rating.hbs'));
13
+
14
+ const recommendationCarouselTemplate = require('../../../components/bloomreach/why-not-add-content.hbs');
15
+
16
+ const DEFAULT_EL = {
17
+ addToCartError: '[data-add-to-cart-error]',
18
+ card: '.why-not-add-card',
19
+ cardWrapper: '.why-not-add-card-wrapper',
20
+ cta: '.why-not-add-card__cta',
21
+ next: '[data-why-not-add-next]',
22
+ pagination: '[data-why-not-add-pagination]',
23
+ productLink: '.why-not-add-card__title',
24
+ prev: '[data-why-not-add-prev]',
25
+ root: '[data-why-not-add]',
26
+ slider: '[data-why-not-add-slider]',
27
+ productCodeAttribute: 'data-product-code',
28
+ };
29
+
30
+ export function createBloomreachRecommendationCarouselWidget(config) {
31
+ const state = {
32
+ sliders: [],
33
+ loadingButton: null,
34
+ };
35
+ const el = {
36
+ ...DEFAULT_EL,
37
+ widgetContainer: config.widgetContainer,
38
+ };
39
+ const addToCartEvent = config.addToCartEvent || 'addToCart';
40
+ let widget = null;
41
+
42
+ function getRenderedRoots($container) {
43
+ let $roots = $container.find(el.root);
44
+
45
+ if (config.modifier) {
46
+ $roots = $roots.filter(`.${config.modifier}`);
47
+ }
48
+
49
+ return $roots;
50
+ }
51
+
52
+ function removeRenderedWidget($container) {
53
+ getRenderedRoots($container).remove();
54
+ }
55
+
56
+ function normalizeProducts(payloadData) {
57
+ return Wick.BloomreachWidget.normalizePayload(payloadData)
58
+ .map(function (item) {
59
+ return item.baseProduct || item;
60
+ })
61
+ .filter(function (product) {
62
+ return config.isEligibleProduct ? config.isEligibleProduct(product) : true;
63
+ })
64
+ .slice(0, 5);
65
+ }
66
+
67
+ function renderWidget($container, payloadData) {
68
+ const products = normalizeProducts(payloadData);
69
+
70
+ if (!products.length) {
71
+ if (config.appendToContainer) {
72
+ removeRenderedWidget($container);
73
+ } else {
74
+ $container.empty().hide();
75
+ }
76
+
77
+ return;
78
+ }
79
+
80
+ const html = recommendationCarouselTemplate({
81
+ title: config.title,
82
+ modifier: config.modifier,
83
+ products: products.map(function (product) {
84
+ return {
85
+ ...Wick.BloomreachWidget.getProductRenderData(product),
86
+ addToCartError: config.addToCartError,
87
+ showBadge: !config.hideBadge,
88
+ };
89
+ }),
90
+ isSingleProduct: products.length === 1,
91
+ });
92
+
93
+ if (config.appendToContainer) {
94
+ removeRenderedWidget($container);
95
+ $container.append(html);
96
+ return;
97
+ }
98
+
99
+ $container.html(html).show();
100
+ }
101
+
102
+ function destroySliders() {
103
+ state.sliders.forEach(function (slider) {
104
+ if (slider && slider.destroy) {
105
+ slider.destroy(true, true);
106
+ }
107
+ });
108
+
109
+ state.sliders = [];
110
+ }
111
+
112
+ function initSliders($root) {
113
+ destroySliders();
114
+
115
+ $root.find(el.slider).each(function () {
116
+ const sliderEl = this;
117
+ const $slider = $(sliderEl);
118
+ const $widget = $slider.closest(el.root);
119
+ const slidesCount = $slider.find('.swiper-slide').length;
120
+
121
+ if (slidesCount <= 1) {
122
+ return;
123
+ }
124
+
125
+ const slider = new Swiper(sliderEl, {
126
+ roundLengths: true,
127
+ slidesPerView: 1,
128
+ spaceBetween: 12,
129
+ watchOverflow: true,
130
+ navigation: {
131
+ nextEl: $widget.find(el.next)[0],
132
+ prevEl: $widget.find(el.prev)[0],
133
+ disabledClass: 'why-not-add__arrow--disabled',
134
+ },
135
+ pagination: {
136
+ el: $widget.find(el.pagination)[0],
137
+ clickable: true,
138
+ renderBullet(index, className) {
139
+ return `<button class="${className}" type="button" aria-label="Go to slide ${
140
+ index + 1
141
+ }"></button>`;
142
+ },
143
+ bulletClass: 'why-not-add__pagination-item',
144
+ bulletActiveClass: 'why-not-add__pagination-item--active',
145
+ },
146
+ });
147
+
148
+ state.sliders.push(slider);
149
+ });
150
+ }
151
+
152
+ function setCardAdded($card) {
153
+ const $button = $card.find(el.cta);
154
+
155
+ $card.removeClass('why-not-add-card--failed').addClass('why-not-add-card--added');
156
+ $card.find('.why-not-add-card__error').addClass('d-none');
157
+
158
+ $button.prop('disabled', true).attr('aria-label', 'Added to basket');
159
+ $button.find('.loading-button__text').addClass('d-none');
160
+ $button.find('.button__icon--success').removeClass('d-none');
161
+ }
162
+
163
+ function setCardFailed($card, messageText) {
164
+ const $button = $card.find(el.cta);
165
+ const errorText = messageText || config.addToCartError;
166
+
167
+ $card.removeClass('why-not-add-card--added').addClass('why-not-add-card--failed');
168
+
169
+ $button
170
+ .prop('disabled', true)
171
+ .attr('aria-label', errorText || 'Product has not been added to basket');
172
+
173
+ if (errorText) {
174
+ $card.find(el.addToCartError).text(errorText);
175
+ }
176
+
177
+ $card.find('.why-not-add-card__error').removeClass('d-none');
178
+ }
179
+
180
+ function handleAddToCartResponse($card, response) {
181
+ const messageType = response && response.messageType;
182
+ const isSuccess = !messageType || messageType === 'success';
183
+
184
+ if (isSuccess) {
185
+ if (config.disableAfterSuccess) {
186
+ setCardAdded($card);
187
+ }
188
+
189
+ return;
190
+ }
191
+
192
+ if (config.disableAfterFailure) {
193
+ setCardFailed($card, response && response.messageText);
194
+ }
195
+ }
196
+
197
+ function getAddToCartPayload(productCode) {
198
+ const payload = { productCode };
199
+
200
+ if (config.doNotShowAddedProductPopup) {
201
+ payload.doNotShowAddedProductPopup = true;
202
+ }
203
+
204
+ return payload;
205
+ }
206
+
207
+ function bindProductTracking($root) {
208
+ $root.off(`click.${config.namespace}Tracking`, el.productLink);
209
+ $root.on(`click.${config.namespace}Tracking`, el.productLink, function (event) {
210
+ const productCode = $(event.currentTarget)
211
+ .closest(el.card)
212
+ .attr(el.productCodeAttribute);
213
+
214
+ widget.tracking.trackClick(productCode);
215
+ });
216
+ }
217
+
218
+ function bindAddToCart($root) {
219
+ $root.off(`click.${config.namespace}`, el.cta);
220
+ $root.on(`click.${config.namespace}`, el.cta, function (event) {
221
+ event.preventDefault();
222
+
223
+ const $button = $(event.currentTarget);
224
+ const $card = $button.closest(el.cardWrapper);
225
+ const productCode = $card.find(el.card).attr(el.productCodeAttribute);
226
+
227
+ if (
228
+ !productCode ||
229
+ $button.prop('disabled') ||
230
+ state.loadingButton.isLoading($button)
231
+ ) {
232
+ return;
233
+ }
234
+
235
+ widget.tracking.trackAddToCart([
236
+ {
237
+ item_id: productCode,
238
+ sku: productCode,
239
+ },
240
+ ]);
241
+
242
+ state.loadingButton.start($button);
243
+
244
+ Wick.BloomreachWidget.dispatchWidgetEvent(
245
+ addToCartEvent,
246
+ getAddToCartPayload(productCode)
247
+ )
248
+ .then(function (response) {
249
+ state.loadingButton.stop($button);
250
+
251
+ if (config.doNotShowAddedProductPopup) {
252
+ handleAddToCartResponse($card, response);
253
+ return;
254
+ }
255
+
256
+ if (Wick.MiniBasketSliderFE) {
257
+ Wick.MiniBasketSliderFE.isMiniBasketLoaded = false;
258
+ }
259
+ })
260
+ .catch(function (error) {
261
+ state.loadingButton.stop($button);
262
+
263
+ if (config.disableAfterFailure) {
264
+ setCardFailed($card, error && (error.messageText || error.message));
265
+ }
266
+ });
267
+ });
268
+ }
269
+
270
+ function bindVatToggle() {
271
+ if (Wick.BloomreachWidget.bindVatToggle) {
272
+ Wick.BloomreachWidget.bindVatToggle(`${config.namespace}VatToggle`);
273
+ }
274
+ }
275
+
276
+ function initRenderedWidget($container) {
277
+ const $root = getRenderedRoots($container).last();
278
+
279
+ if (!$root.length) {
280
+ return;
281
+ }
282
+
283
+ if (!state.loadingButton) {
284
+ state.loadingButton = createLoadingButton({
285
+ text: Wick.BloomreachWidget.el.loadingButtonText,
286
+ loader: Wick.BloomreachWidget.el.loadingButtonLoader,
287
+ });
288
+ }
289
+
290
+ Wick.BloomreachWidget.drawRating($root);
291
+ initSliders($root);
292
+ bindProductTracking($root);
293
+ bindAddToCart($root);
294
+ bindVatToggle();
295
+ Wick.BloomreachWidget.reapplyVatDisplay();
296
+ }
297
+
298
+ widget = createBloomreachWidget({
299
+ el,
300
+ hide($containers) {
301
+ if (config.appendToContainer) {
302
+ $containers.each(function () {
303
+ removeRenderedWidget($(this));
304
+ });
305
+ return;
306
+ }
307
+
308
+ $containers.empty().hide();
309
+ },
310
+ renderWidget,
311
+ initRenderedWidget,
312
+ getViewTargets($containers) {
313
+ return [$containers.find(el.productLink).get(0), $containers.find(el.cta).get(0)];
314
+ },
315
+ });
316
+
317
+ return widget;
318
+ }
@@ -0,0 +1,370 @@
1
+ import { isApp } from '../utils/helpers';
2
+ import { createBloomreachWidgetTracking } from './bloomreach-widget-tracking';
3
+
4
+ var Wick = window.Wick || {};
5
+
6
+ import { createEvent } from '../utils/create-event';
7
+
8
+ export function createBloomreachWidget(config) {
9
+ const tracking = config.tracking || createBloomreachWidgetTracking();
10
+
11
+ const widget = {
12
+ el: config.el || {},
13
+ tracking,
14
+
15
+ getContainers(options = {}) {
16
+ if (options.container) {
17
+ return $(options.container);
18
+ }
19
+
20
+ return $(widget.el.widgetContainer);
21
+ },
22
+
23
+ hide(options = {}) {
24
+ const $containers = widget.getContainers(options);
25
+
26
+ if (config.hide) {
27
+ config.hide($containers, options, widget);
28
+ return;
29
+ }
30
+
31
+ $containers.empty().hide();
32
+ },
33
+
34
+ init(payloadData, options = {}) {
35
+ const $containers = widget.getContainers(options);
36
+
37
+ if (!$containers.length) {
38
+ return;
39
+ }
40
+
41
+ if (!payloadData || !Wick.BloomreachWidget.hasRecommendations(payloadData)) {
42
+ widget.hide(options);
43
+ return;
44
+ }
45
+
46
+ tracking.setPayload(payloadData);
47
+
48
+ if (config.setPayload) {
49
+ config.setPayload(payloadData, widget);
50
+ }
51
+
52
+ $containers.each(function () {
53
+ const $container = $(this);
54
+
55
+ if (config.renderWidget) {
56
+ config.renderWidget($container, payloadData, widget);
57
+ }
58
+
59
+ if (config.initRenderedWidget) {
60
+ config.initRenderedWidget($container, widget);
61
+ }
62
+ });
63
+
64
+ if (config.getViewTargets) {
65
+ tracking.observeView(config.getViewTargets($containers, widget));
66
+ }
67
+ },
68
+ };
69
+
70
+ return widget;
71
+ }
72
+
73
+ Wick.BloomreachWidget = {
74
+ widgets: {},
75
+
76
+ el: {
77
+ loadingButtonText: '.loading-button__text',
78
+ loadingButtonLoader: '.loading-button__loader',
79
+ ratingOverlay: '.rating-overlay',
80
+ starOverlay: '.star-overlay',
81
+ vatInc: '.including-vat-inherit',
82
+ vatExc: '.excluding-vat-inherit',
83
+ },
84
+
85
+ badgeColorMap: {
86
+ blue: '#019ee3',
87
+ gray: '#3e3e3e',
88
+ green: '#9acd32',
89
+ red: '#cf000f',
90
+ yellow: '#f7ca18',
91
+ },
92
+
93
+ getBadgeColor(color) {
94
+ if (!color) {
95
+ return '';
96
+ }
97
+
98
+ return Wick.BloomreachWidget.badgeColorMap[color] || color;
99
+ },
100
+
101
+ getBadge(product) {
102
+ if (!product) {
103
+ return null;
104
+ }
105
+
106
+ const promotion = product.potentialPromotions && product.potentialPromotions[0];
107
+ const promotionAttributes = promotion && promotion.customAttributes;
108
+
109
+ if (promotionAttributes && promotionAttributes.overlayText) {
110
+ return {
111
+ text: promotionAttributes.overlayText,
112
+ textColor: Wick.BloomreachWidget.getBadgeColor(
113
+ promotionAttributes.overlayTextColor
114
+ ),
115
+ color: Wick.BloomreachWidget.getBadgeColor(
116
+ promotionAttributes.overlayBackgroundColor
117
+ ),
118
+ };
119
+ }
120
+
121
+ if (product.badge && product.badge.text) {
122
+ return {
123
+ ...product.badge,
124
+ textColor: Wick.BloomreachWidget.getBadgeColor(product.badge.textColor),
125
+ color: Wick.BloomreachWidget.getBadgeColor(product.badge.color),
126
+ };
127
+ }
128
+
129
+ return product.badge || null;
130
+ },
131
+
132
+ registerWidgets(widgetList) {
133
+ widgetList.forEach(function ({ type, widget }) {
134
+ Wick.BloomreachWidget.widgets[type] = widget;
135
+ });
136
+ },
137
+
138
+ getWidget(type) {
139
+ return Wick.BloomreachWidget.widgets[type];
140
+ },
141
+
142
+ init(type, payloadData, options = {}) {
143
+ const widget = Wick.BloomreachWidget.getWidget(type);
144
+
145
+ if (!widget || typeof widget.init !== 'function') {
146
+ return;
147
+ }
148
+
149
+ widget.init(payloadData, options, Wick.BloomreachWidget);
150
+ },
151
+
152
+ normalizePayload(payloadData) {
153
+ if (Array.isArray(payloadData)) {
154
+ return payloadData;
155
+ }
156
+
157
+ if (payloadData && Array.isArray(payloadData.recommendedProducts)) {
158
+ return payloadData.recommendedProducts;
159
+ }
160
+
161
+ return [];
162
+ },
163
+
164
+ hasRecommendations(payloadData) {
165
+ return Wick.BloomreachWidget.normalizePayload(payloadData).length > 0;
166
+ },
167
+
168
+ removeBlankTargets($root) {
169
+ if (!isApp()) {
170
+ return;
171
+ }
172
+
173
+ $root.find('a[target="_blank"]').removeAttr('target');
174
+ },
175
+
176
+ getDisplayPrice(product) {
177
+ return product.displayPrice || product.price || {};
178
+ },
179
+
180
+ getDisplayPriceExcVat(product) {
181
+ return product.displayPriceExclusiveVat || product.priceExclusiveVat || null;
182
+ },
183
+
184
+ getExcVatFormattedValue(product, displayPrice) {
185
+ const excVat = Wick.BloomreachWidget.getDisplayPriceExcVat(product);
186
+
187
+ if (excVat && excVat.formattedValue) {
188
+ return excVat.formattedValue;
189
+ }
190
+
191
+ if (!displayPrice || typeof displayPrice.value !== 'number') {
192
+ return displayPrice ? displayPrice.formattedValue || '' : '';
193
+ }
194
+
195
+ const vatRate = displayPrice.vatRatePercentage || 20;
196
+
197
+ return Wick.BloomreachWidget.formatPrice(displayPrice.value / (1 + vatRate / 100));
198
+ },
199
+
200
+ getPriceValue(price) {
201
+ return price && typeof price.value === 'number' ? price.value : 0;
202
+ },
203
+
204
+ getPriceFormattedValue(price) {
205
+ if (!price) {
206
+ return '';
207
+ }
208
+
209
+ if (price.formattedValue) {
210
+ return price.formattedValue;
211
+ }
212
+
213
+ if (typeof price.value === 'number') {
214
+ return Wick.BloomreachWidget.formatPrice(price.value);
215
+ }
216
+
217
+ return '';
218
+ },
219
+
220
+ getWasPrice(product) {
221
+ const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
222
+
223
+ return displayPrice && displayPrice.wasPrice ? displayPrice.wasPrice : null;
224
+ },
225
+
226
+ getWasPriceFormatted(product) {
227
+ const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
228
+ const wasPrice = Wick.BloomreachWidget.getWasPrice(product);
229
+
230
+ if (wasPrice && wasPrice.formattedValue) {
231
+ return wasPrice.formattedValue;
232
+ }
233
+
234
+ if (typeof wasPrice === 'number') {
235
+ return Wick.BloomreachWidget.formatPrice(wasPrice);
236
+ }
237
+
238
+ if (wasPrice) {
239
+ return `${displayPrice.currencySymbol || '£'}${wasPrice}`;
240
+ }
241
+
242
+ return '';
243
+ },
244
+
245
+ getExcVatWasPrice(product) {
246
+ const priceExclusiveVat = product.priceExclusiveVat || null;
247
+ const displayPriceExclusiveVat = product.displayPriceExclusiveVat || null;
248
+ const wasPrice =
249
+ (displayPriceExclusiveVat && displayPriceExclusiveVat.wasPrice) ||
250
+ (priceExclusiveVat && priceExclusiveVat.wasPrice);
251
+
252
+ if (wasPrice && wasPrice.formattedValue) {
253
+ return wasPrice.formattedValue;
254
+ }
255
+
256
+ if (typeof wasPrice === 'number') {
257
+ return Wick.BloomreachWidget.formatPrice(wasPrice);
258
+ }
259
+
260
+ return wasPrice || '';
261
+ },
262
+
263
+ getProductImage(product, fallbackProduct) {
264
+ const productImages = product.images || [];
265
+ const fallbackImages = fallbackProduct ? fallbackProduct.images || [] : [];
266
+ const images = productImages.length ? productImages : fallbackImages;
267
+
268
+ return (
269
+ images.find(function (item) {
270
+ return item.format === 'product';
271
+ }) ||
272
+ images.find(function (item) {
273
+ return item.imageType === 'PRIMARY';
274
+ }) ||
275
+ images[0] ||
276
+ {}
277
+ );
278
+ },
279
+
280
+ getProductRenderData(product, options = {}) {
281
+ const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
282
+ const displayPriceExcVat = Wick.BloomreachWidget.getDisplayPriceExcVat(product);
283
+ const wasPriceFormatted = Wick.BloomreachWidget.getWasPriceFormatted(product);
284
+ const isSwitchVat = !!(window.ACC && window.ACC.app && window.ACC.app.isVatToggleAvailable);
285
+ const excVatFormattedValue = options.fallbackExcVat
286
+ ? Wick.BloomreachWidget.getExcVatFormattedValue(product, displayPrice)
287
+ : Wick.BloomreachWidget.getPriceFormattedValue(displayPriceExcVat);
288
+
289
+ return {
290
+ ...product,
291
+ badge: Wick.BloomreachWidget.getBadge(product),
292
+ price: displayPrice,
293
+ image:
294
+ options.image ||
295
+ Wick.BloomreachWidget.getProductImage(product, options.fallbackProduct),
296
+ wasPriceFormatted,
297
+ 'switch-vat': isSwitchVat,
298
+ incVatFormattedValue: Wick.BloomreachWidget.getPriceFormattedValue(displayPrice),
299
+ incVatValue: Wick.BloomreachWidget.getPriceValue(displayPrice),
300
+ excVatFormattedValue,
301
+ excVatValue: Wick.BloomreachWidget.getPriceValue(displayPriceExcVat),
302
+ incVatWasPriceFormatted: wasPriceFormatted,
303
+ excVatWasPriceFormatted: Wick.BloomreachWidget.getExcVatWasPrice(product),
304
+ };
305
+ },
306
+
307
+ drawRating($root) {
308
+ const { ratingOverlay, starOverlay } = Wick.BloomreachWidget.el;
309
+
310
+ $root.find(ratingOverlay).each(function () {
311
+ let rating = parseFloat($(this).attr('data-rating')) || 0;
312
+ const $stars = $(this).children(starOverlay);
313
+
314
+ $stars.each(function () {
315
+ const $star = $(this);
316
+
317
+ if (rating >= 1) {
318
+ rating--;
319
+ } else if (rating > 0) {
320
+ const width = Math.asin(2 * rating - 1) / Math.PI + 0.5;
321
+ $star.css('width', width + 'rem');
322
+ rating = 0;
323
+ } else {
324
+ $star.css('width', '0rem');
325
+ }
326
+ });
327
+ });
328
+ },
329
+
330
+ dispatchWidgetEvent(eventName, payload) {
331
+ return new Promise(function (resolve, reject) {
332
+ const eventDetail = { resolve, reject };
333
+ const event = createEvent(eventName, payload, eventDetail);
334
+
335
+ window.dispatchEvent(event);
336
+ });
337
+ },
338
+
339
+ reapplyVatDisplay() {
340
+ if (!Wick.VatToggle || typeof Wick.VatToggle.isActive !== 'function') {
341
+ return;
342
+ }
343
+
344
+ const { vatInc, vatExc } = Wick.BloomreachWidget.el;
345
+ const hiddenClassName = Wick.VatToggle.HIDDEN_CLASS_NAME || 'd-none';
346
+ const isExcVatActive = Wick.VatToggle.isActive();
347
+
348
+ $(vatInc).toggleClass(hiddenClassName, isExcVatActive);
349
+ $(vatExc).toggleClass(hiddenClassName, !isExcVatActive);
350
+ },
351
+
352
+ bindVatToggle(namespace) {
353
+ if (!Wick.VatToggle || !Wick.VatToggle.TOGGLE_VAT_EVENT_NAME) {
354
+ return;
355
+ }
356
+
357
+ const eventName = `${Wick.VatToggle.TOGGLE_VAT_EVENT_NAME}.${namespace}`;
358
+
359
+ $(window).off(eventName).on(eventName, Wick.BloomreachWidget.reapplyVatDisplay);
360
+ },
361
+
362
+ formatPrice(value) {
363
+ return new Intl.NumberFormat('en-GB', {
364
+ style: 'currency',
365
+ currency: 'GBP',
366
+ minimumFractionDigits: 2,
367
+ maximumFractionDigits: 2,
368
+ }).format(value);
369
+ },
370
+ };