@ons/design-system 46.0.0 → 46.1.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.
package/js/main.js CHANGED
@@ -24,4 +24,5 @@ import '../components/skip-to-content/skip-to-content.dom';
24
24
  import '../components/download-resources/download-resources';
25
25
  import '../components/select/select';
26
26
  import '../components/modal/modal.dom';
27
- import '../components/timeout-modal/timeout.dom';
27
+ import '../components/timeout-modal/timeout-modal.dom';
28
+ import '../components/timeout-panel/timeout-panel.dom';
@@ -1,15 +1,13 @@
1
- import Modal from '../modal/modal';
2
-
3
1
  export default class Timeout {
4
- constructor(context, url, time) {
2
+ constructor(context, sessionExpiryEndpoint, initialExpiryTime, enableTimeoutReset, startOnLoad) {
5
3
  this.context = context;
6
- this.sessionExpiryEndpoint = url;
7
- this.initialExpiryTime = time;
8
- this.continueButton = context.querySelector('.ons-js-modal-btn');
4
+ this.sessionExpiryEndpoint = sessionExpiryEndpoint;
5
+ this.initialExpiryTime = initialExpiryTime;
6
+ this.enableTimeoutReset = enableTimeoutReset || false;
7
+ this.startOnLoad = startOnLoad || false;
9
8
  this.countdown = context.querySelector('.ons-js-timeout-timer');
10
9
  this.accessibleCountdown = context.querySelector('.ons-js-timeout-timer-acc');
11
10
  this.timeOutRedirectUrl = context.getAttribute('data-redirect-url');
12
- this.modalVisibleInMilliseconds = context.getAttribute('data-show-modal-time') * 1000;
13
11
 
14
12
  // Language dependent text strings
15
13
  this.minutesTextSingular = context.getAttribute('data-minutes-text-singular');
@@ -17,17 +15,15 @@ export default class Timeout {
17
15
  this.secondsTextSingular = context.getAttribute('data-seconds-text-singular');
18
16
  this.secondsTextPlural = context.getAttribute('data-seconds-text-plural');
19
17
  this.countdownText = context.getAttribute('data-countdown-text');
20
- this.redirectingText = context.getAttribute('data-redirecting-text');
18
+ this.countdownExpiredText = context.getAttribute('data-countdown-expired-text');
19
+ this.endWithFullStop = context.getAttribute('data-full-stop');
21
20
 
22
21
  // Settings
23
- this.expiryTimeInMilliseconds = 0;
24
22
  this.expiryTime = '';
25
- this.showModalTimeout = null;
23
+ this.expiryTimeInMilliseconds = 0;
26
24
  this.timers = [];
27
25
  this.timerRunOnce = false;
28
-
29
- // Create modal instance
30
- this.modal = new Modal(this.context);
26
+ this.countdownStarted = false;
31
27
 
32
28
  // Start module
33
29
  this.initialise();
@@ -39,43 +35,31 @@ export default class Timeout {
39
35
  } else {
40
36
  this.expiryTime = await this.setNewExpiryTime();
41
37
  }
42
-
43
38
  this.expiryTimeInMilliseconds = this.convertTimeToMilliSeconds(this.expiryTime);
44
39
 
45
- this.bindEventListeners();
46
- }
47
-
48
- bindEventListeners() {
49
- window.onload = this.startTimeout();
50
- window.addEventListener('focus', this.handleWindowFocus.bind(this));
51
- window.addEventListener('keydown', this.escToClose.bind(this));
52
- this.continueButton.addEventListener('click', this.closeModalAndRestartTimeout.bind(this));
53
- this.addThrottledEvents();
54
- }
55
-
56
- startTimeout() {
57
- clearTimeout(this.showModalTimeout);
58
- this.showModalTimeout = setTimeout(this.openModal.bind(this), this.expiryTimeInMilliseconds - this.modalVisibleInMilliseconds);
59
- }
40
+ if (this.enableTimeoutReset) {
41
+ this.addThrottledResetEvents();
42
+ }
60
43
 
61
- async openModal() {
62
- const modalWillOpen = await this.hasExpiryTimeResetInAnotherTab();
63
- if (modalWillOpen && !this.modal.isDialogOpen()) {
64
- this.modal.openDialog();
44
+ if (this.startOnLoad) {
65
45
  this.startUiCountdown();
66
46
  }
47
+
48
+ window.addEventListener('focus', this.handleWindowFocus.bind(this));
67
49
  }
68
50
 
69
51
  async startUiCountdown() {
70
52
  this.clearTimers();
71
- clearInterval(this.shouldModalCloseCheck);
53
+ this.countdownStarted = true;
72
54
 
73
- this.shouldModalCloseCheck = setInterval(async () => {
74
- await this.hasExpiryTimeResetInAnotherTab();
75
- }, 20000);
55
+ if (this.enableTimeoutReset) {
56
+ this.shouldRestartCheck = setInterval(async () => {
57
+ await this.hasExpiryTimeResetInAnotherTab();
58
+ }, 20000);
59
+ }
76
60
 
77
- let millseconds = this.modalVisibleInMilliseconds;
78
- let seconds = millseconds / 1000;
61
+ let milliseconds = this.convertTimeToMilliSeconds(this.expiryTime);
62
+ let seconds = milliseconds / 1000;
79
63
  let timers = this.timers;
80
64
  let $this = this;
81
65
 
@@ -95,14 +79,15 @@ export default class Timeout {
95
79
  (minutesLeft > 0 ? minutesText : '') +
96
80
  (minutesLeft > 0 && secondsLeft > 0 ? ' ' : '') +
97
81
  (secondsLeft > 0 ? secondsText : '') +
98
- '</span>.';
82
+ '</span>' +
83
+ ($this.endWithFullStop ? '.' : '');
99
84
 
100
85
  if (timerExpired) {
101
- const shouldExpire = await $this.hasExpiryTimeResetInAnotherTab();
86
+ const shouldExpire = this.enableTimeoutReset ? await $this.hasExpiryTimeResetInAnotherTab() : true;
102
87
 
103
88
  if (shouldExpire) {
104
- $this.countdown.innerHTML = '<span class="ons-u-fw-b">' + $this.redirectingText + '</span>';
105
- $this.accessibleCountdown.innerHTML = $this.redirectingText;
89
+ $this.countdown.innerHTML = '<span class="ons-u-fw-b">' + $this.countdownExpiredText + '</span>';
90
+ $this.accessibleCountdown.innerHTML = $this.countdownExpiredText;
106
91
  setTimeout($this.redirect.bind($this), 2000);
107
92
  }
108
93
  } else {
@@ -132,25 +117,16 @@ export default class Timeout {
132
117
  if (checkExpiryTime != this.expiryTime) {
133
118
  this.expiryTime = checkExpiryTime;
134
119
  this.expiryTimeInMilliseconds = this.convertTimeToMilliSeconds(checkExpiryTime);
135
- this.closeModalAndRestartTimeout(this.expiryTimeInMilliseconds);
120
+ this.restartTimeout(this.expiryTimeInMilliseconds);
136
121
  } else {
137
122
  return true;
138
123
  }
139
124
  }
140
125
 
141
- closeModalAndRestartTimeout(timeInMilliSeconds) {
142
- if (typeof timeInMilliSeconds !== 'string') {
143
- timeInMilliSeconds = false;
144
- }
145
- if (this.modal.isDialogOpen()) {
146
- this.modal.closeDialog();
147
- }
148
- this.restartTimeout(timeInMilliSeconds);
149
- }
150
-
151
126
  async restartTimeout(timeInMilliSeconds) {
152
127
  this.clearTimers();
153
- clearInterval(this.shouldModalCloseCheck);
128
+ clearInterval(this.shouldRestartCheck);
129
+ this.countdownStarted = false;
154
130
 
155
131
  if (timeInMilliSeconds) {
156
132
  this.expiryTimeInMilliseconds = timeInMilliSeconds;
@@ -159,26 +135,13 @@ export default class Timeout {
159
135
  this.expiryTime = createNewExpiryTime;
160
136
  this.expiryTimeInMilliseconds = this.convertTimeToMilliSeconds(createNewExpiryTime);
161
137
  }
162
-
163
- this.startTimeout();
164
138
  }
165
139
 
166
140
  async handleWindowFocus() {
167
- if (this.sessionExpiryEndpoint) {
168
- const canSetNewExpiry = await this.setNewExpiryTime();
169
- if (!canSetNewExpiry) {
170
- this.redirect();
171
- } else {
172
- const newExpiryTimeInMilliseconds = this.convertTimeToMilliSeconds(canSetNewExpiry).toString();
173
- this.closeModalAndRestartTimeout(newExpiryTimeInMilliseconds);
174
- }
175
- }
176
- }
177
-
178
- escToClose(event) {
179
- if (this.modal.isDialogOpen() && event.keyCode === 27) {
180
- this.closeModalAndRestartTimeout();
181
- }
141
+ this.expiryTime = await this.getExpiryTime();
142
+ this.clearTimers();
143
+ clearInterval(this.shouldRestartCheck);
144
+ this.startUiCountdown();
182
145
  }
183
146
 
184
147
  async setNewExpiryTime() {
@@ -235,45 +198,45 @@ export default class Timeout {
235
198
  }
236
199
  }
237
200
 
238
- addThrottledEvents() {
201
+ addThrottledResetEvents() {
239
202
  window.onclick = this.throttle(() => {
240
203
  /* istanbul ignore next */
241
- if (!this.modal.isDialogOpen()) {
204
+ if (!this.countdownStarted) {
242
205
  this.restartTimeout();
243
206
  }
244
207
  }, 61000);
245
208
 
246
209
  window.onmousemove = this.throttle(() => {
247
210
  /* istanbul ignore next */
248
- if (!this.modal.isDialogOpen()) {
211
+ if (!this.countdownStarted) {
249
212
  this.restartTimeout();
250
213
  }
251
214
  }, 61000);
252
215
 
253
216
  window.onmousedown = this.throttle(() => {
254
217
  /* istanbul ignore next */
255
- if (!this.modal.isDialogOpen()) {
218
+ if (!this.countdownStarted) {
256
219
  this.restartTimeout();
257
220
  }
258
221
  }, 61000);
259
222
 
260
223
  window.onscroll = this.throttle(() => {
261
224
  /* istanbul ignore next */
262
- if (!this.modal.isDialogOpen()) {
225
+ if (!this.countdownStarted) {
263
226
  this.restartTimeout();
264
227
  }
265
228
  }, 61000);
266
229
 
267
230
  window.onkeypress = this.throttle(() => {
268
231
  /* istanbul ignore next */
269
- if (!this.modal.isDialogOpen()) {
232
+ if (!this.countdownStarted) {
270
233
  this.restartTimeout();
271
234
  }
272
235
  }, 61000);
273
236
 
274
237
  window.onkeyup = this.throttle(() => {
275
238
  /* istanbul ignore next */
276
- if (!this.modal.isDialogOpen()) {
239
+ if (!this.countdownStarted) {
277
240
  this.restartTimeout();
278
241
  }
279
242
  }, 61000);
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.0.0",
4
+ "version": "46.1.0",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "author": {