govuk_frontend_toolkit 4.14.1 → 4.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e930f48d96df464b6a83f79a134a2a832dbbf85
4
- data.tar.gz: 6912fbfef5c5057925daef6c3f6365ae21aafc5a
3
+ metadata.gz: 851436b61e519834d96f32d1269b194d2664599c
4
+ data.tar.gz: bb4bec220d75477490dc8fc10ba7140380e1c34c
5
5
  SHA512:
6
- metadata.gz: 34cc0e0e7b403de73f533017cac23caa7204fbf1fc327ce085b41da790c2a973ac7321a67251dc95a5895031f2a619800febb93f962fcb9545dc17146c59106d
7
- data.tar.gz: 995e4a9864de22fceecad8ba353c205ba85a4c8e853f1f0b934a5b63892295f44dd4fb4cb22107192548adadc0cab27fe774e95d00b0cdd699f3c9f56d83c3a7
6
+ metadata.gz: 6b6c3638a4df4d76c23d5dffed432c565208ca81664890a6c1dbf2ca5969ae13281e9479c3f1c75484ba71768dbc85eca0a25685ddf1803f2f55613ac415b790
7
+ data.tar.gz: 2dec81dc8c4d5e1437527eaf201c6f4f34d928f6bde344d709acc8faf2443482a3bab004020beec37c0cee273fc6bde6deee6ae9ec5e561cf01a1bebaafeb76a
@@ -1,3 +1,8 @@
1
+ # 4.15.0
2
+
3
+ - Add support for Google Analytics fieldsObject ([PR #298](https://github.com/alphagov/govuk_frontend_toolkit/pull/298))
4
+ - anchor-buttons.js: normalise keyboard behaviour between buttons and links with a button role ([PR #297](https://github.com/alphagov/govuk_frontend_toolkit/pull/297))
5
+
1
6
  # 4.14.1
2
7
 
3
8
  - Fix tabular number sizing in Firefox ([PR #301](https://github.com/alphagov/govuk_frontend_toolkit/pull/301))
@@ -1 +1 @@
1
- 4.14.1
1
+ 4.15.0
@@ -9,7 +9,9 @@
9
9
  var Analytics = function(config) {
10
10
  this.trackers = [];
11
11
  if (typeof config.universalId != 'undefined') {
12
- this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(config.universalId, config.cookieDomain));
12
+ var universalId = config.universalId;
13
+ delete config.universalId;
14
+ this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config));
13
15
  }
14
16
  };
15
17
 
@@ -3,25 +3,32 @@
3
3
 
4
4
  var GOVUK = global.GOVUK || {};
5
5
 
6
- var GoogleAnalyticsUniversalTracker = function(id, cookieDomain) {
7
- configureProfile(id, cookieDomain);
8
- anonymizeIp();
6
+ var GoogleAnalyticsUniversalTracker = function(trackingId, fieldsObject) {
9
7
 
10
- function configureProfile(id, cookieDomain) {
11
- sendToGa('create', id, {'cookieDomain': cookieDomain});
8
+ function configureProfile() {
9
+ // https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#create
10
+ sendToGa('create', trackingId, fieldsObject);
12
11
  }
13
12
 
14
13
  function anonymizeIp() {
15
14
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#anonymizeip
16
15
  sendToGa('set', 'anonymizeIp', true);
17
16
  }
17
+
18
+ // Support legacy cookieDomain param
19
+ if (typeof fieldsObject === 'string') {
20
+ fieldsObject = { cookieDomain: fieldsObject };
21
+ }
22
+
23
+ configureProfile();
24
+ anonymizeIp();
18
25
  };
19
26
 
20
27
  GoogleAnalyticsUniversalTracker.load = function() {
21
28
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
22
29
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
23
30
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
24
- })(global,document,'script','//www.google-analytics.com/analytics.js','ga');
31
+ })(global,document,'script','https://www.google-analytics.com/analytics.js','ga');
25
32
  };
26
33
 
27
34
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
@@ -0,0 +1,61 @@
1
+ // javascript 'shim' to trigger the click event of element(s)
2
+ // when the space key is pressed.
3
+ //
4
+ // usage instructions:
5
+ // GOVUK.anchorButtons.init();
6
+ //
7
+ // If you want to customise the shim you can pass in a custom configuration
8
+ // object with your own selector for the target elements and addional keyup
9
+ // codes if there becomes a need to do so. For example:
10
+ // GOVUK.anchorButtons.init({ selector: '[role="button"]' });
11
+ (function(global) {
12
+ "use strict";
13
+
14
+ var $ = global.jQuery;
15
+ var GOVUK = global.GOVUK || {};
16
+
17
+ GOVUK.anchorButtons = {
18
+
19
+ // default configuration that can be overridden by passing object as second parameter to module
20
+ config: {
21
+ // the target element(s) to attach the shim event to
22
+ selector: 'a[role="button"]',
23
+ // array of keys to match against upon the keyup event
24
+ keycodes: [
25
+ 32 // spacekey
26
+ ],
27
+ },
28
+
29
+ // event behaviour (not a typical anonymous function for resuse if needed)
30
+ triggerClickOnTarget: function triggerClickOnTarget(event) {
31
+ var code = event.charCode || event.keyCode;
32
+ // if the keyCode/charCode from this event is in the keycodes array then
33
+ if ($.inArray(code, this.config.keycodes) !== -1) {
34
+ event.preventDefault();
35
+ // trigger the target's click event
36
+ $(event.target).trigger("click");
37
+ }
38
+ },
39
+
40
+ // By default this will find all anchors with role attribute set to
41
+ // 'button' and will trigger their click event when the space key (32) is pressed.
42
+ // @method init
43
+ // @param {Object} customConfig object to override default configuration
44
+ // {String} customConfig.selector a selector for the elements to be 'clicked'
45
+ // {Array} customConfig.keycodes an array of javascript keycode values to match against that when pressed will trigger the click
46
+ init: function init(customConfig) {
47
+ // extend the default config with any custom attributes passed in
48
+ this.config = $.extend(this.config, customConfig);
49
+ // if we have found elements then:
50
+ if($(this.config.selector).length > 0) {
51
+ // listen to 'document' for keyup event on the elements and fire the triggerClickOnTarget
52
+ $(document).on('keyup', this.config.selector, this.triggerClickOnTarget.bind(this));
53
+ }
54
+ }
55
+
56
+ };
57
+
58
+ // hand back to global
59
+ global.GOVUK = GOVUK;
60
+
61
+ })(window);
@@ -5,7 +5,6 @@
5
5
  var GOVUK = global.GOVUK || {};
6
6
 
7
7
  var SelectionButtons = function (elmsOrSelector, opts) {
8
- var $elms;
9
8
 
10
9
  this.selectedClass = 'selected';
11
10
  this.focusedClass = 'focused';
@@ -15,7 +14,6 @@
15
14
  }.bind(this));
16
15
  }
17
16
  if (typeof elmsOrSelector === 'string') {
18
- $elms = $(elmsOrSelector);
19
17
  this.selector = elmsOrSelector;
20
18
  this.setInitialState($(this.selector));
21
19
  } else if (elmsOrSelector !== undefined) {
@@ -1,21 +1,29 @@
1
1
  describe("GOVUK.Analytics", function() {
2
+ function addGoogleAnalyticsSpy() {
3
+ window.ga = function() {};
4
+ spyOn(window, 'ga');
5
+ }
6
+
2
7
  var analytics;
8
+ var universalSetupArguments;
3
9
 
4
10
  beforeEach(function() {
5
- window.ga = function() {};
6
- spyOn(window, 'ga');
7
- this.config = {
8
- universalId: 'universal-id',
9
- cookieDomain: '.www.gov.uk'
10
- };
11
+ addGoogleAnalyticsSpy();
11
12
 
12
- analytics = new GOVUK.Analytics(this.config);
13
+ analytics = new GOVUK.Analytics({
14
+ universalId: 'universal-id',
15
+ cookieDomain: '.www.gov.uk',
16
+ siteSpeedSampleRate: 100
17
+ });
13
18
  });
14
19
 
15
20
  describe('when created', function() {
21
+ beforeEach(function() {
22
+ universalSetupArguments = window.ga.calls.allArgs();
23
+ });
24
+
16
25
  it('configures a universal tracker', function () {
17
- var universalSetupArguments = window.ga.calls.allArgs();
18
- expect(universalSetupArguments[0]).toEqual(['create', 'universal-id', {'cookieDomain': '.www.gov.uk'}]);
26
+ expect(universalSetupArguments[0]).toEqual(['create', 'universal-id', {cookieDomain: '.www.gov.uk', siteSpeedSampleRate: 100}]);
19
27
  });
20
28
  });
21
29
 
@@ -1,17 +1,26 @@
1
1
  describe("GOVUK.GoogleAnalyticsUniversalTracker", function() {
2
+ function addGoogleAnalyticsSpy() {
3
+ window.ga = function() {};
4
+ spyOn(window, 'ga');
5
+ }
6
+
2
7
  var universal;
8
+ var setupArguments;
3
9
 
4
10
  beforeEach(function() {
5
- window.ga = function() {};
6
- spyOn(window, 'ga');
7
- universal = new GOVUK.GoogleAnalyticsUniversalTracker('id', 'cookie-domain.com');
11
+ addGoogleAnalyticsSpy();
12
+
13
+ universal = new GOVUK.GoogleAnalyticsUniversalTracker('id', {
14
+ cookieDomain: 'cookie-domain.com',
15
+ siteSpeedSampleRate: 100
16
+ });
8
17
  });
9
18
 
10
19
  it('can load the libraries needed to run universal Google Analytics', function() {
11
20
  delete window.ga;
12
- $('[src="//www.google-analytics.com/analytics.js"]').remove();
21
+ $('[src="https://www.google-analytics.com/analytics.js"]').remove();
13
22
  GOVUK.GoogleAnalyticsUniversalTracker.load();
14
- expect($('script[async][src="//www.google-analytics.com/analytics.js"]').length).toBe(1);
23
+ expect($('script[async][src="https://www.google-analytics.com/analytics.js"]').length).toBe(1);
15
24
  expect(typeof window.ga).toBe('function');
16
25
 
17
26
  window.ga('send message');
@@ -19,14 +28,12 @@ describe("GOVUK.GoogleAnalyticsUniversalTracker", function() {
19
28
  });
20
29
 
21
30
  describe('when created', function() {
22
- var setupArguments;
23
-
24
31
  beforeEach(function() {
25
32
  setupArguments = window.ga.calls.allArgs();
26
33
  });
27
34
 
28
- it('configures a Google tracker using the provided profile ID and cookie domain', function() {
29
- expect(setupArguments[0]).toEqual(['create', 'id', {'cookieDomain': 'cookie-domain.com'}]);
35
+ it('configures a Google tracker using the provided profile ID and config', function() {
36
+ expect(setupArguments[0]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com', siteSpeedSampleRate: 100}]);
30
37
  });
31
38
 
32
39
  it('anonymises the IP', function() {
@@ -34,6 +41,19 @@ describe("GOVUK.GoogleAnalyticsUniversalTracker", function() {
34
41
  });
35
42
  });
36
43
 
44
+ describe('when created (with legacy non-object syntax)', function() {
45
+ beforeEach(function() {
46
+ addGoogleAnalyticsSpy();
47
+
48
+ universal = new GOVUK.GoogleAnalyticsUniversalTracker('id', 'cookie-domain.com');
49
+ setupArguments = window.ga.calls.allArgs();
50
+ });
51
+
52
+ it('configures a Google tracker using the provided profile ID and cookie domain', function() {
53
+ expect(setupArguments[0]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com'}]);
54
+ });
55
+ });
56
+
37
57
  describe('when pageviews are tracked', function() {
38
58
  it('sends them to Google Analytics', function() {
39
59
  universal.trackPageview();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_frontend_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.14.1
4
+ version: 4.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-03 00:00:00.000000000 Z
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -229,6 +229,7 @@ files:
229
229
  - app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js
230
230
  - app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
231
231
  - app/assets/javascripts/govuk/analytics/print-intent.js
232
+ - app/assets/javascripts/govuk/anchor-buttons.js
232
233
  - app/assets/javascripts/govuk/modules.js
233
234
  - app/assets/javascripts/govuk/modules/auto-track-event.js
234
235
  - app/assets/javascripts/govuk/multivariate-test.js