wickes-css2 2.94.0-order-summary.2 → 2.94.0-order-summary.4

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.
@@ -29,6 +29,7 @@ import {
29
29
  } from './basket/session-sync'
30
30
  import {displayEnergyEfficiency} from "./basket/display-energy-efficiency";
31
31
  import {appendLoader, hideLoader, showLoader} from "./utils/loader";
32
+ import { initStickySummary } from './components/sticky-order-summary';
32
33
 
33
34
  var Wick = window.Wick || {};
34
35
  Wick.BasketPage = {
@@ -1256,6 +1257,9 @@ Wick.BasketPage = {
1256
1257
  $(Wick.BasketPage.el.content).find(quantityButton).prop('disabled', false);
1257
1258
  }
1258
1259
  };
1260
+
1261
+ $(document).on('cartUpdate', initStickySummary);
1262
+
1259
1263
  $(document).ready(function () {
1260
1264
  function init() {
1261
1265
 
@@ -1290,6 +1294,7 @@ $(document).ready(function () {
1290
1294
 
1291
1295
  $(Wick.BasketPage.el.voucherRemove).unbind('click');
1292
1296
  Wick.BasketPage.paintActionButton();
1297
+ initStickySummary();
1293
1298
  Wick.BasketPage.updateCart(...Array(3), true);
1294
1299
  setDefaultCharityValue();
1295
1300
  if (!$(Wick.BasketPage.el.loader).length) {
@@ -0,0 +1,40 @@
1
+ export function initStickySummary () {
2
+ let io;
3
+ const $summaries = $('[data-summary-main]');
4
+ const $stickies = $('[data-summary-sticky]');
5
+ if (!$summaries.length || !$stickies.length) return;
6
+
7
+ const toggle = (hide) => {
8
+ $stickies.toggleClass('is-hidden', hide);
9
+ $('body').toggleClass('summary-hidden', hide);
10
+
11
+ if (hide) {
12
+ $('.summary__aside.collapse.show').collapse('hide');
13
+ }
14
+ };
15
+
16
+ if ('IntersectionObserver' in window) {
17
+ if (io) io.disconnect();
18
+ io = new IntersectionObserver(
19
+ entries => {
20
+ const visible = entries.some(e => e.isIntersecting);
21
+ toggle(visible);
22
+ },
23
+ { rootMargin: '0px 0px -20% 0px', threshold: 0 }
24
+ );
25
+ $summaries.each(function () { io.observe(this); });
26
+ return;
27
+ }
28
+
29
+ function check () {
30
+ let hide = false;
31
+ $summaries.each(function () {
32
+ const r = this.getBoundingClientRect();
33
+ if (r.top < window.innerHeight * 0.8 && r.bottom > 0) hide = true;
34
+ });
35
+ toggle(hide);
36
+ }
37
+ $(window).off('scroll.sticky resize.sticky')
38
+ .on('scroll.sticky resize.sticky', check);
39
+ check();
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wickes-css2",
3
- "version": "2.94.0-order-summary.2",
3
+ "version": "2.94.0-order-summary.4",
4
4
  "description": "CSS and JS and page templates in use by Wickes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,7 +37,7 @@
37
37
  {{/if}}
38
38
  </ul>
39
39
  {{#unless mobile}}
40
- <div class="checkout-widget__total">
40
+ <div class="checkout-widget__total" data-summary-main>
41
41
  {{#if confirmationSummary}}
42
42
  <div> {{ confirmation-summary.total.title }}</div>
43
43
  <div class="checkout-widget__total-value">{{ confirmation-summary.total.value }}</div>
@@ -1,7 +1,7 @@
1
1
  {{#if basket}}
2
2
  <div class="summary summary--mobile d-lg-none" id="summary-mobile-{{id}}">
3
3
  {{> summary-mobile-bar}}
4
- <div class="collapse summary__aside container" id="checkout-summary-mobile-accordion-{{id}}">
4
+ <div class="collapse summary__aside container" id="checkout-summary-mobile-accordion-{{id}}" data-summary-sticky>
5
5
 
6
6
  {{> checkout_order-summary-new head=title mod=mod id=(concat id "-mobile") mobile="true"}}
7
7
  {{#unless basket}}
@@ -1,4 +1,4 @@
1
- <div class="summary__mobile-bar">
1
+ <div class="summary__mobile-bar" data-summary-sticky>
2
2
  <div class="summary__mobile-order collapsed"
3
3
  data-toggle="collapse"
4
4
  aria-expanded="false"
@@ -13,5 +13,7 @@
13
13
  </div>
14
14
  </div>
15
15
  </div>
16
- {{> checkout-action container="true" hidePaypalEmail="true"}}
16
+ <div>
17
+ {{> checkout-action container="true" hidePaypalEmail="true"}}
18
+ </div>
17
19
  </div>
@@ -29,6 +29,7 @@ import {
29
29
  } from './basket/session-sync'
30
30
  import {displayEnergyEfficiency} from "./basket/display-energy-efficiency";
31
31
  import {appendLoader, hideLoader, showLoader} from "./utils/loader";
32
+ import { initStickySummary } from './components/sticky-order-summary';
32
33
 
33
34
  var Wick = window.Wick || {};
34
35
  Wick.BasketPage = {
@@ -1256,6 +1257,9 @@ Wick.BasketPage = {
1256
1257
  $(Wick.BasketPage.el.content).find(quantityButton).prop('disabled', false);
1257
1258
  }
1258
1259
  };
1260
+
1261
+ $(document).on('cartUpdate', initStickySummary);
1262
+
1259
1263
  $(document).ready(function () {
1260
1264
  function init() {
1261
1265
 
@@ -1290,6 +1294,7 @@ $(document).ready(function () {
1290
1294
 
1291
1295
  $(Wick.BasketPage.el.voucherRemove).unbind('click');
1292
1296
  Wick.BasketPage.paintActionButton();
1297
+ initStickySummary();
1293
1298
  Wick.BasketPage.updateCart(...Array(3), true);
1294
1299
  setDefaultCharityValue();
1295
1300
  if (!$(Wick.BasketPage.el.loader).length) {
@@ -0,0 +1,40 @@
1
+ export function initStickySummary () {
2
+ let io;
3
+ const $summaries = $('[data-summary-main]');
4
+ const $stickies = $('[data-summary-sticky]');
5
+ if (!$summaries.length || !$stickies.length) return;
6
+
7
+ const toggle = (hide) => {
8
+ $stickies.toggleClass('is-hidden', hide);
9
+ $('body').toggleClass('summary-hidden', hide);
10
+
11
+ if (hide) {
12
+ $('.summary__aside.collapse.show').collapse('hide');
13
+ }
14
+ };
15
+
16
+ if ('IntersectionObserver' in window) {
17
+ if (io) io.disconnect();
18
+ io = new IntersectionObserver(
19
+ entries => {
20
+ const visible = entries.some(e => e.isIntersecting);
21
+ toggle(visible);
22
+ },
23
+ { rootMargin: '0px 0px -20% 0px', threshold: 0 }
24
+ );
25
+ $summaries.each(function () { io.observe(this); });
26
+ return;
27
+ }
28
+
29
+ function check () {
30
+ let hide = false;
31
+ $summaries.each(function () {
32
+ const r = this.getBoundingClientRect();
33
+ if (r.top < window.innerHeight * 0.8 && r.bottom > 0) hide = true;
34
+ });
35
+ toggle(hide);
36
+ }
37
+ $(window).off('scroll.sticky resize.sticky')
38
+ .on('scroll.sticky resize.sticky', check);
39
+ check();
40
+ }
@@ -19,10 +19,10 @@
19
19
  {{/content}}
20
20
  {{#content "aside"}}
21
21
  {{> order-summary
22
- shopping-cart-v2.checkout
23
- id=1
24
- title="Order Summary"
25
- basket=true
22
+ shopping-cart-v2.checkout
23
+ id=1
24
+ title="Order Summary"
25
+ basket=true
26
26
  }}
27
27
  {{> checkout-action mod="mounted"}}
28
28
  {{> checkout-action mod="mounted" view="mobile"}}
@@ -1,5 +1,35 @@
1
1
  @import '../helpers/helpers';
2
2
 
3
+ [data-summary-sticky] {
4
+ position: fixed;
5
+ bottom: 0;
6
+ left: 0;
7
+ right: 0;
8
+ transform: translateY(100%);
9
+ opacity: 0;
10
+ pointer-events: none;
11
+ will-change: transform, opacity;
12
+ transition: transform 0.5s ease, opacity 0.5s ease;
13
+ }
14
+
15
+ [data-summary-sticky]:not(.is-hidden) {
16
+ transform: translateY(0);
17
+ opacity: 1;
18
+ pointer-events: auto;
19
+ }
20
+
21
+ [data-summary-sticky].is-hidden {
22
+ transform: translateY(100%);
23
+ opacity: 0;
24
+ transition: transform 0.5s ease 0s, opacity 0.5s ease 5s;
25
+ pointer-events: none;
26
+ }
27
+
28
+ body.summary-hidden .back-to-top {
29
+ bottom: 20px !important;
30
+ right: 16px !important;
31
+ }
32
+
3
33
  .summary {
4
34
  &__aside {
5
35
  padding: 15px;