@ons/design-system 46.0.0 → 46.1.2
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 +1 -1
- package/components/message-list/_message-list.scss +1 -1
- package/components/modal/_macro.njk +1 -1
- package/components/panel/_macro.njk +5 -1
- package/components/panel/_panel.scss +4 -0
- package/components/tabs/_tabs.scss +2 -1
- package/components/timeout-modal/_macro.njk +3 -2
- package/components/timeout-modal/{timeout.dom.js → timeout-modal.dom.js} +2 -2
- package/components/timeout-modal/timeout-modal.js +62 -0
- package/components/timeout-panel/_macro.njk +26 -0
- package/components/timeout-panel/timeout-panel.dom.js +17 -0
- package/css/census.css +1 -1
- package/css/main.css +1 -1
- package/js/main.js +2 -1
- package/{components/timeout-modal → js}/timeout.js +44 -78
- package/layout/_template.njk +2 -2
- package/package.json +2 -4
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
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,
|
|
2
|
+
constructor(context, sessionExpiryEndpoint, initialExpiryTime, enableTimeoutReset, startOnLoad) {
|
|
5
3
|
this.context = context;
|
|
6
|
-
this.sessionExpiryEndpoint =
|
|
7
|
-
this.initialExpiryTime =
|
|
8
|
-
this.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
53
|
+
this.countdownStarted = true;
|
|
72
54
|
|
|
73
|
-
this.
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
if (this.enableTimeoutReset) {
|
|
56
|
+
this.shouldRestartCheck = setInterval(async () => {
|
|
57
|
+
await this.hasExpiryTimeResetInAnotherTab();
|
|
58
|
+
}, 20000);
|
|
59
|
+
}
|
|
76
60
|
|
|
77
|
-
let
|
|
78
|
-
let seconds =
|
|
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.
|
|
105
|
-
$this.accessibleCountdown.innerHTML = $this.
|
|
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.
|
|
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.
|
|
128
|
+
clearInterval(this.shouldRestartCheck);
|
|
129
|
+
this.countdownStarted = false;
|
|
154
130
|
|
|
155
131
|
if (timeInMilliSeconds) {
|
|
156
132
|
this.expiryTimeInMilliseconds = timeInMilliSeconds;
|
|
@@ -159,25 +135,15 @@ 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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.closeModalAndRestartTimeout(newExpiryTimeInMilliseconds);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
escToClose(event) {
|
|
179
|
-
if (this.modal.isDialogOpen() && event.keyCode === 27) {
|
|
180
|
-
this.closeModalAndRestartTimeout();
|
|
141
|
+
this.expiryTime = await this.getExpiryTime();
|
|
142
|
+
this.clearTimers();
|
|
143
|
+
clearInterval(this.shouldRestartCheck);
|
|
144
|
+
if (this.countdownStarted) {
|
|
145
|
+
this.countdownStarted = false;
|
|
146
|
+
this.startUiCountdown();
|
|
181
147
|
}
|
|
182
148
|
}
|
|
183
149
|
|
|
@@ -235,45 +201,45 @@ export default class Timeout {
|
|
|
235
201
|
}
|
|
236
202
|
}
|
|
237
203
|
|
|
238
|
-
|
|
204
|
+
addThrottledResetEvents() {
|
|
239
205
|
window.onclick = this.throttle(() => {
|
|
240
206
|
/* istanbul ignore next */
|
|
241
|
-
if (!this.
|
|
207
|
+
if (!this.countdownStarted) {
|
|
242
208
|
this.restartTimeout();
|
|
243
209
|
}
|
|
244
210
|
}, 61000);
|
|
245
211
|
|
|
246
212
|
window.onmousemove = this.throttle(() => {
|
|
247
213
|
/* istanbul ignore next */
|
|
248
|
-
if (!this.
|
|
214
|
+
if (!this.countdownStarted) {
|
|
249
215
|
this.restartTimeout();
|
|
250
216
|
}
|
|
251
217
|
}, 61000);
|
|
252
218
|
|
|
253
219
|
window.onmousedown = this.throttle(() => {
|
|
254
220
|
/* istanbul ignore next */
|
|
255
|
-
if (!this.
|
|
221
|
+
if (!this.countdownStarted) {
|
|
256
222
|
this.restartTimeout();
|
|
257
223
|
}
|
|
258
224
|
}, 61000);
|
|
259
225
|
|
|
260
226
|
window.onscroll = this.throttle(() => {
|
|
261
227
|
/* istanbul ignore next */
|
|
262
|
-
if (!this.
|
|
228
|
+
if (!this.countdownStarted) {
|
|
263
229
|
this.restartTimeout();
|
|
264
230
|
}
|
|
265
231
|
}, 61000);
|
|
266
232
|
|
|
267
233
|
window.onkeypress = this.throttle(() => {
|
|
268
234
|
/* istanbul ignore next */
|
|
269
|
-
if (!this.
|
|
235
|
+
if (!this.countdownStarted) {
|
|
270
236
|
this.restartTimeout();
|
|
271
237
|
}
|
|
272
238
|
}, 61000);
|
|
273
239
|
|
|
274
240
|
window.onkeyup = this.throttle(() => {
|
|
275
241
|
/* istanbul ignore next */
|
|
276
|
-
if (!this.
|
|
242
|
+
if (!this.countdownStarted) {
|
|
277
243
|
this.restartTimeout();
|
|
278
244
|
}
|
|
279
245
|
}, 61000);
|
package/layout/_template.njk
CHANGED
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
</div>
|
|
192
192
|
{% endset %}
|
|
193
193
|
{% endif %}
|
|
194
|
-
{% if pageConfig.asideCol.position is defined and pageConfig.asideCol.position == "before" %}
|
|
194
|
+
{% if pageConfig.asideCol is defined and pageConfig.asideCol and pageConfig.asideCol.position is defined and pageConfig.asideCol.position == "before" %}
|
|
195
195
|
{{ aside | safe }}
|
|
196
196
|
{% endif %}
|
|
197
197
|
<div class="ons-grid__col ons-col-{{ mainColNumber }}@m{{ mainColClasses }}">
|
|
@@ -199,7 +199,7 @@
|
|
|
199
199
|
{% block main %}{% endblock %}
|
|
200
200
|
</main>
|
|
201
201
|
</div>
|
|
202
|
-
{% if pageConfig.asideCol.position is defined and pageConfig.asideCol.position == "after" %}
|
|
202
|
+
{% if pageConfig.asideCol is defined and pageConfig.asideCol and pageConfig.asideCol.position is defined and pageConfig.asideCol.position == "after" %}
|
|
203
203
|
{{ aside | safe }}
|
|
204
204
|
{% endif %}
|
|
205
205
|
</div>
|
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ons/design-system",
|
|
3
3
|
"description": "ONS Design System built CSS, JS, and Nunjucks templates",
|
|
4
|
-
"version": "46.
|
|
4
|
+
"version": "46.1.2",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": {
|
|
8
|
-
"name": "
|
|
9
|
-
"email": "bameyrick@gmail.com",
|
|
10
|
-
"url": "https://github.com/bameyrick"
|
|
8
|
+
"name": "ONS Digital"
|
|
11
9
|
},
|
|
12
10
|
"scripts": {
|
|
13
11
|
"start": "gulp start",
|