govuk_frontend_toolkit 7.0.1 → 7.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a06217abb14b1587a98e4ad17c9e10f07c426ce1
|
4
|
+
data.tar.gz: 32af41483145c3e4206b919f2b51013ea1bbbe31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81823c3100252f3e39a31438f012def0602ae917b11e330978210b5ea433378b72c363d76c080bf54f99ca6a0ce6790ae83c01a11c38ad0588b333fea8abc5d0
|
7
|
+
data.tar.gz: cc75f42603dcf4d59320f5e5de93c80ed9db62b304a725f9d7c82fecd03c2c8c172b59f73d4f84b90911c7732edb7d5dc49af7526f9b292ba3fee88643b4833b
|
data/app/assets/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 7.1.0
|
2
|
+
|
3
|
+
- Promote the details polyfill to Frontend Toolkit from GOV.UK Elements ([PR #426](https://github.com/alphagov/govuk_frontend_toolkit/pull/426)).
|
4
|
+
|
1
5
|
# 7.0.1
|
2
6
|
|
3
7
|
- Volume up and down buttons in the media player were overlapping the current volume percentage on focus. This fix keeps the large button touch area, but adjusts the focus state to be smaller. ([PR #429](https://github.com/alphagov/govuk_frontend_toolkit/pull/429)).
|
data/app/assets/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.0
|
1
|
+
7.1.0
|
@@ -0,0 +1,240 @@
|
|
1
|
+
// <details> polyfill
|
2
|
+
// http://caniuse.com/#feat=details
|
3
|
+
|
4
|
+
// FF Support for HTML5's <details> and <summary>
|
5
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=591737
|
6
|
+
|
7
|
+
// http://www.sitepoint.com/fixing-the-details-element/
|
8
|
+
|
9
|
+
;(function (global) {
|
10
|
+
'use strict'
|
11
|
+
|
12
|
+
var GOVUK = global.GOVUK || {}
|
13
|
+
|
14
|
+
GOVUK.details = {
|
15
|
+
NATIVE_DETAILS: typeof document.createElement('details').open === 'boolean',
|
16
|
+
KEY_ENTER: 13,
|
17
|
+
KEY_SPACE: 32,
|
18
|
+
|
19
|
+
// Create a started flag so we can prevent the initialisation
|
20
|
+
// function firing from both DOMContentLoaded and window.onload
|
21
|
+
started: false,
|
22
|
+
|
23
|
+
// Add event construct for modern browsers or IE
|
24
|
+
// which fires the callback with a pre-converted target reference
|
25
|
+
addEvent: function (node, type, callback) {
|
26
|
+
if (node.addEventListener) {
|
27
|
+
node.addEventListener(type, function (e) {
|
28
|
+
callback(e, e.target)
|
29
|
+
}, false)
|
30
|
+
} else if (node.attachEvent) {
|
31
|
+
node.attachEvent('on' + type, function (e) {
|
32
|
+
callback(e, e.srcElement)
|
33
|
+
})
|
34
|
+
}
|
35
|
+
},
|
36
|
+
|
37
|
+
removeEvent: function (node, type) {
|
38
|
+
if (node.removeEventListener) {
|
39
|
+
node.removeEventListener(type, function (e) {
|
40
|
+
}, false)
|
41
|
+
} else if (node.detachEvent) {
|
42
|
+
node.detachEvent('on' + type, function (e) {
|
43
|
+
})
|
44
|
+
}
|
45
|
+
},
|
46
|
+
|
47
|
+
// Cross-browser character code / key pressed
|
48
|
+
charCode: function (e) {
|
49
|
+
return (typeof e.which === 'number') ? e.which : e.keyCode
|
50
|
+
},
|
51
|
+
|
52
|
+
// Cross-browser preventing default action
|
53
|
+
preventDefault: function (e) {
|
54
|
+
if (e.preventDefault) {
|
55
|
+
e.preventDefault()
|
56
|
+
} else {
|
57
|
+
e.returnValue = false
|
58
|
+
}
|
59
|
+
},
|
60
|
+
|
61
|
+
// Handle cross-modal click events
|
62
|
+
addClickEvent: function (node, callback) {
|
63
|
+
GOVUK.details.addEvent(node, 'keypress', function (e, target) {
|
64
|
+
// When the key gets pressed - check if it is enter or space
|
65
|
+
if (GOVUK.details.charCode(e) === GOVUK.details.KEY_ENTER || GOVUK.details.charCode(e) === GOVUK.details.KEY_SPACE) {
|
66
|
+
if (target.nodeName.toLowerCase() === 'summary') {
|
67
|
+
// Prevent space from scrolling the page
|
68
|
+
// and enter from submitting a form
|
69
|
+
GOVUK.details.preventDefault(e)
|
70
|
+
// Click to let the click event do all the necessary action
|
71
|
+
if (target.click) {
|
72
|
+
target.click()
|
73
|
+
} else {
|
74
|
+
// except Safari 5.1 and under don't support .click() here
|
75
|
+
callback(e, target)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
})
|
80
|
+
|
81
|
+
// Prevent keyup to prevent clicking twice in Firefox when using space key
|
82
|
+
GOVUK.details.addEvent(node, 'keyup', function (e, target) {
|
83
|
+
if (GOVUK.details.charCode(e) === GOVUK.details.KEY_SPACE) {
|
84
|
+
if (target.nodeName === 'SUMMARY') {
|
85
|
+
GOVUK.details.preventDefault(e)
|
86
|
+
}
|
87
|
+
}
|
88
|
+
})
|
89
|
+
|
90
|
+
GOVUK.details.addEvent(node, 'click', function (e, target) {
|
91
|
+
callback(e, target)
|
92
|
+
})
|
93
|
+
},
|
94
|
+
|
95
|
+
// Get the nearest ancestor element of a node that matches a given tag name
|
96
|
+
getAncestor: function (node, match) {
|
97
|
+
do {
|
98
|
+
if (!node || node.nodeName.toLowerCase() === match) {
|
99
|
+
break
|
100
|
+
}
|
101
|
+
node = node.parentNode
|
102
|
+
} while (node)
|
103
|
+
|
104
|
+
return node
|
105
|
+
},
|
106
|
+
|
107
|
+
// Initialisation function
|
108
|
+
addDetailsPolyfill: function (list, container) {
|
109
|
+
container = container || document.body
|
110
|
+
// If this has already happened, just return
|
111
|
+
// else set the flag so it doesn't happen again
|
112
|
+
if (GOVUK.details.started) {
|
113
|
+
return
|
114
|
+
}
|
115
|
+
GOVUK.details.started = true
|
116
|
+
// Get the collection of details elements, but if that's empty
|
117
|
+
// then we don't need to bother with the rest of the scripting
|
118
|
+
if ((list = container.getElementsByTagName('details')).length === 0) {
|
119
|
+
return
|
120
|
+
}
|
121
|
+
// else iterate through them to apply their initial state
|
122
|
+
var n = list.length
|
123
|
+
var i = 0
|
124
|
+
for (i; i < n; i++) {
|
125
|
+
var details = list[i]
|
126
|
+
|
127
|
+
// Save shortcuts to the inner summary and content elements
|
128
|
+
details.__summary = details.getElementsByTagName('summary').item(0)
|
129
|
+
details.__content = details.getElementsByTagName('div').item(0)
|
130
|
+
|
131
|
+
if (!details.__summary || !details.__content) {
|
132
|
+
return
|
133
|
+
}
|
134
|
+
// If the content doesn't have an ID, assign it one now
|
135
|
+
// which we'll need for the summary's aria-controls assignment
|
136
|
+
if (!details.__content.id) {
|
137
|
+
details.__content.id = 'details-content-' + i
|
138
|
+
}
|
139
|
+
|
140
|
+
// Add ARIA role="group" to details
|
141
|
+
details.setAttribute('role', 'group')
|
142
|
+
|
143
|
+
// Add role=button to summary
|
144
|
+
details.__summary.setAttribute('role', 'button')
|
145
|
+
|
146
|
+
// Add aria-controls
|
147
|
+
details.__summary.setAttribute('aria-controls', details.__content.id)
|
148
|
+
|
149
|
+
// Set tabIndex so the summary is keyboard accessible for non-native elements
|
150
|
+
// http://www.saliences.com/browserBugs/tabIndex.html
|
151
|
+
if (!GOVUK.details.NATIVE_DETAILS) {
|
152
|
+
details.__summary.tabIndex = 0
|
153
|
+
}
|
154
|
+
|
155
|
+
// Detect initial open state
|
156
|
+
var openAttr = details.getAttribute('open') !== null
|
157
|
+
if (openAttr === true) {
|
158
|
+
details.__summary.setAttribute('aria-expanded', 'true')
|
159
|
+
details.__content.setAttribute('aria-hidden', 'false')
|
160
|
+
} else {
|
161
|
+
details.__summary.setAttribute('aria-expanded', 'false')
|
162
|
+
details.__content.setAttribute('aria-hidden', 'true')
|
163
|
+
if (!GOVUK.details.NATIVE_DETAILS) {
|
164
|
+
details.__content.style.display = 'none'
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
// Create a circular reference from the summary back to its
|
169
|
+
// parent details element, for convenience in the click handler
|
170
|
+
details.__summary.__details = details
|
171
|
+
|
172
|
+
// If this is not a native implementation, create an arrow
|
173
|
+
// inside the summary
|
174
|
+
if (!GOVUK.details.NATIVE_DETAILS) {
|
175
|
+
var twisty = document.createElement('i')
|
176
|
+
|
177
|
+
if (openAttr === true) {
|
178
|
+
twisty.className = 'arrow arrow-open'
|
179
|
+
twisty.appendChild(document.createTextNode('\u25bc'))
|
180
|
+
} else {
|
181
|
+
twisty.className = 'arrow arrow-closed'
|
182
|
+
twisty.appendChild(document.createTextNode('\u25ba'))
|
183
|
+
}
|
184
|
+
|
185
|
+
details.__summary.__twisty = details.__summary.insertBefore(twisty, details.__summary.firstChild)
|
186
|
+
details.__summary.__twisty.setAttribute('aria-hidden', 'true')
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
// Bind a click event to handle summary elements
|
191
|
+
GOVUK.details.addClickEvent(container, function (e, summary) {
|
192
|
+
if (!(summary = GOVUK.details.getAncestor(summary, 'summary'))) {
|
193
|
+
return true
|
194
|
+
}
|
195
|
+
return GOVUK.details.statechange(summary)
|
196
|
+
})
|
197
|
+
},
|
198
|
+
|
199
|
+
// Define a statechange function that updates aria-expanded and style.display
|
200
|
+
// Also update the arrow position
|
201
|
+
statechange: function (summary) {
|
202
|
+
var expanded = summary.__details.__summary.getAttribute('aria-expanded') === 'true'
|
203
|
+
var hidden = summary.__details.__content.getAttribute('aria-hidden') === 'true'
|
204
|
+
|
205
|
+
summary.__details.__summary.setAttribute('aria-expanded', (expanded ? 'false' : 'true'))
|
206
|
+
summary.__details.__content.setAttribute('aria-hidden', (hidden ? 'false' : 'true'))
|
207
|
+
|
208
|
+
if (!GOVUK.details.NATIVE_DETAILS) {
|
209
|
+
summary.__details.__content.style.display = (expanded ? 'none' : '')
|
210
|
+
|
211
|
+
var hasOpenAttr = summary.__details.getAttribute('open') !== null
|
212
|
+
if (!hasOpenAttr) {
|
213
|
+
summary.__details.setAttribute('open', 'open')
|
214
|
+
} else {
|
215
|
+
summary.__details.removeAttribute('open')
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
if (summary.__twisty) {
|
220
|
+
summary.__twisty.firstChild.nodeValue = (expanded ? '\u25ba' : '\u25bc')
|
221
|
+
summary.__twisty.setAttribute('class', (expanded ? 'arrow arrow-closed' : 'arrow arrow-open'))
|
222
|
+
}
|
223
|
+
|
224
|
+
return true
|
225
|
+
},
|
226
|
+
|
227
|
+
destroy: function (node) {
|
228
|
+
GOVUK.details.removeEvent(node, 'click')
|
229
|
+
},
|
230
|
+
|
231
|
+
// Bind two load events for modern and older browsers
|
232
|
+
// If the first one fires it will set a flag to block the second one
|
233
|
+
// but if it's not supported then the second one will fire
|
234
|
+
init: function ($container) {
|
235
|
+
GOVUK.details.addEvent(document, 'DOMContentLoaded', GOVUK.details.addDetailsPolyfill)
|
236
|
+
GOVUK.details.addEvent(window, 'load', GOVUK.details.addDetailsPolyfill)
|
237
|
+
}
|
238
|
+
}
|
239
|
+
global.GOVUK = GOVUK
|
240
|
+
})(window)
|
data/app/assets/spec/manifest.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
var manifest = {
|
3
3
|
support: [
|
4
4
|
'../../node_modules/jquery/dist/jquery.js',
|
5
|
+
'../../javascripts/govuk/details.polyfill.js',
|
5
6
|
'../../javascripts/govuk/modules.js',
|
6
7
|
'../../javascripts/govuk/modules/auto-track-event.js',
|
7
8
|
'../../javascripts/govuk/primary-links.js',
|
@@ -19,6 +20,7 @@ var manifest = {
|
|
19
20
|
'../../javascripts/govuk/analytics/mailto-link-tracker.js'
|
20
21
|
],
|
21
22
|
test: [
|
23
|
+
'../unit/details.polyfill.spec.js',
|
22
24
|
'../unit/modules.spec.js',
|
23
25
|
'../unit/Modules/auto-track-event.spec.js',
|
24
26
|
'../unit/primary-links.spec.js',
|
@@ -0,0 +1,91 @@
|
|
1
|
+
/* global describe it expect beforeEach afterEach */
|
2
|
+
|
3
|
+
var $ = window.jQuery
|
4
|
+
|
5
|
+
describe('details-polyfill', function () {
|
6
|
+
'use strict'
|
7
|
+
var GOVUK = window.GOVUK
|
8
|
+
|
9
|
+
beforeEach(function (done) {
|
10
|
+
// Sample markup
|
11
|
+
this.$content = $(
|
12
|
+
'<details>' +
|
13
|
+
'<summary><span class="summary">Summary</span></summary>' +
|
14
|
+
'<div><p>Hidden content</p></div>' +
|
15
|
+
'</details>'
|
16
|
+
)
|
17
|
+
|
18
|
+
// Find elements
|
19
|
+
var $summaries = this.$content.find('summary')
|
20
|
+
var $hiddenContent = this.$content.find('div')
|
21
|
+
|
22
|
+
this.$summary1 = $summaries.eq(0)
|
23
|
+
this.$hiddenContent1 = $hiddenContent.eq(0)
|
24
|
+
|
25
|
+
// Add to page
|
26
|
+
$(document.body).append(this.$content)
|
27
|
+
|
28
|
+
setTimeout(function () {
|
29
|
+
done()
|
30
|
+
}, 1)
|
31
|
+
})
|
32
|
+
|
33
|
+
afterEach(function () {
|
34
|
+
this.detailsPolyfill = null
|
35
|
+
this.$content.remove()
|
36
|
+
})
|
37
|
+
|
38
|
+
describe('When the polyfill is initialised', function () {
|
39
|
+
beforeEach(function () {
|
40
|
+
// Initialise detailsPolyfill
|
41
|
+
this.detailsPolyfill = GOVUK.details.addDetailsPolyfill()
|
42
|
+
GOVUK.details.started = false
|
43
|
+
})
|
44
|
+
it('should add to summary the button role', function () {
|
45
|
+
expect(this.$summary1.attr('role')).toBe('button')
|
46
|
+
})
|
47
|
+
|
48
|
+
it('should set the element controlled by the summary using aria-controls', function () {
|
49
|
+
expect(this.$summary1.attr('aria-controls')).toBe('details-content-0')
|
50
|
+
})
|
51
|
+
|
52
|
+
it('should set the expanded state of the summary to false using aria-expanded', function () {
|
53
|
+
expect(this.$summary1.attr('aria-expanded')).toBe('false')
|
54
|
+
})
|
55
|
+
|
56
|
+
it('should add a unique id to the hidden content in order to be controlled by the summary', function () {
|
57
|
+
expect(this.$hiddenContent1.attr('id')).toBe('details-content-0')
|
58
|
+
})
|
59
|
+
|
60
|
+
it('should present the content as hidden using aria-hidden', function () {
|
61
|
+
expect(this.$hiddenContent1.attr('aria-hidden')).toBe('true')
|
62
|
+
})
|
63
|
+
|
64
|
+
it('should visually hide the content', function () {
|
65
|
+
expect(this.$hiddenContent1.is(':visible')).toBe(false)
|
66
|
+
})
|
67
|
+
|
68
|
+
describe('and when summary is clicked', function () {
|
69
|
+
beforeEach(function () {
|
70
|
+
// Trigger click on summary
|
71
|
+
this.$summary1.click()
|
72
|
+
})
|
73
|
+
|
74
|
+
it('should indicate the expanded state of the summary using aria-expanded', function () {
|
75
|
+
expect(this.$summary1.attr('aria-expanded')).toBe('true')
|
76
|
+
})
|
77
|
+
|
78
|
+
it('should make the content visible', function () {
|
79
|
+
expect(this.$hiddenContent1.is(':visible')).toBe(true)
|
80
|
+
})
|
81
|
+
|
82
|
+
it('should indicate the visible state of the content using aria-hidden', function () {
|
83
|
+
expect(this.$hiddenContent1.attr('aria-hidden')).toBe('false')
|
84
|
+
})
|
85
|
+
|
86
|
+
it('should indicate the open state of the content', function () {
|
87
|
+
expect(this.$content.attr('open')).toBe('open')
|
88
|
+
})
|
89
|
+
})
|
90
|
+
})
|
91
|
+
})
|
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: 7.0
|
4
|
+
version: 7.1.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: 2017-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- app/assets/javascripts/govuk/analytics/govuk-tracker.js
|
226
226
|
- app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
|
227
227
|
- app/assets/javascripts/govuk/analytics/print-intent.js
|
228
|
+
- app/assets/javascripts/govuk/details.polyfill.js
|
228
229
|
- app/assets/javascripts/govuk/modules.js
|
229
230
|
- app/assets/javascripts/govuk/modules/auto-track-event.js
|
230
231
|
- app/assets/javascripts/govuk/primary-links.js
|
@@ -251,6 +252,7 @@ files:
|
|
251
252
|
- app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js
|
252
253
|
- app/assets/spec/unit/analytics/govuk-tracker.spec.js
|
253
254
|
- app/assets/spec/unit/analytics/mailto-link-tracker.spec.js
|
255
|
+
- app/assets/spec/unit/details.polyfill.spec.js
|
254
256
|
- app/assets/spec/unit/modules.spec.js
|
255
257
|
- app/assets/spec/unit/modules/auto-track-event.spec.js
|
256
258
|
- app/assets/spec/unit/primary-links.spec.js
|
@@ -303,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
305
|
version: '0'
|
304
306
|
requirements: []
|
305
307
|
rubyforge_project:
|
306
|
-
rubygems_version: 2.
|
308
|
+
rubygems_version: 2.6.13
|
307
309
|
signing_key:
|
308
310
|
specification_version: 4
|
309
311
|
summary: Tools for building frontend applications
|