govuk_frontend_toolkit 4.16.0 → 4.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/CHANGELOG.md +5 -0
- data/app/assets/VERSION.txt +1 -1
- data/app/assets/docs/javascript.md +33 -0
- data/app/assets/javascripts/govuk/{anchor-buttons.js → shim-links-with-button-role.js} +7 -8
- data/app/assets/spec/manifest.js +2 -0
- data/app/assets/spec/support/LocalTestRunner.html +4 -4
- data/app/assets/spec/unit/shim-links-with-button-role.spec.js +36 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f4ddc81957a656a0c17f892dfd132fc43ab5340
|
4
|
+
data.tar.gz: 3cea126b4db1d8bbf4738b4c0761a1caad2993d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1faf61dffef40648e7ff3950fc82c72cfc90809ae94cc21171620a42b628c0bb9f5f67580cd21e48c11e3d2927bb3da612921dbc67033f11ad47c71c895089c5
|
7
|
+
data.tar.gz: 130f686cd01660d1935c9356cba616803c6adba0011bb85c1a0fc2744de4671493ec7f27c2f7f57c618b0b2babb9eb08f532a3f10744073e76862e2ec515c7c7
|
data/app/assets/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 4.16.1
|
2
|
+
|
3
|
+
- Fix anchor-buttons.js to trigger a native click event, also rename to shimLinksWithButtonRole.js to explain what it does
|
4
|
+
- Add tests for shimLinksWithButtonRole ([PR #310](https://github.com/alphagov/govuk_frontend_toolkit/pull/310))
|
5
|
+
|
1
6
|
# 4.16.0
|
2
7
|
|
3
8
|
- Add Department for International Trade organisation ([PR #308](https://github.com/alphagov/govuk_frontend_toolkit/pull/308))
|
data/app/assets/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.16.
|
1
|
+
4.16.1
|
@@ -398,3 +398,36 @@ GOVUK.selectionButtons = function (elms, opts) {
|
|
398
398
|
```
|
399
399
|
|
400
400
|
This method will mean the `destroy` method is not available to call.
|
401
|
+
|
402
|
+
## Shim links with button role
|
403
|
+
|
404
|
+
Links styled to look like buttons lack button behaviour. This script will allow them to be triggered with a space key after they’ve been focused, to match standard buttons.
|
405
|
+
|
406
|
+
### Usage
|
407
|
+
|
408
|
+
By default, this behaviour will only be applied to links with a role of button.
|
409
|
+
|
410
|
+
```html
|
411
|
+
<a class="button" role="button">A button</a>
|
412
|
+
```
|
413
|
+
|
414
|
+
```javascript
|
415
|
+
GOVUK.shimLinksWithButtonRole.init();
|
416
|
+
```
|
417
|
+
|
418
|
+
If you need to override the elements this is applied to then you can do that by passing in a custom selector to the initialiser:
|
419
|
+
|
420
|
+
```javascript
|
421
|
+
GOVUK.shimLinksWithButtonRole.init({
|
422
|
+
selector: '.my-class'
|
423
|
+
});
|
424
|
+
```
|
425
|
+
|
426
|
+
It’s also possible to define more or different keycodes to activate against:
|
427
|
+
|
428
|
+
```javascript
|
429
|
+
// activate when the user presses space or ‘r’
|
430
|
+
GOVUK.shimLinksWithButtonRole.init({
|
431
|
+
keycodes: [32, 114]
|
432
|
+
});
|
433
|
+
```
|
@@ -2,19 +2,19 @@
|
|
2
2
|
// when the space key is pressed.
|
3
3
|
//
|
4
4
|
// usage instructions:
|
5
|
-
// GOVUK.
|
5
|
+
// GOVUK.shimLinksWithButtonRole.init();
|
6
6
|
//
|
7
7
|
// If you want to customise the shim you can pass in a custom configuration
|
8
8
|
// object with your own selector for the target elements and addional keyup
|
9
9
|
// codes if there becomes a need to do so. For example:
|
10
|
-
// GOVUK.
|
10
|
+
// GOVUK.shimLinksWithButtonRole.init({ selector: '[role="button"]' });
|
11
11
|
(function(global) {
|
12
12
|
"use strict";
|
13
13
|
|
14
14
|
var $ = global.jQuery;
|
15
15
|
var GOVUK = global.GOVUK || {};
|
16
16
|
|
17
|
-
GOVUK.
|
17
|
+
GOVUK.shimLinksWithButtonRole = {
|
18
18
|
|
19
19
|
// default configuration that can be overridden by passing object as second parameter to module
|
20
20
|
config: {
|
@@ -28,16 +28,15 @@
|
|
28
28
|
|
29
29
|
// event behaviour (not a typical anonymous function for resuse if needed)
|
30
30
|
triggerClickOnTarget: function triggerClickOnTarget(event) {
|
31
|
-
|
32
|
-
|
33
|
-
if ($.inArray(code, this.config.keycodes) !== -1) {
|
31
|
+
// if the code from this event is in the keycodes array then
|
32
|
+
if ($.inArray(event.which, this.config.keycodes) !== -1) {
|
34
33
|
event.preventDefault();
|
35
34
|
// trigger the target's click event
|
36
|
-
|
35
|
+
event.target.click();
|
37
36
|
}
|
38
37
|
},
|
39
38
|
|
40
|
-
// By default this will find all
|
39
|
+
// By default this will find all links with role attribute set to
|
41
40
|
// 'button' and will trigger their click event when the space key (32) is pressed.
|
42
41
|
// @method init
|
43
42
|
// @param {Object} customConfig object to override default configuration
|
data/app/assets/spec/manifest.js
CHANGED
@@ -6,6 +6,7 @@ var manifest = {
|
|
6
6
|
'../../javascripts/govuk/modules/auto-track-event.js',
|
7
7
|
'../../javascripts/govuk/multivariate-test.js',
|
8
8
|
'../../javascripts/govuk/primary-links.js',
|
9
|
+
'../../javascripts/govuk/shim-links-with-button-role.js',
|
9
10
|
'../../javascripts/govuk/stick-at-top-when-scrolling.js',
|
10
11
|
'../../javascripts/govuk/stop-scrolling-at-footer.js',
|
11
12
|
'../../javascripts/govuk/selection-buttons.js',
|
@@ -21,6 +22,7 @@ var manifest = {
|
|
21
22
|
'../unit/Modules/auto-track-event.spec.js',
|
22
23
|
'../unit/multivariate-test.spec.js',
|
23
24
|
'../unit/primary-links.spec.js',
|
25
|
+
'../unit/shim-links-with-button-role.spec.js',
|
24
26
|
'../unit/stick-at-top-when-scrolling.spec.js',
|
25
27
|
'../unit/selection-button.spec.js',
|
26
28
|
'../unit/analytics/google-analytics-universal-tracker.spec.js',
|
@@ -3,16 +3,16 @@
|
|
3
3
|
<head>
|
4
4
|
<title>Jasmine Test Runner</title>
|
5
5
|
|
6
|
-
<link rel="stylesheet" type="text/css" href="../../node_modules/
|
6
|
+
<link rel="stylesheet" type="text/css" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
|
7
7
|
<style>
|
8
8
|
#wrapper { display: none; }
|
9
9
|
</style>
|
10
10
|
|
11
11
|
<!-- JASMINE FILES -->
|
12
|
-
<script type="text/javascript" src="../../node_modules/
|
13
|
-
<script type="text/javascript" src="../../node_modules/
|
12
|
+
<script type="text/javascript" src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
|
13
|
+
<script type="text/javascript" src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
|
14
14
|
|
15
|
-
<script type="text/javascript" src="../../node_modules/
|
15
|
+
<script type="text/javascript" src="../../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
|
16
16
|
<script type="text/javascript" src="./load.js"></script>
|
17
17
|
</head>
|
18
18
|
<body>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
describe("shim-links-with-button-role", function () {
|
2
|
+
var $body;
|
3
|
+
var $buttonLink;
|
4
|
+
var keyupEvent;
|
5
|
+
|
6
|
+
beforeEach(function () {
|
7
|
+
$buttonLink = $('<a role="button">Button</a>');
|
8
|
+
$buttonLink.on('click',function(){
|
9
|
+
$buttonLink.addClass('clicked');
|
10
|
+
});
|
11
|
+
$(document.body).append($buttonLink);
|
12
|
+
keyupEvent = $.Event('keyup');
|
13
|
+
keyupEvent.target = $buttonLink.get(0);
|
14
|
+
GOVUK.shimLinksWithButtonRole.init();
|
15
|
+
});
|
16
|
+
|
17
|
+
afterEach(function () {
|
18
|
+
$buttonLink.remove();
|
19
|
+
$(document).off('keyup');
|
20
|
+
});
|
21
|
+
|
22
|
+
it('should trigger event on space', function(){
|
23
|
+
// Ideally we’d test the page loading functionality but that seems hard to
|
24
|
+
// do within a Jasmine context. Settle for checking a bound event trigger.
|
25
|
+
keyupEvent.which = 32; // Space character
|
26
|
+
$(document).trigger(keyupEvent);
|
27
|
+
expect($buttonLink.hasClass('clicked')).toBe(true);
|
28
|
+
});
|
29
|
+
|
30
|
+
it('should not trigger event on tab', function(){
|
31
|
+
keyupEvent.which = 9; // Tab character
|
32
|
+
$(document).trigger(keyupEvent);
|
33
|
+
expect($buttonLink.hasClass('clicked')).toBe(false);
|
34
|
+
});
|
35
|
+
|
36
|
+
});
|
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.16.
|
4
|
+
version: 4.16.1
|
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-
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -235,12 +235,12 @@ files:
|
|
235
235
|
- app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js
|
236
236
|
- app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
|
237
237
|
- app/assets/javascripts/govuk/analytics/print-intent.js
|
238
|
-
- app/assets/javascripts/govuk/anchor-buttons.js
|
239
238
|
- app/assets/javascripts/govuk/modules.js
|
240
239
|
- app/assets/javascripts/govuk/modules/auto-track-event.js
|
241
240
|
- app/assets/javascripts/govuk/multivariate-test.js
|
242
241
|
- app/assets/javascripts/govuk/primary-links.js
|
243
242
|
- app/assets/javascripts/govuk/selection-buttons.js
|
243
|
+
- app/assets/javascripts/govuk/shim-links-with-button-role.js
|
244
244
|
- app/assets/javascripts/govuk/stick-at-top-when-scrolling.js
|
245
245
|
- app/assets/javascripts/govuk/stop-scrolling-at-footer.js
|
246
246
|
- app/assets/javascripts/govuk_toolkit.js
|
@@ -265,6 +265,7 @@ files:
|
|
265
265
|
- app/assets/spec/unit/multivariate-test.spec.js
|
266
266
|
- app/assets/spec/unit/primary-links.spec.js
|
267
267
|
- app/assets/spec/unit/selection-button.spec.js
|
268
|
+
- app/assets/spec/unit/shim-links-with-button-role.spec.js
|
268
269
|
- app/assets/spec/unit/stick-at-top-when-scrolling.spec.js
|
269
270
|
- app/assets/stylesheets/.gitkeep
|
270
271
|
- app/assets/stylesheets/_colours.scss
|