@ons/design-system 46.1.0 → 46.1.3

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018 ONS Digital
3
+ Copyright (c) 2018 Crown Copyright (Office for National Statistics)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -12,7 +12,7 @@
12
12
  }
13
13
 
14
14
  &__subject {
15
- margin: 0;
15
+ margin: 0 0 0.2rem;
16
16
  }
17
17
 
18
18
  &__metadata {
@@ -33,9 +33,10 @@
33
33
  color: $color-text;
34
34
  display: inline-block;
35
35
  height: 2.5rem;
36
+ line-height: 2.3rem;
36
37
  margin: 0 0.1rem 0 0;
37
38
  overflow: visible;
38
- padding: 0.5rem 1rem;
39
+ padding: 0 1rem;
39
40
  position: relative;
40
41
  text-decoration: underline;
41
42
 
@@ -8,6 +8,9 @@ export default class TimeoutModal {
8
8
  this.initialExpiryTime = initialExpiryTime;
9
9
  this.continueButton = context.querySelector('.ons-js-modal-btn');
10
10
  this.modalVisibleInMilliseconds = context.getAttribute('data-show-modal-time') * 1000;
11
+ this.expiryTime = '';
12
+ this.expiryTimeInMilliseconds = 0;
13
+ this.shouldRestartCheck = false;
11
14
 
12
15
  // Create modal instance
13
16
  this.modal = new Modal(this.context);
@@ -27,7 +30,8 @@ export default class TimeoutModal {
27
30
  startTimeout() {
28
31
  clearTimeout(this.showModalTimeout);
29
32
  if (this.initialExpiryTime) {
30
- this.expiryTimeInMilliseconds = this.timeout.convertTimeToMilliSeconds(this.initialExpiryTime);
33
+ this.expiryTime = this.timeout.expiryTime;
34
+ this.expiryTimeInMilliseconds = this.timeout.convertTimeToMilliSeconds(this.expiryTime);
31
35
  } else {
32
36
  // For demo purposes
33
37
  this.expiryTimeInMilliseconds = 60000;
@@ -39,18 +43,39 @@ export default class TimeoutModal {
39
43
  }
40
44
 
41
45
  async openModalAndStartCountdown() {
42
- const modalWillOpen = await this.timeout.hasExpiryTimeResetInAnotherTab();
46
+ const modalWillOpen = await this.hasExpiryTimeResetInAnotherTab();
43
47
  if (modalWillOpen && !this.modal.isDialogOpen()) {
44
48
  this.modal.openDialog();
45
49
  this.timeout.startUiCountdown();
50
+
51
+ this.shouldRestartCheck = setInterval(async () => {
52
+ await this.hasExpiryTimeResetInAnotherTab();
53
+ }, 20000);
46
54
  }
47
55
  }
48
56
 
49
- closeModalAndRestartTimeout() {
57
+ async hasExpiryTimeResetInAnotherTab() {
58
+ const checkExpiryTime = await this.timeout.getExpiryTime();
59
+ if (checkExpiryTime.substring(0, 19) != this.timeout.expiryTime.substring(0, 19)) {
60
+ // Substring is required as endpoint can at random return milliseconds with expiry time
61
+ this.expiryTime = checkExpiryTime;
62
+ this.expiryTimeInMilliseconds = this.timeout.convertTimeToMilliSeconds(checkExpiryTime);
63
+ this.closeModalAndRestartTimeout(this.expiryTimeInMilliseconds);
64
+ } else {
65
+ return true;
66
+ }
67
+ }
68
+
69
+ async closeModalAndRestartTimeout(time) {
70
+ clearInterval(this.shouldRestartCheck);
71
+
72
+ if (typeof timeInMilliSeconds !== 'string') {
73
+ time = false;
74
+ }
50
75
  if (this.modal.isDialogOpen()) {
51
76
  this.modal.closeDialog();
52
77
  }
53
- this.timeout.restartTimeout();
78
+ await this.timeout.restartTimeout(time);
54
79
  this.startTimeout();
55
80
  }
56
81