@ons/design-system 61.0.0 → 61.0.1

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.
@@ -28,9 +28,8 @@
28
28
 
29
29
  {% if not params.error %}
30
30
  {% call onsPanel({
31
- "classes": "ons-u-mb-s" + (' ' + params.classes if params.classes)
32
- })
33
- %}
31
+ "classes": "ons-u-mb-s" + (' ' + params.classes if params.classes)
32
+ }) %}
34
33
  {{ content | safe }}
35
34
  {% endcall %}
36
35
  {% else %}
@@ -39,11 +38,10 @@
39
38
 
40
39
  {% if params.securityMessage %}
41
40
  {% call onsPanel({
42
- "type": "bare",
43
- "iconType": "lock",
44
- "classes": "ons-u-mb-s"
45
- })
46
- %}
41
+ "type": "bare",
42
+ "iconType": "lock",
43
+ "classes": "ons-u-mb-s"
44
+ }) %}
47
45
  {{ params.securityMessage }}
48
46
  {% endcall %}
49
47
  {% endif %}
@@ -1,4 +1,5 @@
1
1
  import dialogPolyfill from 'dialog-polyfill';
2
+ import initAnalytics from '../../js/analytics';
2
3
 
3
4
  const overLayClass = 'ons-modal-overlay';
4
5
  const ie11Class = 'ons-modal-ie11';
@@ -8,7 +9,7 @@ export default class Modal {
8
9
  this.component = component;
9
10
  this.launcher = document.querySelector(`[data-modal-id=${component.id}]`);
10
11
  this.closeButton = component.querySelector('.ons-js-modal-btn');
11
- this.setGaAttributes = component.getAttribute('data-enable-ga');
12
+ this.setGAAttributes = component.getAttribute('data-enable-ga');
12
13
  this.lastFocusedEl = null;
13
14
  this.dialogCSSSupported = true;
14
15
  this.modalType = this.component.classList.contains('ons-js-timeout-modal') ? 'Timeout' : 'Generic';
@@ -33,9 +34,10 @@ export default class Modal {
33
34
  if (this.modalType !== 'Timeout') {
34
35
  window.addEventListener('keydown', this.escToClose.bind(this));
35
36
  }
36
- this.component.setAttribute('data-ga-action', `Modal initialised`);
37
- this.component.setAttribute('data-ga-label', `${this.modalType} modal initialised`);
38
- this.component.setAttribute('data-ga-category', `${this.modalType} modal`);
37
+
38
+ if (this.setGAAttributes) {
39
+ this.component.setAttribute('data-ga', `visible`);
40
+ }
39
41
  }
40
42
 
41
43
  dialogSupported() {
@@ -71,13 +73,15 @@ export default class Modal {
71
73
  this.component.showModal();
72
74
  }
73
75
 
74
- if (this.setGaAttributes) {
76
+ if (this.setGAAttributes) {
75
77
  if (event) {
76
78
  this.component.setAttribute('data-ga-action', `Modal opened by ${event.type} event`);
77
79
  } else {
78
80
  this.component.setAttribute('data-ga-action', 'Modal opened by timed event');
79
81
  }
80
82
  this.component.setAttribute('data-ga-label', `${this.modalType} modal opened`);
83
+ this.component.setAttribute('data-ga-category', `${this.modalType} modal`);
84
+ initAnalytics();
81
85
  }
82
86
  }
83
87
  }
@@ -116,13 +120,15 @@ export default class Modal {
116
120
  this.component.close();
117
121
  this.setFocusOnLastFocusedEl(this.lastFocusedEl);
118
122
 
119
- if (this.setGaAttributes) {
123
+ if (this.setGAAttributes) {
120
124
  if (event) {
121
125
  this.component.setAttribute('data-ga-action', `Modal closed by ${event.type} event`);
122
126
  } else {
123
127
  this.component.setAttribute('data-ga-action', 'Modal closed by timed event');
124
128
  }
125
129
  this.component.setAttribute('data-ga-label', `${this.modalType} modal closed`);
130
+ this.component.setAttribute('data-ga-category', `${this.modalType} modal`);
131
+ initAnalytics();
126
132
  }
127
133
  }
128
134
  }
@@ -82,17 +82,6 @@ describe('script: modal', () => {
82
82
  await setTestPage('/test', template);
83
83
  });
84
84
 
85
- describe('when the page has been loaded but the modal has not been opened yet', () => {
86
- it('has the correct attributes set on the modal', async () => {
87
- const gaLabel = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-label'));
88
- const gaAction = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-action'));
89
- const gaCategory = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-category'));
90
- expect(gaLabel).toBe('Generic modal initialised');
91
- expect(gaAction).toBe('Modal initialised');
92
- expect(gaCategory).toBe('Generic modal');
93
- });
94
- });
95
-
96
85
  describe('when the modal is launched by a click event', () => {
97
86
  beforeEach(async () => {
98
87
  await page.focus('#launcher');
@@ -1,26 +1,25 @@
1
1
  {% from "components/modal/_macro.njk" import onsModal %}
2
2
  {% macro onsTimeoutModal(params) %}
3
3
  {% call onsModal({
4
- "title": params.title,
5
- "btnText": params.btnText,
6
- "classes": "ons-js-timeout-modal",
7
- "enableGA": params.enableGA,
8
- "attributes": {
9
- "data-redirect-url": params.redirectUrl,
10
- "data-server-session-expires-at": params.sessionExpiresAt,
11
- "data-show-modal-time": params.showModalTimeInSeconds,
12
- "data-server-session-expiry-endpoint": params.serverSessionExpiryEndpoint,
13
- "data-countdown-text": params.countdownText,
14
- "data-countdown-expired-text": params.countdownExpiredText,
15
- "data-minutes-text-singular": params.minutesTextSingular,
16
- "data-minutes-text-plural": params.minutesTextPlural,
17
- "data-seconds-text-singular": params.secondsTextSingular,
18
- "data-seconds-text-plural": params.secondsTextPlural,
19
- "data-full-stop": params.endWithFullStop,
20
- "aria-describedby": "timeout-time-remaining"
21
- }
22
- })
23
- %}
4
+ "title": params.title,
5
+ "btnText": params.btnText,
6
+ "classes": "ons-js-timeout-modal",
7
+ "enableGA": params.enableGA,
8
+ "attributes": {
9
+ "data-redirect-url": params.redirectUrl,
10
+ "data-server-session-expires-at": params.sessionExpiresAt,
11
+ "data-show-modal-time": params.showModalTimeInSeconds,
12
+ "data-server-session-expiry-endpoint": params.serverSessionExpiryEndpoint,
13
+ "data-countdown-text": params.countdownText,
14
+ "data-countdown-expired-text": params.countdownExpiredText,
15
+ "data-minutes-text-singular": params.minutesTextSingular,
16
+ "data-minutes-text-plural": params.minutesTextPlural,
17
+ "data-seconds-text-singular": params.secondsTextSingular,
18
+ "data-seconds-text-plural": params.secondsTextPlural,
19
+ "data-full-stop": params.endWithFullStop,
20
+ "aria-describedby": "timeout-time-remaining"
21
+ }
22
+ }) %}
24
23
  <p>{{ params.textFirstLine }}</p>
25
24
  <p class="ons-js-timeout-timer" aria-hidden="true" aria-relevant="additions"></p>
26
25
  <p class="ons-js-timeout-timer-acc ons-u-vh" role="status" id="timeout-time-remaining"></p>
@@ -167,6 +167,7 @@ describe('script: timeout modal', () => {
167
167
  ...EXAMPLE_TIMEOUT_MODAL_BASIC,
168
168
  showModalTimeInSeconds: 1,
169
169
  sessionExpiresAt: expiryTimeInISOFormat,
170
+ enableGA: true,
170
171
  });
171
172
 
172
173
  const template = `
@@ -186,6 +187,15 @@ describe('script: timeout modal', () => {
186
187
  await page.waitForTimeout(2000);
187
188
  expect(page.url()).toContain('#!');
188
189
  });
190
+
191
+ it('and GA tracking is enabled it has the correct attributes set on the modal', async () => {
192
+ const gaLabel = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-label'));
193
+ const gaAction = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-action'));
194
+ const gaCategory = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-category'));
195
+ expect(gaLabel).toBe('Timeout modal closed');
196
+ expect(gaAction).toBe('Modal closed by timed event');
197
+ expect(gaCategory).toBe('Timeout modal');
198
+ });
189
199
  });
190
200
  });
191
201
 
@@ -233,23 +243,17 @@ describe('script: timeout modal', () => {
233
243
  });
234
244
 
235
245
  const template = `
236
- <div class="ons-page">
237
- ${component}
238
- </div>
239
- `;
246
+ <div class="ons-page">
247
+ ${component}
248
+ </div>
249
+ `;
240
250
 
241
251
  await setTestPage('/test', template);
242
252
  });
243
253
 
244
- describe('when the page has been loaded but the modal has not been opened yet', () => {
245
- it('has the correct attributes set on the modal', async () => {
246
- const gaLabel = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-label'));
247
- const gaAction = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-action'));
248
- const gaCategory = await page.$eval('.ons-modal', node => node.getAttribute('data-ga-category'));
249
- expect(gaLabel).toBe('Timeout modal initialised');
250
- expect(gaAction).toBe('Modal initialised');
251
- expect(gaCategory).toBe('Timeout modal');
252
- });
254
+ it('has ga initialise attribute set', async () => {
255
+ const gaInitialise = await page.$eval('.ons-modal', node => node.getAttribute('data-ga'));
256
+ expect(gaInitialise).toBe('visible');
253
257
  });
254
258
 
255
259
  describe('when the modal is open', () => {
package/js/analytics.js CHANGED
@@ -20,16 +20,12 @@ export const trackElement = el => {
20
20
  });
21
21
  };
22
22
 
23
- const isVisible = el => {
24
- return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
25
- };
26
-
27
23
  export default function initAnalytics() {
28
24
  let trackVisibleElements = [...document.querySelectorAll('[data-ga=visible]')];
29
25
 
30
26
  const interval = window.setInterval(() => {
31
27
  trackVisibleElements = trackVisibleElements.filter(element => {
32
- return isVisible(element) ? trackElement(element) && false : true;
28
+ return element ? trackElement(element) && false : true;
33
29
  });
34
30
  if (trackVisibleElements.length === 0) {
35
31
  window.clearInterval(interval);
package/js/timeout.js CHANGED
@@ -1,3 +1,4 @@
1
+ import initAnalytics from './analytics';
1
2
  export default class Timeout {
2
3
  constructor(context, sessionExpiryEndpoint, initialExpiryTime, enableTimeoutReset, startOnLoad) {
3
4
  this.context = context;
@@ -8,6 +9,7 @@ export default class Timeout {
8
9
  this.countdown = context.querySelector('.ons-js-timeout-timer');
9
10
  this.accessibleCountdown = context.querySelector('.ons-js-timeout-timer-acc');
10
11
  this.timeOutRedirectUrl = context.getAttribute('data-redirect-url');
12
+ this.setGAAttributes = context.getAttribute('data-enable-ga');
11
13
 
12
14
  // Language dependent text strings
13
15
  this.minutesTextSingular = context.getAttribute('data-minutes-text-singular');
@@ -79,6 +81,11 @@ export default class Timeout {
79
81
  if (timerExpired) {
80
82
  $this.countdown.innerHTML = '<span class="ons-u-fw-b">' + $this.countdownExpiredText + '</span>';
81
83
  $this.accessibleCountdown.innerHTML = $this.countdownExpiredText;
84
+ if ($this.setGAAttributes && $this.context.classList.contains('ons-modal')) {
85
+ $this.context.setAttribute('data-ga-action', 'Modal closed by timed event');
86
+ $this.context.setAttribute('data-ga-label', `Timeout modal closed`);
87
+ initAnalytics();
88
+ }
82
89
  setTimeout($this.redirect.bind($this), 2000);
83
90
  } else {
84
91
  seconds--;
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": "61.0.0",
4
+ "version": "61.0.1",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "author": {