@ons/design-system 46.1.2 → 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.
@@ -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,30 +30,52 @@ export default class TimeoutModal {
27
30
  startTimeout() {
28
31
  clearTimeout(this.showModalTimeout);
29
32
  if (this.initialExpiryTime) {
30
- this.totalMilliseconds = this.timeout.expiryTimeInMilliseconds;
33
+ this.expiryTime = this.timeout.expiryTime;
34
+ this.expiryTimeInMilliseconds = this.timeout.convertTimeToMilliSeconds(this.expiryTime);
31
35
  } else {
32
36
  // For demo purposes
33
- this.totalMilliseconds = 60000;
37
+ this.expiryTimeInMilliseconds = 60000;
34
38
  }
35
39
  this.showModalTimeout = setTimeout(
36
40
  this.openModalAndStartCountdown.bind(this),
37
- this.totalMilliseconds - this.modalVisibleInMilliseconds,
41
+ this.expiryTimeInMilliseconds - this.modalVisibleInMilliseconds,
38
42
  );
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
 
package/js/timeout.js CHANGED
@@ -51,14 +51,8 @@ export default class Timeout {
51
51
  async startUiCountdown() {
52
52
  this.clearTimers();
53
53
  this.countdownStarted = true;
54
-
55
- if (this.enableTimeoutReset) {
56
- this.shouldRestartCheck = setInterval(async () => {
57
- await this.hasExpiryTimeResetInAnotherTab();
58
- }, 20000);
59
- }
60
-
61
54
  let milliseconds = this.convertTimeToMilliSeconds(this.expiryTime);
55
+
62
56
  let seconds = milliseconds / 1000;
63
57
  let timers = this.timers;
64
58
  let $this = this;
@@ -83,13 +77,9 @@ export default class Timeout {
83
77
  ($this.endWithFullStop ? '.' : '');
84
78
 
85
79
  if (timerExpired) {
86
- const shouldExpire = this.enableTimeoutReset ? await $this.hasExpiryTimeResetInAnotherTab() : true;
87
-
88
- if (shouldExpire) {
89
- $this.countdown.innerHTML = '<span class="ons-u-fw-b">' + $this.countdownExpiredText + '</span>';
90
- $this.accessibleCountdown.innerHTML = $this.countdownExpiredText;
91
- setTimeout($this.redirect.bind($this), 2000);
92
- }
80
+ $this.countdown.innerHTML = '<span class="ons-u-fw-b">' + $this.countdownExpiredText + '</span>';
81
+ $this.accessibleCountdown.innerHTML = $this.countdownExpiredText;
82
+ setTimeout($this.redirect.bind($this), 2000);
93
83
  } else {
94
84
  seconds--;
95
85
  $this.expiryTimeInMilliseconds = seconds * 1000;
@@ -111,24 +101,10 @@ export default class Timeout {
111
101
  })();
112
102
  }
113
103
 
114
- async hasExpiryTimeResetInAnotherTab() {
115
- const checkExpiryTime = await this.getExpiryTime();
116
-
117
- if (checkExpiryTime != this.expiryTime) {
118
- this.expiryTime = checkExpiryTime;
119
- this.expiryTimeInMilliseconds = this.convertTimeToMilliSeconds(checkExpiryTime);
120
- this.restartTimeout(this.expiryTimeInMilliseconds);
121
- } else {
122
- return true;
123
- }
124
- }
125
-
126
104
  async restartTimeout(timeInMilliSeconds) {
127
105
  this.clearTimers();
128
- clearInterval(this.shouldRestartCheck);
129
106
  this.countdownStarted = false;
130
-
131
- if (timeInMilliSeconds) {
107
+ if (timeInMilliSeconds !== false) {
132
108
  this.expiryTimeInMilliseconds = timeInMilliSeconds;
133
109
  } else {
134
110
  const createNewExpiryTime = await this.setNewExpiryTime();
@@ -138,11 +114,8 @@ export default class Timeout {
138
114
  }
139
115
 
140
116
  async handleWindowFocus() {
141
- this.expiryTime = await this.getExpiryTime();
142
117
  this.clearTimers();
143
- clearInterval(this.shouldRestartCheck);
144
118
  if (this.countdownStarted) {
145
- this.countdownStarted = false;
146
119
  this.startUiCountdown();
147
120
  }
148
121
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ons/design-system",
3
3
  "description": "ONS Design System built CSS, JS, and Nunjucks templates",
4
- "version": "46.1.2",
4
+ "version": "46.1.3",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -78,8 +78,8 @@
78
78
  "chai": "^4.3.4",
79
79
  "chai-as-promised": "^7.1.1",
80
80
  "chai-spies": "^1.0.0",
81
- "codecov": "3.7.2",
82
- "core-js": "^3.15.2",
81
+ "codecov": "^3.8.3",
82
+ "core-js": "^3.21.1",
83
83
  "cssnano": "^4.1.11",
84
84
  "dialog-polyfill": "^0.5.6",
85
85
  "eslint": "^5.9.0",
@@ -119,7 +119,7 @@
119
119
  "karma-mocha-reporter": "^2.2.5",
120
120
  "lighthouse": "^7.5.0",
121
121
  "lint-staged": "^8.1.0",
122
- "lodash": "^4.17.11",
122
+ "lodash": "^4.17.21",
123
123
  "marked": "^2.1.3",
124
124
  "mdn-polyfills": "^5.14.0",
125
125
  "minimist": "^1.2.5",