govuk_fe_assets 0.1.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/govuk_fe_assets.gemspec +26 -0
- data/lib/govuk_fe_assets.rb +5 -0
- data/lib/govuk_fe_assets/version.rb +3 -0
- data/node_modules/govuk-frontend/README.md +96 -0
- data/node_modules/govuk-frontend/all-ie8.scss +6 -0
- data/node_modules/govuk-frontend/all.js +1720 -0
- data/node_modules/govuk-frontend/all.scss +11 -0
- data/node_modules/govuk-frontend/assets/fonts/bold-a2452cb66f-v1.woff2 +0 -0
- data/node_modules/govuk-frontend/assets/fonts/bold-f38c792ac2-v1.woff +0 -0
- data/node_modules/govuk-frontend/assets/fonts/bold-fb2676462a-v1.eot +0 -0
- data/node_modules/govuk-frontend/assets/fonts/bold-tabular-357fdfbcc3-v1.eot +0 -0
- data/node_modules/govuk-frontend/assets/fonts/bold-tabular-784c21afb8-v1.woff +0 -0
- data/node_modules/govuk-frontend/assets/fonts/bold-tabular-b89238d840-v1.woff2 +0 -0
- data/node_modules/govuk-frontend/assets/fonts/light-2c037cf7e1-v1.eot +0 -0
- data/node_modules/govuk-frontend/assets/fonts/light-458f8ea81c-v1.woff +0 -0
- data/node_modules/govuk-frontend/assets/fonts/light-f38ad40456-v1.woff2 +0 -0
- data/node_modules/govuk-frontend/assets/fonts/light-tabular-498ea8ffe2-v1.eot +0 -0
- data/node_modules/govuk-frontend/assets/fonts/light-tabular-62cc6f0a28-v1.woff +0 -0
- data/node_modules/govuk-frontend/assets/fonts/light-tabular-851b10ccdd-v1.woff2 +0 -0
- data/node_modules/govuk-frontend/assets/images/favicon.ico +0 -0
- data/node_modules/govuk-frontend/assets/images/govuk-apple-touch-icon-152x152.png +0 -0
- data/node_modules/govuk-frontend/assets/images/govuk-apple-touch-icon-167x167.png +0 -0
- data/node_modules/govuk-frontend/assets/images/govuk-apple-touch-icon-180x180.png +0 -0
- data/node_modules/govuk-frontend/assets/images/govuk-apple-touch-icon.png +0 -0
- data/node_modules/govuk-frontend/assets/images/govuk-crest-2x.png +0 -0
- data/node_modules/govuk-frontend/assets/images/govuk-crest.png +0 -0
- data/node_modules/govuk-frontend/assets/images/govuk-logotype-crown.png +0 -0
- data/node_modules/govuk-frontend/assets/images/govuk-mask-icon.svg +7 -0
- data/node_modules/govuk-frontend/assets/images/govuk-opengraph-image.png +0 -0
- data/node_modules/govuk-frontend/assets/images/icon-arrow-left.png +0 -0
- data/node_modules/govuk-frontend/assets/images/icon-important.png +0 -0
- data/node_modules/govuk-frontend/assets/images/icon-pointer-2x.png +0 -0
- data/node_modules/govuk-frontend/assets/images/icon-pointer.png +0 -0
- data/node_modules/govuk-frontend/common.js +39 -0
- data/node_modules/govuk-frontend/components/_all.scss +26 -0
- data/node_modules/govuk-frontend/components/back-link/README.md +142 -0
- data/node_modules/govuk-frontend/components/back-link/_back-link.scss +54 -0
- data/node_modules/govuk-frontend/components/back-link/back-link.njk +3 -0
- data/node_modules/govuk-frontend/components/back-link/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/back-link/template.njk +2 -0
- data/node_modules/govuk-frontend/components/breadcrumbs/README.md +335 -0
- data/node_modules/govuk-frontend/components/breadcrumbs/_breadcrumbs.scss +119 -0
- data/node_modules/govuk-frontend/components/breadcrumbs/breadcrumbs.njk +14 -0
- data/node_modules/govuk-frontend/components/breadcrumbs/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/breadcrumbs/template.njk +13 -0
- data/node_modules/govuk-frontend/components/button/README.md +319 -0
- data/node_modules/govuk-frontend/components/button/_button.scss +185 -0
- data/node_modules/govuk-frontend/components/button/button.js +548 -0
- data/node_modules/govuk-frontend/components/button/button.njk +3 -0
- data/node_modules/govuk-frontend/components/button/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/button/template.njk +35 -0
- data/node_modules/govuk-frontend/components/checkboxes/README.md +782 -0
- data/node_modules/govuk-frontend/components/checkboxes/_checkboxes.scss +151 -0
- data/node_modules/govuk-frontend/components/checkboxes/checkboxes.js +730 -0
- data/node_modules/govuk-frontend/components/checkboxes/checkboxes.njk +27 -0
- data/node_modules/govuk-frontend/components/checkboxes/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/checkboxes/template.njk +86 -0
- data/node_modules/govuk-frontend/components/date-input/README.md +640 -0
- data/node_modules/govuk-frontend/components/date-input/_date-input.scss +35 -0
- data/node_modules/govuk-frontend/components/date-input/date-input.njk +23 -0
- data/node_modules/govuk-frontend/components/date-input/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/date-input/template.njk +76 -0
- data/node_modules/govuk-frontend/components/details/README.md +237 -0
- data/node_modules/govuk-frontend/components/details/_details.scss +86 -0
- data/node_modules/govuk-frontend/components/details/details.js +836 -0
- data/node_modules/govuk-frontend/components/details/details.njk +7 -0
- data/node_modules/govuk-frontend/components/details/implementation.md +43 -0
- data/node_modules/govuk-frontend/components/details/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/details/template.njk +10 -0
- data/node_modules/govuk-frontend/components/error-message/README.md +143 -0
- data/node_modules/govuk-frontend/components/error-message/_error-message.scss +15 -0
- data/node_modules/govuk-frontend/components/error-message/error-message.njk +7 -0
- data/node_modules/govuk-frontend/components/error-message/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/error-message/template.njk +3 -0
- data/node_modules/govuk-frontend/components/error-summary/README.md +215 -0
- data/node_modules/govuk-frontend/components/error-summary/_error-summary.scss +68 -0
- data/node_modules/govuk-frontend/components/error-summary/error-summary.js +520 -0
- data/node_modules/govuk-frontend/components/error-summary/error-summary.njk +17 -0
- data/node_modules/govuk-frontend/components/error-summary/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/error-summary/template.njk +25 -0
- data/node_modules/govuk-frontend/components/fieldset/README.md +213 -0
- data/node_modules/govuk-frontend/components/fieldset/_fieldset.scss +58 -0
- data/node_modules/govuk-frontend/components/fieldset/fieldset.njk +13 -0
- data/node_modules/govuk-frontend/components/fieldset/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/fieldset/template.njk +17 -0
- data/node_modules/govuk-frontend/components/file-upload/README.md +332 -0
- data/node_modules/govuk-frontend/components/file-upload/_file-upload.scss +19 -0
- data/node_modules/govuk-frontend/components/file-upload/file-upload.njk +9 -0
- data/node_modules/govuk-frontend/components/file-upload/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/file-upload/template.njk +42 -0
- data/node_modules/govuk-frontend/components/footer/README.md +284 -0
- data/node_modules/govuk-frontend/components/footer/_footer.scss +216 -0
- data/node_modules/govuk-frontend/components/footer/footer.njk +3 -0
- data/node_modules/govuk-frontend/components/footer/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/footer/template.njk +80 -0
- data/node_modules/govuk-frontend/components/header/README.md +524 -0
- data/node_modules/govuk-frontend/components/header/_header.scss +285 -0
- data/node_modules/govuk-frontend/components/header/header.js +717 -0
- data/node_modules/govuk-frontend/components/header/header.njk +3 -0
- data/node_modules/govuk-frontend/components/header/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/header/template.njk +82 -0
- data/node_modules/govuk-frontend/components/hint/README.md +157 -0
- data/node_modules/govuk-frontend/components/hint/_hint.scss +29 -0
- data/node_modules/govuk-frontend/components/hint/hint.njk +7 -0
- data/node_modules/govuk-frontend/components/hint/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/hint/template.njk +4 -0
- data/node_modules/govuk-frontend/components/input/README.md +416 -0
- data/node_modules/govuk-frontend/components/input/_input.scss +62 -0
- data/node_modules/govuk-frontend/components/input/input.njk +9 -0
- data/node_modules/govuk-frontend/components/input/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/input/template.njk +42 -0
- data/node_modules/govuk-frontend/components/inset-text/README.md +157 -0
- data/node_modules/govuk-frontend/components/inset-text/_inset-text.scss +28 -0
- data/node_modules/govuk-frontend/components/inset-text/inset-text.njk +7 -0
- data/node_modules/govuk-frontend/components/inset-text/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/inset-text/template.njk +4 -0
- data/node_modules/govuk-frontend/components/label/README.md +193 -0
- data/node_modules/govuk-frontend/components/label/_label.scss +45 -0
- data/node_modules/govuk-frontend/components/label/label.njk +6 -0
- data/node_modules/govuk-frontend/components/label/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/label/template.njk +15 -0
- data/node_modules/govuk-frontend/components/panel/README.md +151 -0
- data/node_modules/govuk-frontend/components/panel/_panel.scss +42 -0
- data/node_modules/govuk-frontend/components/panel/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/panel/panel.njk +7 -0
- data/node_modules/govuk-frontend/components/panel/template.njk +12 -0
- data/node_modules/govuk-frontend/components/phase-banner/README.md +152 -0
- data/node_modules/govuk-frontend/components/phase-banner/_phase-banner.scss +31 -0
- data/node_modules/govuk-frontend/components/phase-banner/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/phase-banner/phase-banner.njk +7 -0
- data/node_modules/govuk-frontend/components/phase-banner/template.njk +17 -0
- data/node_modules/govuk-frontend/components/radios/README.md +686 -0
- data/node_modules/govuk-frontend/components/radios/_radios.scss +157 -0
- data/node_modules/govuk-frontend/components/radios/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/radios/radios.js +730 -0
- data/node_modules/govuk-frontend/components/radios/radios.njk +27 -0
- data/node_modules/govuk-frontend/components/radios/template.njk +85 -0
- data/node_modules/govuk-frontend/components/select/README.md +387 -0
- data/node_modules/govuk-frontend/components/select/_select.scss +35 -0
- data/node_modules/govuk-frontend/components/select/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/select/select.njk +24 -0
- data/node_modules/govuk-frontend/components/select/template.njk +44 -0
- data/node_modules/govuk-frontend/components/skip-link/README.md +142 -0
- data/node_modules/govuk-frontend/components/skip-link/_skip-link.scss +15 -0
- data/node_modules/govuk-frontend/components/skip-link/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/skip-link/skip-link.njk +3 -0
- data/node_modules/govuk-frontend/components/skip-link/template.njk +3 -0
- data/node_modules/govuk-frontend/components/table/README.md +585 -0
- data/node_modules/govuk-frontend/components/table/_table.scss +50 -0
- data/node_modules/govuk-frontend/components/table/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/table/table.njk +45 -0
- data/node_modules/govuk-frontend/components/table/template.njk +39 -0
- data/node_modules/govuk-frontend/components/tabs/README.md +375 -0
- data/node_modules/govuk-frontend/components/tabs/_tabs.scss +120 -0
- data/node_modules/govuk-frontend/components/tabs/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/tabs/tabs.js +1302 -0
- data/node_modules/govuk-frontend/components/tabs/tabs.njk +3 -0
- data/node_modules/govuk-frontend/components/tabs/template.njk +29 -0
- data/node_modules/govuk-frontend/components/tag/README.md +150 -0
- data/node_modules/govuk-frontend/components/tag/_tag.scss +23 -0
- data/node_modules/govuk-frontend/components/tag/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/tag/tag.njk +7 -0
- data/node_modules/govuk-frontend/components/tag/template.njk +3 -0
- data/node_modules/govuk-frontend/components/textarea/README.md +350 -0
- data/node_modules/govuk-frontend/components/textarea/_textarea.scss +31 -0
- data/node_modules/govuk-frontend/components/textarea/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/textarea/template.njk +41 -0
- data/node_modules/govuk-frontend/components/textarea/textarea.njk +11 -0
- data/node_modules/govuk-frontend/components/warning-text/README.md +148 -0
- data/node_modules/govuk-frontend/components/warning-text/_warning-text.scss +50 -0
- data/node_modules/govuk-frontend/components/warning-text/macro.njk +3 -0
- data/node_modules/govuk-frontend/components/warning-text/template.njk +9 -0
- data/node_modules/govuk-frontend/components/warning-text/warning-text.njk +9 -0
- data/node_modules/govuk-frontend/core/_all.scss +6 -0
- data/node_modules/govuk-frontend/core/_global-styles.scss +19 -0
- data/node_modules/govuk-frontend/core/_links.scss +40 -0
- data/node_modules/govuk-frontend/core/_lists.scss +63 -0
- data/node_modules/govuk-frontend/core/_section-break.scss +56 -0
- data/node_modules/govuk-frontend/core/_template.scss +16 -0
- data/node_modules/govuk-frontend/core/_typography.scss +186 -0
- data/node_modules/govuk-frontend/helpers/_all.scss +12 -0
- data/node_modules/govuk-frontend/helpers/_clearfix.scss +15 -0
- data/node_modules/govuk-frontend/helpers/_colour.scss +51 -0
- data/node_modules/govuk-frontend/helpers/_device-pixels.scss +38 -0
- data/node_modules/govuk-frontend/helpers/_focusable.scss +34 -0
- data/node_modules/govuk-frontend/helpers/_font-faces.scss +67 -0
- data/node_modules/govuk-frontend/helpers/_grid.scss +100 -0
- data/node_modules/govuk-frontend/helpers/_links.scss +149 -0
- data/node_modules/govuk-frontend/helpers/_media-queries.scss +95 -0
- data/node_modules/govuk-frontend/helpers/_shape-arrow.scss +80 -0
- data/node_modules/govuk-frontend/helpers/_spacing.scss +152 -0
- data/node_modules/govuk-frontend/helpers/_typography.scss +153 -0
- data/node_modules/govuk-frontend/helpers/_visually-hidden.scss +76 -0
- data/node_modules/govuk-frontend/objects/_all.scss +4 -0
- data/node_modules/govuk-frontend/objects/_form-group.scss +21 -0
- data/node_modules/govuk-frontend/objects/_grid.scss +10 -0
- data/node_modules/govuk-frontend/objects/_main-wrapper.scss +37 -0
- data/node_modules/govuk-frontend/objects/_width-container.scss +28 -0
- data/node_modules/govuk-frontend/overrides/_all.scss +4 -0
- data/node_modules/govuk-frontend/overrides/_display.scss +14 -0
- data/node_modules/govuk-frontend/overrides/_spacing.scss +58 -0
- data/node_modules/govuk-frontend/overrides/_typography.scss +21 -0
- data/node_modules/govuk-frontend/overrides/_width.scss +41 -0
- data/node_modules/govuk-frontend/package.json +50 -0
- data/node_modules/govuk-frontend/settings/_all.scss +21 -0
- data/node_modules/govuk-frontend/settings/_assets.scss +82 -0
- data/node_modules/govuk-frontend/settings/_colours-applied.scss +130 -0
- data/node_modules/govuk-frontend/settings/_colours-organisations.scss +136 -0
- data/node_modules/govuk-frontend/settings/_colours-palette.scss +37 -0
- data/node_modules/govuk-frontend/settings/_compatibility.scss +51 -0
- data/node_modules/govuk-frontend/settings/_global-styles.scss +13 -0
- data/node_modules/govuk-frontend/settings/_ie8.scss +18 -0
- data/node_modules/govuk-frontend/settings/_measurements.scss +85 -0
- data/node_modules/govuk-frontend/settings/_media-queries.scss +23 -0
- data/node_modules/govuk-frontend/settings/_spacing.scss +80 -0
- data/node_modules/govuk-frontend/settings/_typography-font-families.scss +22 -0
- data/node_modules/govuk-frontend/settings/_typography-font.scss +48 -0
- data/node_modules/govuk-frontend/settings/_typography-responsive.scss +138 -0
- data/node_modules/govuk-frontend/template.njk +56 -0
- data/node_modules/govuk-frontend/tools/_all.scss +7 -0
- data/node_modules/govuk-frontend/tools/_compatibility.scss +36 -0
- data/node_modules/govuk-frontend/tools/_exports.scss +33 -0
- data/node_modules/govuk-frontend/tools/_font-url.scss +28 -0
- data/node_modules/govuk-frontend/tools/_ie8.scss +51 -0
- data/node_modules/govuk-frontend/tools/_iff.scss +15 -0
- data/node_modules/govuk-frontend/tools/_image-url.scss +28 -0
- data/node_modules/govuk-frontend/tools/_px-to-em.scss +20 -0
- data/node_modules/govuk-frontend/utilities/_all.scss +2 -0
- data/node_modules/govuk-frontend/utilities/_clearfix.scss +5 -0
- data/node_modules/govuk-frontend/utilities/_visually-hidden.scss +9 -0
- data/node_modules/govuk-frontend/vendor/_sass-mq.scss +351 -0
- data/node_modules/govuk-frontend/vendor/polyfills/DOMTokenList.js +272 -0
- data/node_modules/govuk-frontend/vendor/polyfills/Document.js +34 -0
- data/node_modules/govuk-frontend/vendor/polyfills/Element.js +147 -0
- data/node_modules/govuk-frontend/vendor/polyfills/Element/prototype/classList.js +449 -0
- data/node_modules/govuk-frontend/vendor/polyfills/Event.js +504 -0
- data/node_modules/govuk-frontend/vendor/polyfills/Function/prototype/bind.js +252 -0
- data/node_modules/govuk-frontend/vendor/polyfills/Object/defineProperty.js +94 -0
- data/node_modules/govuk-frontend/vendor/polyfills/Window.js +28 -0
- data/package-lock.json +10 -0
- data/package.json +5 -0
- metadata +334 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9de41385cb47d0fa1164b2b54d1989de277d4e92
|
4
|
+
data.tar.gz: f8d16455304b07fd11b98a619cc6240117079baf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd0550ad05a62a77678b980cc7b445670ecf53b388041e6ed923cc35137c3ea75e43e02b12fb0ed7072b73026fb730ea8eb49134292b5112507dd5c7f08b26f0
|
7
|
+
data.tar.gz: 83215505fbd0e2317a67c99102ca4c92ee10084136e77810e44eab03b0ab2aa61c9159160143dfd7d440403e819eab5ed674cd76c9b8e75d53c39df697c0c367
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Tijmen Brommet
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# GovukFeAssets
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/govuk_fe_assets`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'govuk_fe_assets'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install govuk_fe_assets
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tijmenb/govuk_fe_assets.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "govuk_fe_assets/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "govuk_fe_assets"
|
8
|
+
spec.version = GovukFeAssets::VERSION
|
9
|
+
spec.authors = ["Tijmen Brommet"]
|
10
|
+
spec.email = ["tijmen@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{FE asssets - do not use this gem}
|
13
|
+
spec.description = %q{FE asssets - do not use this gem}
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# GOV.UK Frontend
|
2
|
+
|
3
|
+
GOV.UK Frontend contains the code you need to start building a user interface
|
4
|
+
for government platforms and services.
|
5
|
+
|
6
|
+
See live examples of GOV.UK Frontend components, and guidance on when to use
|
7
|
+
them in your service, in the [GOV.UK Design System](https://www.gov.uk/design-system).
|
8
|
+
|
9
|
+
## Contact the team
|
10
|
+
|
11
|
+
GOV.UK Frontend is maintained by a team at Government Digital Service. If you want to know more about GOV.UK Frontend, please email the [Design System
|
12
|
+
team](mailto:govuk-design-system-support@digital.cabinet-office.gov.uk) or get in touch with them on [Slack](https://ukgovernmentdigital.slack.com/messages/govuk-design-system).
|
13
|
+
|
14
|
+
## Quick start
|
15
|
+
|
16
|
+
There are 2 ways to start using GOV.UK Frontend in your app.
|
17
|
+
|
18
|
+
Once installed, you will be able to use the code from the examples in the
|
19
|
+
[GOV.UK Design System](https://www.gov.uk/design-system in your service.
|
20
|
+
|
21
|
+
### 1. Install with npm (recommended)
|
22
|
+
|
23
|
+
We recommend [installing GOV.UK Frontend using node package manager
|
24
|
+
(npm)](https://github.com/alphagov/govuk-frontend/blob/master/docs/installation/installing-with-npm.md).
|
25
|
+
|
26
|
+
### 2. Install by using compiled files
|
27
|
+
|
28
|
+
You can also [download the compiled and minified assets (CSS, JavaScript) from
|
29
|
+
GitHub](https://github.com/alphagov/govuk-frontend/blob/master/docs/installation/installing-from-dist.md).
|
30
|
+
|
31
|
+
## Importing styles
|
32
|
+
|
33
|
+
You need to import the GOV.UK Frontend styles into the main Sass file in your
|
34
|
+
project. You should place the below code before your own Sass rules (or Sass
|
35
|
+
imports) if you want to override GOV.UK Frontend with your own styles.
|
36
|
+
|
37
|
+
To import add the below to your Sass file:
|
38
|
+
|
39
|
+
```scss
|
40
|
+
@import "node_modules/govuk-frontend/all";
|
41
|
+
```
|
42
|
+
|
43
|
+
[More details on importing styles](https://github.com/alphagov/govuk-frontend/blob/master/docs/installation/installing-with-npm.md#importing-styles)
|
44
|
+
|
45
|
+
## Importing JavaScript
|
46
|
+
|
47
|
+
Some of the JavaScript included in GOV.UK Frontend improves the usability and
|
48
|
+
accessibility of the components. You should make sure that you are importing and
|
49
|
+
initialising Javascript in your application to ensure that all users can use it successfully.
|
50
|
+
|
51
|
+
You can include Javascript for all components either by copying the `all.js` from `node_modules/govuk-frontend` into your application or referencing the file directly:
|
52
|
+
|
53
|
+
```html
|
54
|
+
<script src="<path-to-govuk-frontend-all-file>/all.js"></script>
|
55
|
+
```
|
56
|
+
Next you need to initialise the script by adding:
|
57
|
+
|
58
|
+
```html
|
59
|
+
<script>window.GOVUKFrontend.initAll()</script>
|
60
|
+
```
|
61
|
+
|
62
|
+
[More details on importing Javascript and advanced options](https://github.com/alphagov/govuk-frontend/blob/master/docs/installation/installing-with-npm.md#importing-javascript)
|
63
|
+
|
64
|
+
|
65
|
+
## Importing assets
|
66
|
+
|
67
|
+
In order to import GOV.UK Frontend images and fonts to your project, you should configure your application to reference or copy the relevant GOV.UK Frontend assets.
|
68
|
+
|
69
|
+
[More details on importing assets](https://github.com/alphagov/govuk-frontend/blob/master/docs/installation/installing-with-npm.md#import-assets)
|
70
|
+
|
71
|
+
|
72
|
+
## Getting updates
|
73
|
+
|
74
|
+
To check whether you have the latest version of GOV.UK Frontend, run:
|
75
|
+
|
76
|
+
```
|
77
|
+
npm outdated govuk-frontend
|
78
|
+
```
|
79
|
+
|
80
|
+
To update to the latest version, run:
|
81
|
+
|
82
|
+
```
|
83
|
+
npm update govuk-frontend
|
84
|
+
```
|
85
|
+
|
86
|
+
## Licence
|
87
|
+
|
88
|
+
Unless stated otherwise, the codebase is released under the MIT License. This
|
89
|
+
covers both the codebase and any sample code in the documentation. The
|
90
|
+
documentation is © Crown copyright and available under the terms of the
|
91
|
+
Open Government 3.0 licence.
|
92
|
+
|
93
|
+
## Contribution guidelines
|
94
|
+
|
95
|
+
If you want to help us build GOV.UK Frontend, view our [contribution
|
96
|
+
guidelines](https://github.com/alphagov/govuk-frontend/blob/master/CONTRIBUTING.md).
|
@@ -0,0 +1,1720 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3
|
+
typeof define === 'function' && define.amd ? define('GOVUKFrontend', ['exports'], factory) :
|
4
|
+
(factory((global.GOVUKFrontend = {})));
|
5
|
+
}(this, (function (exports) { 'use strict';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* TODO: Ideally this would be a NodeList.prototype.forEach polyfill
|
9
|
+
* This seems to fail in IE8, requires more investigation.
|
10
|
+
* See: https://github.com/imagitama/nodelist-foreach-polyfill
|
11
|
+
*/
|
12
|
+
function nodeListForEach (nodes, callback) {
|
13
|
+
if (window.NodeList.prototype.forEach) {
|
14
|
+
return nodes.forEach(callback)
|
15
|
+
}
|
16
|
+
for (var i = 0; i < nodes.length; i++) {
|
17
|
+
callback.call(window, nodes[i], i, nodes);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
// Used to generate a unique string, allows multiple instances of the component without
|
22
|
+
// Them conflicting with each other.
|
23
|
+
// https://stackoverflow.com/a/8809472
|
24
|
+
function generateUniqueID () {
|
25
|
+
var d = new Date().getTime();
|
26
|
+
if (typeof window.performance !== 'undefined' && typeof window.performance.now === 'function') {
|
27
|
+
d += window.performance.now(); // use high-precision timer if available
|
28
|
+
}
|
29
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
30
|
+
var r = (d + Math.random() * 16) % 16 | 0;
|
31
|
+
d = Math.floor(d / 16);
|
32
|
+
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
|
33
|
+
})
|
34
|
+
}
|
35
|
+
|
36
|
+
(function(undefined) {
|
37
|
+
|
38
|
+
// Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
|
39
|
+
var detect = ('Window' in this);
|
40
|
+
|
41
|
+
if (detect) return
|
42
|
+
|
43
|
+
// Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
|
44
|
+
if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
|
45
|
+
(function (global) {
|
46
|
+
if (global.constructor) {
|
47
|
+
global.Window = global.constructor;
|
48
|
+
} else {
|
49
|
+
(global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
|
50
|
+
}
|
51
|
+
}(this));
|
52
|
+
}
|
53
|
+
|
54
|
+
})
|
55
|
+
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
56
|
+
|
57
|
+
(function(undefined) {
|
58
|
+
|
59
|
+
// Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
|
60
|
+
var detect = ("Document" in this);
|
61
|
+
|
62
|
+
if (detect) return
|
63
|
+
|
64
|
+
// Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
|
65
|
+
if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
|
66
|
+
|
67
|
+
if (this.HTMLDocument) { // IE8
|
68
|
+
|
69
|
+
// HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
|
70
|
+
this.Document = this.HTMLDocument;
|
71
|
+
|
72
|
+
} else {
|
73
|
+
|
74
|
+
// Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made.
|
75
|
+
this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
|
76
|
+
this.Document.prototype = document;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
})
|
82
|
+
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
83
|
+
|
84
|
+
(function(undefined) {
|
85
|
+
|
86
|
+
// Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
|
87
|
+
var detect = ('Element' in this && 'HTMLElement' in this);
|
88
|
+
|
89
|
+
if (detect) return
|
90
|
+
|
91
|
+
// Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
|
92
|
+
(function () {
|
93
|
+
|
94
|
+
// IE8
|
95
|
+
if (window.Element && !window.HTMLElement) {
|
96
|
+
window.HTMLElement = window.Element;
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
|
100
|
+
// create Element constructor
|
101
|
+
window.Element = window.HTMLElement = new Function('return function Element() {}')();
|
102
|
+
|
103
|
+
// generate sandboxed iframe
|
104
|
+
var vbody = document.appendChild(document.createElement('body'));
|
105
|
+
var frame = vbody.appendChild(document.createElement('iframe'));
|
106
|
+
|
107
|
+
// use sandboxed iframe to replicate Element functionality
|
108
|
+
var frameDocument = frame.contentWindow.document;
|
109
|
+
var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
|
110
|
+
var cache = {};
|
111
|
+
|
112
|
+
// polyfill Element.prototype on an element
|
113
|
+
var shiv = function (element, deep) {
|
114
|
+
var
|
115
|
+
childNodes = element.childNodes || [],
|
116
|
+
index = -1,
|
117
|
+
key, value, childNode;
|
118
|
+
|
119
|
+
if (element.nodeType === 1 && element.constructor !== Element) {
|
120
|
+
element.constructor = Element;
|
121
|
+
|
122
|
+
for (key in cache) {
|
123
|
+
value = cache[key];
|
124
|
+
element[key] = value;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
while (childNode = deep && childNodes[++index]) {
|
129
|
+
shiv(childNode, deep);
|
130
|
+
}
|
131
|
+
|
132
|
+
return element;
|
133
|
+
};
|
134
|
+
|
135
|
+
var elements = document.getElementsByTagName('*');
|
136
|
+
var nativeCreateElement = document.createElement;
|
137
|
+
var interval;
|
138
|
+
var loopLimit = 100;
|
139
|
+
|
140
|
+
prototype.attachEvent('onpropertychange', function (event) {
|
141
|
+
var
|
142
|
+
propertyName = event.propertyName,
|
143
|
+
nonValue = !cache.hasOwnProperty(propertyName),
|
144
|
+
newValue = prototype[propertyName],
|
145
|
+
oldValue = cache[propertyName],
|
146
|
+
index = -1,
|
147
|
+
element;
|
148
|
+
|
149
|
+
while (element = elements[++index]) {
|
150
|
+
if (element.nodeType === 1) {
|
151
|
+
if (nonValue || element[propertyName] === oldValue) {
|
152
|
+
element[propertyName] = newValue;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
cache[propertyName] = newValue;
|
158
|
+
});
|
159
|
+
|
160
|
+
prototype.constructor = Element;
|
161
|
+
|
162
|
+
if (!prototype.hasAttribute) {
|
163
|
+
// <Element>.hasAttribute
|
164
|
+
prototype.hasAttribute = function hasAttribute(name) {
|
165
|
+
return this.getAttribute(name) !== null;
|
166
|
+
};
|
167
|
+
}
|
168
|
+
|
169
|
+
// Apply Element prototype to the pre-existing DOM as soon as the body element appears.
|
170
|
+
function bodyCheck() {
|
171
|
+
if (!(loopLimit--)) clearTimeout(interval);
|
172
|
+
if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
|
173
|
+
shiv(document, true);
|
174
|
+
if (interval && document.body.prototype) clearTimeout(interval);
|
175
|
+
return (!!document.body.prototype);
|
176
|
+
}
|
177
|
+
return false;
|
178
|
+
}
|
179
|
+
if (!bodyCheck()) {
|
180
|
+
document.onreadystatechange = bodyCheck;
|
181
|
+
interval = setInterval(bodyCheck, 25);
|
182
|
+
}
|
183
|
+
|
184
|
+
// Apply to any new elements created after load
|
185
|
+
document.createElement = function createElement(nodeName) {
|
186
|
+
var element = nativeCreateElement(String(nodeName).toLowerCase());
|
187
|
+
return shiv(element);
|
188
|
+
};
|
189
|
+
|
190
|
+
// remove sandboxed iframe
|
191
|
+
document.removeChild(vbody);
|
192
|
+
}());
|
193
|
+
|
194
|
+
})
|
195
|
+
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
196
|
+
|
197
|
+
(function(undefined) {
|
198
|
+
|
199
|
+
// Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
|
200
|
+
var detect = (
|
201
|
+
// In IE8, defineProperty could only act on DOM elements, so full support
|
202
|
+
// for the feature requires the ability to set a property on an arbitrary object
|
203
|
+
'defineProperty' in Object && (function() {
|
204
|
+
try {
|
205
|
+
var a = {};
|
206
|
+
Object.defineProperty(a, 'test', {value:42});
|
207
|
+
return true;
|
208
|
+
} catch(e) {
|
209
|
+
return false
|
210
|
+
}
|
211
|
+
}())
|
212
|
+
);
|
213
|
+
|
214
|
+
if (detect) return
|
215
|
+
|
216
|
+
// Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
|
217
|
+
(function (nativeDefineProperty) {
|
218
|
+
|
219
|
+
var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
|
220
|
+
var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
|
221
|
+
var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
|
222
|
+
|
223
|
+
Object.defineProperty = function defineProperty(object, property, descriptor) {
|
224
|
+
|
225
|
+
// Where native support exists, assume it
|
226
|
+
if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
|
227
|
+
return nativeDefineProperty(object, property, descriptor);
|
228
|
+
}
|
229
|
+
|
230
|
+
if (object === null || !(object instanceof Object || typeof object === 'object')) {
|
231
|
+
throw new TypeError('Object.defineProperty called on non-object');
|
232
|
+
}
|
233
|
+
|
234
|
+
if (!(descriptor instanceof Object)) {
|
235
|
+
throw new TypeError('Property description must be an object');
|
236
|
+
}
|
237
|
+
|
238
|
+
var propertyString = String(property);
|
239
|
+
var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
|
240
|
+
var getterType = 'get' in descriptor && typeof descriptor.get;
|
241
|
+
var setterType = 'set' in descriptor && typeof descriptor.set;
|
242
|
+
|
243
|
+
// handle descriptor.get
|
244
|
+
if (getterType) {
|
245
|
+
if (getterType !== 'function') {
|
246
|
+
throw new TypeError('Getter must be a function');
|
247
|
+
}
|
248
|
+
if (!supportsAccessors) {
|
249
|
+
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
250
|
+
}
|
251
|
+
if (hasValueOrWritable) {
|
252
|
+
throw new TypeError(ERR_VALUE_ACCESSORS);
|
253
|
+
}
|
254
|
+
Object.__defineGetter__.call(object, propertyString, descriptor.get);
|
255
|
+
} else {
|
256
|
+
object[propertyString] = descriptor.value;
|
257
|
+
}
|
258
|
+
|
259
|
+
// handle descriptor.set
|
260
|
+
if (setterType) {
|
261
|
+
if (setterType !== 'function') {
|
262
|
+
throw new TypeError('Setter must be a function');
|
263
|
+
}
|
264
|
+
if (!supportsAccessors) {
|
265
|
+
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
266
|
+
}
|
267
|
+
if (hasValueOrWritable) {
|
268
|
+
throw new TypeError(ERR_VALUE_ACCESSORS);
|
269
|
+
}
|
270
|
+
Object.__defineSetter__.call(object, propertyString, descriptor.set);
|
271
|
+
}
|
272
|
+
|
273
|
+
// OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
|
274
|
+
if ('value' in descriptor) {
|
275
|
+
object[propertyString] = descriptor.value;
|
276
|
+
}
|
277
|
+
|
278
|
+
return object;
|
279
|
+
};
|
280
|
+
}(Object.defineProperty));
|
281
|
+
})
|
282
|
+
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
283
|
+
|
284
|
+
(function(undefined) {
|
285
|
+
|
286
|
+
// Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
|
287
|
+
var detect = (
|
288
|
+
(function(global) {
|
289
|
+
|
290
|
+
if (!('Event' in global)) return false;
|
291
|
+
if (typeof global.Event === 'function') return true;
|
292
|
+
|
293
|
+
try {
|
294
|
+
|
295
|
+
// In IE 9-11, the Event object exists but cannot be instantiated
|
296
|
+
new Event('click');
|
297
|
+
return true;
|
298
|
+
} catch(e) {
|
299
|
+
return false;
|
300
|
+
}
|
301
|
+
}(this))
|
302
|
+
);
|
303
|
+
|
304
|
+
if (detect) return
|
305
|
+
|
306
|
+
// Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
|
307
|
+
(function () {
|
308
|
+
var unlistenableWindowEvents = {
|
309
|
+
click: 1,
|
310
|
+
dblclick: 1,
|
311
|
+
keyup: 1,
|
312
|
+
keypress: 1,
|
313
|
+
keydown: 1,
|
314
|
+
mousedown: 1,
|
315
|
+
mouseup: 1,
|
316
|
+
mousemove: 1,
|
317
|
+
mouseover: 1,
|
318
|
+
mouseenter: 1,
|
319
|
+
mouseleave: 1,
|
320
|
+
mouseout: 1,
|
321
|
+
storage: 1,
|
322
|
+
storagecommit: 1,
|
323
|
+
textinput: 1
|
324
|
+
};
|
325
|
+
|
326
|
+
// This polyfill depends on availability of `document` so will not run in a worker
|
327
|
+
// However, we asssume there are no browsers with worker support that lack proper
|
328
|
+
// support for `Event` within the worker
|
329
|
+
if (typeof document === 'undefined' || typeof window === 'undefined') return;
|
330
|
+
|
331
|
+
function indexOf(array, element) {
|
332
|
+
var
|
333
|
+
index = -1,
|
334
|
+
length = array.length;
|
335
|
+
|
336
|
+
while (++index < length) {
|
337
|
+
if (index in array && array[index] === element) {
|
338
|
+
return index;
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
342
|
+
return -1;
|
343
|
+
}
|
344
|
+
|
345
|
+
var existingProto = (window.Event && window.Event.prototype) || null;
|
346
|
+
window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
|
347
|
+
if (!type) {
|
348
|
+
throw new Error('Not enough arguments');
|
349
|
+
}
|
350
|
+
|
351
|
+
var event;
|
352
|
+
// Shortcut if browser supports createEvent
|
353
|
+
if ('createEvent' in document) {
|
354
|
+
event = document.createEvent('Event');
|
355
|
+
var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
|
356
|
+
var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
|
357
|
+
|
358
|
+
event.initEvent(type, bubbles, cancelable);
|
359
|
+
|
360
|
+
return event;
|
361
|
+
}
|
362
|
+
|
363
|
+
event = document.createEventObject();
|
364
|
+
|
365
|
+
event.type = type;
|
366
|
+
event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
|
367
|
+
event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
|
368
|
+
|
369
|
+
return event;
|
370
|
+
};
|
371
|
+
if (existingProto) {
|
372
|
+
Object.defineProperty(window.Event, 'prototype', {
|
373
|
+
configurable: false,
|
374
|
+
enumerable: false,
|
375
|
+
writable: true,
|
376
|
+
value: existingProto
|
377
|
+
});
|
378
|
+
}
|
379
|
+
|
380
|
+
if (!('createEvent' in document)) {
|
381
|
+
window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
|
382
|
+
var
|
383
|
+
element = this,
|
384
|
+
type = arguments[0],
|
385
|
+
listener = arguments[1];
|
386
|
+
|
387
|
+
if (element === window && type in unlistenableWindowEvents) {
|
388
|
+
throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.');
|
389
|
+
}
|
390
|
+
|
391
|
+
if (!element._events) {
|
392
|
+
element._events = {};
|
393
|
+
}
|
394
|
+
|
395
|
+
if (!element._events[type]) {
|
396
|
+
element._events[type] = function (event) {
|
397
|
+
var
|
398
|
+
list = element._events[event.type].list,
|
399
|
+
events = list.slice(),
|
400
|
+
index = -1,
|
401
|
+
length = events.length,
|
402
|
+
eventElement;
|
403
|
+
|
404
|
+
event.preventDefault = function preventDefault() {
|
405
|
+
if (event.cancelable !== false) {
|
406
|
+
event.returnValue = false;
|
407
|
+
}
|
408
|
+
};
|
409
|
+
|
410
|
+
event.stopPropagation = function stopPropagation() {
|
411
|
+
event.cancelBubble = true;
|
412
|
+
};
|
413
|
+
|
414
|
+
event.stopImmediatePropagation = function stopImmediatePropagation() {
|
415
|
+
event.cancelBubble = true;
|
416
|
+
event.cancelImmediate = true;
|
417
|
+
};
|
418
|
+
|
419
|
+
event.currentTarget = element;
|
420
|
+
event.relatedTarget = event.fromElement || null;
|
421
|
+
event.target = event.target || event.srcElement || element;
|
422
|
+
event.timeStamp = new Date().getTime();
|
423
|
+
|
424
|
+
if (event.clientX) {
|
425
|
+
event.pageX = event.clientX + document.documentElement.scrollLeft;
|
426
|
+
event.pageY = event.clientY + document.documentElement.scrollTop;
|
427
|
+
}
|
428
|
+
|
429
|
+
while (++index < length && !event.cancelImmediate) {
|
430
|
+
if (index in events) {
|
431
|
+
eventElement = events[index];
|
432
|
+
|
433
|
+
if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
|
434
|
+
eventElement.call(element, event);
|
435
|
+
}
|
436
|
+
}
|
437
|
+
}
|
438
|
+
};
|
439
|
+
|
440
|
+
element._events[type].list = [];
|
441
|
+
|
442
|
+
if (element.attachEvent) {
|
443
|
+
element.attachEvent('on' + type, element._events[type]);
|
444
|
+
}
|
445
|
+
}
|
446
|
+
|
447
|
+
element._events[type].list.push(listener);
|
448
|
+
};
|
449
|
+
|
450
|
+
window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
|
451
|
+
var
|
452
|
+
element = this,
|
453
|
+
type = arguments[0],
|
454
|
+
listener = arguments[1],
|
455
|
+
index;
|
456
|
+
|
457
|
+
if (element._events && element._events[type] && element._events[type].list) {
|
458
|
+
index = indexOf(element._events[type].list, listener);
|
459
|
+
|
460
|
+
if (index !== -1) {
|
461
|
+
element._events[type].list.splice(index, 1);
|
462
|
+
|
463
|
+
if (!element._events[type].list.length) {
|
464
|
+
if (element.detachEvent) {
|
465
|
+
element.detachEvent('on' + type, element._events[type]);
|
466
|
+
}
|
467
|
+
delete element._events[type];
|
468
|
+
}
|
469
|
+
}
|
470
|
+
}
|
471
|
+
};
|
472
|
+
|
473
|
+
window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
|
474
|
+
if (!arguments.length) {
|
475
|
+
throw new Error('Not enough arguments');
|
476
|
+
}
|
477
|
+
|
478
|
+
if (!event || typeof event.type !== 'string') {
|
479
|
+
throw new Error('DOM Events Exception 0');
|
480
|
+
}
|
481
|
+
|
482
|
+
var element = this, type = event.type;
|
483
|
+
|
484
|
+
try {
|
485
|
+
if (!event.bubbles) {
|
486
|
+
event.cancelBubble = true;
|
487
|
+
|
488
|
+
var cancelBubbleEvent = function (event) {
|
489
|
+
event.cancelBubble = true;
|
490
|
+
|
491
|
+
(element || window).detachEvent('on' + type, cancelBubbleEvent);
|
492
|
+
};
|
493
|
+
|
494
|
+
this.attachEvent('on' + type, cancelBubbleEvent);
|
495
|
+
}
|
496
|
+
|
497
|
+
this.fireEvent('on' + type, event);
|
498
|
+
} catch (error) {
|
499
|
+
event.target = element;
|
500
|
+
|
501
|
+
do {
|
502
|
+
event.currentTarget = element;
|
503
|
+
|
504
|
+
if ('_events' in element && typeof element._events[type] === 'function') {
|
505
|
+
element._events[type].call(element, event);
|
506
|
+
}
|
507
|
+
|
508
|
+
if (typeof element['on' + type] === 'function') {
|
509
|
+
element['on' + type].call(element, event);
|
510
|
+
}
|
511
|
+
|
512
|
+
element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
|
513
|
+
} while (element && !event.cancelBubble);
|
514
|
+
}
|
515
|
+
|
516
|
+
return true;
|
517
|
+
};
|
518
|
+
|
519
|
+
// Add the DOMContentLoaded Event
|
520
|
+
document.attachEvent('onreadystatechange', function() {
|
521
|
+
if (document.readyState === 'complete') {
|
522
|
+
document.dispatchEvent(new Event('DOMContentLoaded', {
|
523
|
+
bubbles: true
|
524
|
+
}));
|
525
|
+
}
|
526
|
+
});
|
527
|
+
}
|
528
|
+
}());
|
529
|
+
|
530
|
+
})
|
531
|
+
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
532
|
+
|
533
|
+
/**
|
534
|
+
* JavaScript 'shim' to trigger the click event of element(s) when the space key is pressed.
|
535
|
+
*
|
536
|
+
* Created since some Assistive Technologies (for example some Screenreaders)
|
537
|
+
* will tell a user to press space on a 'button', so this functionality needs to be shimmed
|
538
|
+
* See https://github.com/alphagov/govuk_elements/pull/272#issuecomment-233028270
|
539
|
+
*
|
540
|
+
* Usage instructions:
|
541
|
+
* the 'shim' will be automatically initialised
|
542
|
+
*/
|
543
|
+
|
544
|
+
var KEY_SPACE = 32;
|
545
|
+
|
546
|
+
function Button ($module) {
|
547
|
+
this.$module = $module;
|
548
|
+
}
|
549
|
+
|
550
|
+
/**
|
551
|
+
* Add event handler for KeyDown
|
552
|
+
* if the event target element has a role='button' and the event is key space pressed
|
553
|
+
* then it prevents the default event and triggers a click event
|
554
|
+
* @param {object} event event
|
555
|
+
*/
|
556
|
+
Button.prototype.handleKeyDown = function (event) {
|
557
|
+
// get the target element
|
558
|
+
var target = event.target;
|
559
|
+
// if the element has a role='button' and the pressed key is a space, we'll simulate a click
|
560
|
+
if (target.getAttribute('role') === 'button' && event.keyCode === KEY_SPACE) {
|
561
|
+
event.preventDefault();
|
562
|
+
// trigger the target's click event
|
563
|
+
target.click();
|
564
|
+
}
|
565
|
+
};
|
566
|
+
|
567
|
+
/**
|
568
|
+
* Initialise an event listener for keydown at document level
|
569
|
+
* this will help listening for later inserted elements with a role="button"
|
570
|
+
*/
|
571
|
+
Button.prototype.init = function () {
|
572
|
+
this.$module.addEventListener('keydown', this.handleKeyDown);
|
573
|
+
};
|
574
|
+
|
575
|
+
(function(undefined) {
|
576
|
+
// Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
|
577
|
+
var detect = 'bind' in Function.prototype;
|
578
|
+
|
579
|
+
if (detect) return
|
580
|
+
|
581
|
+
// Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
|
582
|
+
Object.defineProperty(Function.prototype, 'bind', {
|
583
|
+
value: function bind(that) { // .length is 1
|
584
|
+
// add necessary es5-shim utilities
|
585
|
+
var $Array = Array;
|
586
|
+
var $Object = Object;
|
587
|
+
var ObjectPrototype = $Object.prototype;
|
588
|
+
var ArrayPrototype = $Array.prototype;
|
589
|
+
var Empty = function Empty() {};
|
590
|
+
var to_string = ObjectPrototype.toString;
|
591
|
+
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
|
592
|
+
var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
|
593
|
+
var array_slice = ArrayPrototype.slice;
|
594
|
+
var array_concat = ArrayPrototype.concat;
|
595
|
+
var array_push = ArrayPrototype.push;
|
596
|
+
var max = Math.max;
|
597
|
+
// /add necessary es5-shim utilities
|
598
|
+
|
599
|
+
// 1. Let Target be the this value.
|
600
|
+
var target = this;
|
601
|
+
// 2. If IsCallable(Target) is false, throw a TypeError exception.
|
602
|
+
if (!isCallable(target)) {
|
603
|
+
throw new TypeError('Function.prototype.bind called on incompatible ' + target);
|
604
|
+
}
|
605
|
+
// 3. Let A be a new (possibly empty) internal list of all of the
|
606
|
+
// argument values provided after thisArg (arg1, arg2 etc), in order.
|
607
|
+
// XXX slicedArgs will stand in for "A" if used
|
608
|
+
var args = array_slice.call(arguments, 1); // for normal call
|
609
|
+
// 4. Let F be a new native ECMAScript object.
|
610
|
+
// 11. Set the [[Prototype]] internal property of F to the standard
|
611
|
+
// built-in Function prototype object as specified in 15.3.3.1.
|
612
|
+
// 12. Set the [[Call]] internal property of F as described in
|
613
|
+
// 15.3.4.5.1.
|
614
|
+
// 13. Set the [[Construct]] internal property of F as described in
|
615
|
+
// 15.3.4.5.2.
|
616
|
+
// 14. Set the [[HasInstance]] internal property of F as described in
|
617
|
+
// 15.3.4.5.3.
|
618
|
+
var bound;
|
619
|
+
var binder = function () {
|
620
|
+
|
621
|
+
if (this instanceof bound) {
|
622
|
+
// 15.3.4.5.2 [[Construct]]
|
623
|
+
// When the [[Construct]] internal method of a function object,
|
624
|
+
// F that was created using the bind function is called with a
|
625
|
+
// list of arguments ExtraArgs, the following steps are taken:
|
626
|
+
// 1. Let target be the value of F's [[TargetFunction]]
|
627
|
+
// internal property.
|
628
|
+
// 2. If target has no [[Construct]] internal method, a
|
629
|
+
// TypeError exception is thrown.
|
630
|
+
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
|
631
|
+
// property.
|
632
|
+
// 4. Let args be a new list containing the same values as the
|
633
|
+
// list boundArgs in the same order followed by the same
|
634
|
+
// values as the list ExtraArgs in the same order.
|
635
|
+
// 5. Return the result of calling the [[Construct]] internal
|
636
|
+
// method of target providing args as the arguments.
|
637
|
+
|
638
|
+
var result = target.apply(
|
639
|
+
this,
|
640
|
+
array_concat.call(args, array_slice.call(arguments))
|
641
|
+
);
|
642
|
+
if ($Object(result) === result) {
|
643
|
+
return result;
|
644
|
+
}
|
645
|
+
return this;
|
646
|
+
|
647
|
+
} else {
|
648
|
+
// 15.3.4.5.1 [[Call]]
|
649
|
+
// When the [[Call]] internal method of a function object, F,
|
650
|
+
// which was created using the bind function is called with a
|
651
|
+
// this value and a list of arguments ExtraArgs, the following
|
652
|
+
// steps are taken:
|
653
|
+
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
|
654
|
+
// property.
|
655
|
+
// 2. Let boundThis be the value of F's [[BoundThis]] internal
|
656
|
+
// property.
|
657
|
+
// 3. Let target be the value of F's [[TargetFunction]] internal
|
658
|
+
// property.
|
659
|
+
// 4. Let args be a new list containing the same values as the
|
660
|
+
// list boundArgs in the same order followed by the same
|
661
|
+
// values as the list ExtraArgs in the same order.
|
662
|
+
// 5. Return the result of calling the [[Call]] internal method
|
663
|
+
// of target providing boundThis as the this value and
|
664
|
+
// providing args as the arguments.
|
665
|
+
|
666
|
+
// equiv: target.call(this, ...boundArgs, ...args)
|
667
|
+
return target.apply(
|
668
|
+
that,
|
669
|
+
array_concat.call(args, array_slice.call(arguments))
|
670
|
+
);
|
671
|
+
|
672
|
+
}
|
673
|
+
|
674
|
+
};
|
675
|
+
|
676
|
+
// 15. If the [[Class]] internal property of Target is "Function", then
|
677
|
+
// a. Let L be the length property of Target minus the length of A.
|
678
|
+
// b. Set the length own property of F to either 0 or L, whichever is
|
679
|
+
// larger.
|
680
|
+
// 16. Else set the length own property of F to 0.
|
681
|
+
|
682
|
+
var boundLength = max(0, target.length - args.length);
|
683
|
+
|
684
|
+
// 17. Set the attributes of the length own property of F to the values
|
685
|
+
// specified in 15.3.5.1.
|
686
|
+
var boundArgs = [];
|
687
|
+
for (var i = 0; i < boundLength; i++) {
|
688
|
+
array_push.call(boundArgs, '$' + i);
|
689
|
+
}
|
690
|
+
|
691
|
+
// XXX Build a dynamic function with desired amount of arguments is the only
|
692
|
+
// way to set the length property of a function.
|
693
|
+
// In environments where Content Security Policies enabled (Chrome extensions,
|
694
|
+
// for ex.) all use of eval or Function costructor throws an exception.
|
695
|
+
// However in all of these environments Function.prototype.bind exists
|
696
|
+
// and so this code will never be executed.
|
697
|
+
bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
|
698
|
+
|
699
|
+
if (target.prototype) {
|
700
|
+
Empty.prototype = target.prototype;
|
701
|
+
bound.prototype = new Empty();
|
702
|
+
// Clean up dangling references.
|
703
|
+
Empty.prototype = null;
|
704
|
+
}
|
705
|
+
|
706
|
+
// TODO
|
707
|
+
// 18. Set the [[Extensible]] internal property of F to true.
|
708
|
+
|
709
|
+
// TODO
|
710
|
+
// 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
|
711
|
+
// 20. Call the [[DefineOwnProperty]] internal method of F with
|
712
|
+
// arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
|
713
|
+
// thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
|
714
|
+
// false.
|
715
|
+
// 21. Call the [[DefineOwnProperty]] internal method of F with
|
716
|
+
// arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
|
717
|
+
// [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
|
718
|
+
// and false.
|
719
|
+
|
720
|
+
// TODO
|
721
|
+
// NOTE Function objects created using Function.prototype.bind do not
|
722
|
+
// have a prototype property or the [[Code]], [[FormalParameters]], and
|
723
|
+
// [[Scope]] internal properties.
|
724
|
+
// XXX can't delete prototype in pure-js.
|
725
|
+
|
726
|
+
// 22. Return F.
|
727
|
+
return bound;
|
728
|
+
}
|
729
|
+
});
|
730
|
+
})
|
731
|
+
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
732
|
+
|
733
|
+
/**
|
734
|
+
* JavaScript 'polyfill' for HTML5's <details> and <summary> elements
|
735
|
+
* and 'shim' to add accessiblity enhancements for all browsers
|
736
|
+
*
|
737
|
+
* http://caniuse.com/#feat=details
|
738
|
+
*
|
739
|
+
* Usage instructions:
|
740
|
+
* the 'polyfill' will be automatically initialised
|
741
|
+
*/
|
742
|
+
|
743
|
+
var KEY_ENTER = 13;
|
744
|
+
var KEY_SPACE$1 = 32;
|
745
|
+
|
746
|
+
// Create a flag to know if the browser supports navtive details
|
747
|
+
var NATIVE_DETAILS = typeof document.createElement('details').open === 'boolean';
|
748
|
+
|
749
|
+
function Details ($module) {
|
750
|
+
this.$module = $module;
|
751
|
+
}
|
752
|
+
|
753
|
+
/**
|
754
|
+
* Handle cross-modal click events
|
755
|
+
* @param {object} node element
|
756
|
+
* @param {function} callback function
|
757
|
+
*/
|
758
|
+
Details.prototype.handleInputs = function (node, callback) {
|
759
|
+
node.addEventListener('keypress', function (event) {
|
760
|
+
var target = event.target;
|
761
|
+
// When the key gets pressed - check if it is enter or space
|
762
|
+
if (event.keyCode === KEY_ENTER || event.keyCode === KEY_SPACE$1) {
|
763
|
+
if (target.nodeName.toLowerCase() === 'summary') {
|
764
|
+
// Prevent space from scrolling the page
|
765
|
+
// and enter from submitting a form
|
766
|
+
event.preventDefault();
|
767
|
+
// Click to let the click event do all the necessary action
|
768
|
+
if (target.click) {
|
769
|
+
target.click();
|
770
|
+
} else {
|
771
|
+
// except Safari 5.1 and under don't support .click() here
|
772
|
+
callback(event);
|
773
|
+
}
|
774
|
+
}
|
775
|
+
}
|
776
|
+
});
|
777
|
+
|
778
|
+
// Prevent keyup to prevent clicking twice in Firefox when using space key
|
779
|
+
node.addEventListener('keyup', function (event) {
|
780
|
+
var target = event.target;
|
781
|
+
if (event.keyCode === KEY_SPACE$1) {
|
782
|
+
if (target.nodeName.toLowerCase() === 'summary') {
|
783
|
+
event.preventDefault();
|
784
|
+
}
|
785
|
+
}
|
786
|
+
});
|
787
|
+
|
788
|
+
node.addEventListener('click', callback);
|
789
|
+
};
|
790
|
+
|
791
|
+
Details.prototype.init = function () {
|
792
|
+
var $module = this.$module;
|
793
|
+
|
794
|
+
if (!$module) {
|
795
|
+
return
|
796
|
+
}
|
797
|
+
|
798
|
+
// Save shortcuts to the inner summary and content elements
|
799
|
+
var $summary = this.$summary = $module.getElementsByTagName('summary').item(0);
|
800
|
+
var $content = this.$content = $module.getElementsByTagName('div').item(0);
|
801
|
+
|
802
|
+
// If <details> doesn't have a <summary> and a <div> representing the content
|
803
|
+
// it means the required HTML structure is not met so the script will stop
|
804
|
+
if (!$summary || !$content) {
|
805
|
+
return
|
806
|
+
}
|
807
|
+
|
808
|
+
// If the content doesn't have an ID, assign it one now
|
809
|
+
// which we'll need for the summary's aria-controls assignment
|
810
|
+
if (!$content.id) {
|
811
|
+
$content.id = 'details-content-' + generateUniqueID();
|
812
|
+
}
|
813
|
+
|
814
|
+
// Add ARIA role="group" to details
|
815
|
+
$module.setAttribute('role', 'group');
|
816
|
+
|
817
|
+
// Add role=button to summary
|
818
|
+
$summary.setAttribute('role', 'button');
|
819
|
+
|
820
|
+
// Add aria-controls
|
821
|
+
$summary.setAttribute('aria-controls', $content.id);
|
822
|
+
|
823
|
+
// Set tabIndex so the summary is keyboard accessible for non-native elements
|
824
|
+
// http://www.saliences.com/browserBugs/tabIndex.html
|
825
|
+
if (!NATIVE_DETAILS) {
|
826
|
+
$summary.tabIndex = 0;
|
827
|
+
}
|
828
|
+
|
829
|
+
// Detect initial open state
|
830
|
+
var openAttr = $module.getAttribute('open') !== null;
|
831
|
+
if (openAttr === true) {
|
832
|
+
$summary.setAttribute('aria-expanded', 'true');
|
833
|
+
$content.setAttribute('aria-hidden', 'false');
|
834
|
+
} else {
|
835
|
+
$summary.setAttribute('aria-expanded', 'false');
|
836
|
+
$content.setAttribute('aria-hidden', 'true');
|
837
|
+
if (!NATIVE_DETAILS) {
|
838
|
+
$content.style.display = 'none';
|
839
|
+
}
|
840
|
+
}
|
841
|
+
|
842
|
+
// Bind an event to handle summary elements
|
843
|
+
this.handleInputs($module, this.setAttributes.bind(this));
|
844
|
+
};
|
845
|
+
|
846
|
+
/**
|
847
|
+
* Define a statechange function that updates aria-expanded and style.display
|
848
|
+
* @param {object} summary element
|
849
|
+
*/
|
850
|
+
Details.prototype.setAttributes = function () {
|
851
|
+
var $module = this.$module;
|
852
|
+
var $summary = this.$summary;
|
853
|
+
var $content = this.$content;
|
854
|
+
|
855
|
+
var expanded = $summary.getAttribute('aria-expanded') === 'true';
|
856
|
+
var hidden = $content.getAttribute('aria-hidden') === 'true';
|
857
|
+
|
858
|
+
$summary.setAttribute('aria-expanded', (expanded ? 'false' : 'true'));
|
859
|
+
$content.setAttribute('aria-hidden', (hidden ? 'false' : 'true'));
|
860
|
+
|
861
|
+
if (!NATIVE_DETAILS) {
|
862
|
+
$content.style.display = (expanded ? 'none' : '');
|
863
|
+
|
864
|
+
var hasOpenAttr = $module.getAttribute('open') !== null;
|
865
|
+
if (!hasOpenAttr) {
|
866
|
+
$module.setAttribute('open', 'open');
|
867
|
+
} else {
|
868
|
+
$module.removeAttribute('open');
|
869
|
+
}
|
870
|
+
}
|
871
|
+
return true
|
872
|
+
};
|
873
|
+
|
874
|
+
/**
|
875
|
+
* Remove the click event from the node element
|
876
|
+
* @param {object} node element
|
877
|
+
*/
|
878
|
+
Details.prototype.destroy = function (node) {
|
879
|
+
node.removeEventListener('keypress');
|
880
|
+
node.removeEventListener('keyup');
|
881
|
+
node.removeEventListener('click');
|
882
|
+
};
|
883
|
+
|
884
|
+
function Checkboxes ($module) {
|
885
|
+
this.$module = $module;
|
886
|
+
this.$inputs = $module.querySelectorAll('input[type="checkbox"]');
|
887
|
+
}
|
888
|
+
|
889
|
+
Checkboxes.prototype.init = function () {
|
890
|
+
var $module = this.$module;
|
891
|
+
var $inputs = this.$inputs;
|
892
|
+
|
893
|
+
/**
|
894
|
+
* Loop over all items with [data-controls]
|
895
|
+
* Check if they have a matching conditional reveal
|
896
|
+
* If they do, assign attributes.
|
897
|
+
**/
|
898
|
+
nodeListForEach($inputs, function ($input) {
|
899
|
+
var controls = $input.getAttribute('data-aria-controls');
|
900
|
+
|
901
|
+
// Check if input controls anything
|
902
|
+
// Check if content exists, before setting attributes.
|
903
|
+
if (!controls || !$module.querySelector('#' + controls)) {
|
904
|
+
return
|
905
|
+
}
|
906
|
+
|
907
|
+
// If we have content that is controlled, set attributes.
|
908
|
+
$input.setAttribute('aria-controls', controls);
|
909
|
+
$input.removeAttribute('data-aria-controls');
|
910
|
+
this.setAttributes($input);
|
911
|
+
}.bind(this));
|
912
|
+
|
913
|
+
// Handle events
|
914
|
+
$module.addEventListener('click', this.handleClick.bind(this));
|
915
|
+
};
|
916
|
+
|
917
|
+
Checkboxes.prototype.setAttributes = function ($input) {
|
918
|
+
var inputIsChecked = $input.checked;
|
919
|
+
$input.setAttribute('aria-expanded', inputIsChecked);
|
920
|
+
|
921
|
+
var $content = document.querySelector('#' + $input.getAttribute('aria-controls'));
|
922
|
+
$content.setAttribute('aria-hidden', !inputIsChecked);
|
923
|
+
};
|
924
|
+
|
925
|
+
Checkboxes.prototype.handleClick = function (event) {
|
926
|
+
var $target = event.target;
|
927
|
+
|
928
|
+
// If a checkbox with aria-controls, handle click
|
929
|
+
var isCheckbox = $target.getAttribute('type') === 'checkbox';
|
930
|
+
var hasAriaControls = $target.getAttribute('aria-controls');
|
931
|
+
if (isCheckbox && hasAriaControls) {
|
932
|
+
this.setAttributes($target);
|
933
|
+
}
|
934
|
+
};
|
935
|
+
|
936
|
+
function ErrorSummary ($module) {
|
937
|
+
this.$module = $module;
|
938
|
+
}
|
939
|
+
|
940
|
+
ErrorSummary.prototype.init = function () {
|
941
|
+
var $module = this.$module;
|
942
|
+
if (!$module) {
|
943
|
+
return
|
944
|
+
}
|
945
|
+
window.addEventListener('load', function () {
|
946
|
+
$module.focus();
|
947
|
+
});
|
948
|
+
};
|
949
|
+
|
950
|
+
function Header ($module) {
|
951
|
+
this.$module = $module;
|
952
|
+
}
|
953
|
+
|
954
|
+
Header.prototype.init = function () {
|
955
|
+
// Check for module
|
956
|
+
var $module = this.$module;
|
957
|
+
if (!$module) {
|
958
|
+
return
|
959
|
+
}
|
960
|
+
|
961
|
+
// Check for button
|
962
|
+
var $toggleButton = $module.querySelector('.js-header-toggle');
|
963
|
+
if (!$toggleButton) {
|
964
|
+
return
|
965
|
+
}
|
966
|
+
|
967
|
+
// Handle $toggleButton click events
|
968
|
+
$toggleButton.addEventListener('click', this.handleClick.bind(this));
|
969
|
+
};
|
970
|
+
|
971
|
+
/**
|
972
|
+
* Toggle class
|
973
|
+
* @param {object} node element
|
974
|
+
* @param {string} className to toggle
|
975
|
+
*/
|
976
|
+
Header.prototype.toggleClass = function (node, className) {
|
977
|
+
if (node.className.indexOf(className) > 0) {
|
978
|
+
node.className = node.className.replace(' ' + className, '');
|
979
|
+
} else {
|
980
|
+
node.className += ' ' + className;
|
981
|
+
}
|
982
|
+
};
|
983
|
+
|
984
|
+
/**
|
985
|
+
* An event handler for click event on $toggleButton
|
986
|
+
* @param {object} event event
|
987
|
+
*/
|
988
|
+
Header.prototype.handleClick = function (event) {
|
989
|
+
var $module = this.$module;
|
990
|
+
var $toggleButton = event.target || event.srcElement;
|
991
|
+
var $target = $module.querySelector('#' + $toggleButton.getAttribute('aria-controls'));
|
992
|
+
|
993
|
+
// If a button with aria-controls, handle click
|
994
|
+
if ($toggleButton && $target) {
|
995
|
+
this.toggleClass($target, 'govuk-header__navigation--open');
|
996
|
+
this.toggleClass($toggleButton, 'govuk-header__menu-button--open');
|
997
|
+
|
998
|
+
$toggleButton.setAttribute('aria-expanded', $toggleButton.getAttribute('aria-expanded') !== 'true');
|
999
|
+
$target.setAttribute('aria-hidden', $target.getAttribute('aria-hidden') === 'false');
|
1000
|
+
}
|
1001
|
+
};
|
1002
|
+
|
1003
|
+
function Radios ($module) {
|
1004
|
+
this.$module = $module;
|
1005
|
+
this.$inputs = $module.querySelectorAll('input[type="radio"]');
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
Radios.prototype.init = function () {
|
1009
|
+
var $module = this.$module;
|
1010
|
+
var $inputs = this.$inputs;
|
1011
|
+
|
1012
|
+
/**
|
1013
|
+
* Loop over all items with [data-controls]
|
1014
|
+
* Check if they have a matching conditional reveal
|
1015
|
+
* If they do, assign attributes.
|
1016
|
+
**/
|
1017
|
+
nodeListForEach($inputs, function ($input) {
|
1018
|
+
var controls = $input.getAttribute('data-aria-controls');
|
1019
|
+
|
1020
|
+
// Check if input controls anything
|
1021
|
+
// Check if content exists, before setting attributes.
|
1022
|
+
if (!controls || !$module.querySelector('#' + controls)) {
|
1023
|
+
return
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
// If we have content that is controlled, set attributes.
|
1027
|
+
$input.setAttribute('aria-controls', controls);
|
1028
|
+
$input.removeAttribute('data-aria-controls');
|
1029
|
+
this.setAttributes($input);
|
1030
|
+
}.bind(this));
|
1031
|
+
|
1032
|
+
// Handle events
|
1033
|
+
$module.addEventListener('click', this.handleClick.bind(this));
|
1034
|
+
};
|
1035
|
+
|
1036
|
+
Radios.prototype.setAttributes = function ($input) {
|
1037
|
+
var inputIsChecked = $input.checked;
|
1038
|
+
$input.setAttribute('aria-expanded', inputIsChecked);
|
1039
|
+
|
1040
|
+
var $content = document.querySelector('#' + $input.getAttribute('aria-controls'));
|
1041
|
+
$content.setAttribute('aria-hidden', !inputIsChecked);
|
1042
|
+
};
|
1043
|
+
|
1044
|
+
Radios.prototype.handleClick = function (event) {
|
1045
|
+
nodeListForEach(this.$inputs, function ($input) {
|
1046
|
+
// If a radio with aria-controls, handle click
|
1047
|
+
var isRadio = $input.getAttribute('type') === 'radio';
|
1048
|
+
var hasAriaControls = $input.getAttribute('aria-controls');
|
1049
|
+
if (isRadio && hasAriaControls) {
|
1050
|
+
this.setAttributes($input);
|
1051
|
+
}
|
1052
|
+
}.bind(this));
|
1053
|
+
};
|
1054
|
+
|
1055
|
+
(function(undefined) {
|
1056
|
+
|
1057
|
+
// Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
|
1058
|
+
var detect = (
|
1059
|
+
'DOMTokenList' in this && (function (x) {
|
1060
|
+
return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
|
1061
|
+
})(document.createElement('x'))
|
1062
|
+
);
|
1063
|
+
|
1064
|
+
if (detect) return
|
1065
|
+
|
1066
|
+
// Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
|
1067
|
+
(function (global) {
|
1068
|
+
var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
|
1069
|
+
|
1070
|
+
if (
|
1071
|
+
!nativeImpl ||
|
1072
|
+
(
|
1073
|
+
!!document.createElementNS &&
|
1074
|
+
!!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
|
1075
|
+
!(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
|
1076
|
+
)
|
1077
|
+
) {
|
1078
|
+
global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars
|
1079
|
+
var dpSupport = true;
|
1080
|
+
var defineGetter = function (object, name, fn, configurable) {
|
1081
|
+
if (Object.defineProperty)
|
1082
|
+
Object.defineProperty(object, name, {
|
1083
|
+
configurable: false === dpSupport ? true : !!configurable,
|
1084
|
+
get: fn
|
1085
|
+
});
|
1086
|
+
|
1087
|
+
else object.__defineGetter__(name, fn);
|
1088
|
+
};
|
1089
|
+
|
1090
|
+
/** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
|
1091
|
+
try {
|
1092
|
+
defineGetter({}, "support");
|
1093
|
+
}
|
1094
|
+
catch (e) {
|
1095
|
+
dpSupport = false;
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
|
1099
|
+
var _DOMTokenList = function (el, prop) {
|
1100
|
+
var that = this;
|
1101
|
+
var tokens = [];
|
1102
|
+
var tokenMap = {};
|
1103
|
+
var length = 0;
|
1104
|
+
var maxLength = 0;
|
1105
|
+
var addIndexGetter = function (i) {
|
1106
|
+
defineGetter(that, i, function () {
|
1107
|
+
preop();
|
1108
|
+
return tokens[i];
|
1109
|
+
}, false);
|
1110
|
+
|
1111
|
+
};
|
1112
|
+
var reindex = function () {
|
1113
|
+
|
1114
|
+
/** Define getter functions for array-like access to the tokenList's contents. */
|
1115
|
+
if (length >= maxLength)
|
1116
|
+
for (; maxLength < length; ++maxLength) {
|
1117
|
+
addIndexGetter(maxLength);
|
1118
|
+
}
|
1119
|
+
};
|
1120
|
+
|
1121
|
+
/** Helper function called at the start of each class method. Internal use only. */
|
1122
|
+
var preop = function () {
|
1123
|
+
var error;
|
1124
|
+
var i;
|
1125
|
+
var args = arguments;
|
1126
|
+
var rSpace = /\s+/;
|
1127
|
+
|
1128
|
+
/** Validate the token/s passed to an instance method, if any. */
|
1129
|
+
if (args.length)
|
1130
|
+
for (i = 0; i < args.length; ++i)
|
1131
|
+
if (rSpace.test(args[i])) {
|
1132
|
+
error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
|
1133
|
+
error.code = 5;
|
1134
|
+
error.name = "InvalidCharacterError";
|
1135
|
+
throw error;
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
|
1139
|
+
/** Split the new value apart by whitespace*/
|
1140
|
+
if (typeof el[prop] === "object") {
|
1141
|
+
tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
|
1142
|
+
} else {
|
1143
|
+
tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
|
1144
|
+
}
|
1145
|
+
|
1146
|
+
/** Avoid treating blank strings as single-item token lists */
|
1147
|
+
if ("" === tokens[0]) tokens = [];
|
1148
|
+
|
1149
|
+
/** Repopulate the internal token lists */
|
1150
|
+
tokenMap = {};
|
1151
|
+
for (i = 0; i < tokens.length; ++i)
|
1152
|
+
tokenMap[tokens[i]] = true;
|
1153
|
+
length = tokens.length;
|
1154
|
+
reindex();
|
1155
|
+
};
|
1156
|
+
|
1157
|
+
/** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
|
1158
|
+
preop();
|
1159
|
+
|
1160
|
+
/** Return the number of tokens in the underlying string. Read-only. */
|
1161
|
+
defineGetter(that, "length", function () {
|
1162
|
+
preop();
|
1163
|
+
return length;
|
1164
|
+
});
|
1165
|
+
|
1166
|
+
/** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
|
1167
|
+
that.toLocaleString =
|
1168
|
+
that.toString = function () {
|
1169
|
+
preop();
|
1170
|
+
return tokens.join(" ");
|
1171
|
+
};
|
1172
|
+
|
1173
|
+
that.item = function (idx) {
|
1174
|
+
preop();
|
1175
|
+
return tokens[idx];
|
1176
|
+
};
|
1177
|
+
|
1178
|
+
that.contains = function (token) {
|
1179
|
+
preop();
|
1180
|
+
return !!tokenMap[token];
|
1181
|
+
};
|
1182
|
+
|
1183
|
+
that.add = function () {
|
1184
|
+
preop.apply(that, args = arguments);
|
1185
|
+
|
1186
|
+
for (var args, token, i = 0, l = args.length; i < l; ++i) {
|
1187
|
+
token = args[i];
|
1188
|
+
if (!tokenMap[token]) {
|
1189
|
+
tokens.push(token);
|
1190
|
+
tokenMap[token] = true;
|
1191
|
+
}
|
1192
|
+
}
|
1193
|
+
|
1194
|
+
/** Update the targeted attribute of the attached element if the token list's changed. */
|
1195
|
+
if (length !== tokens.length) {
|
1196
|
+
length = tokens.length >>> 0;
|
1197
|
+
if (typeof el[prop] === "object") {
|
1198
|
+
el[prop].baseVal = tokens.join(" ");
|
1199
|
+
} else {
|
1200
|
+
el[prop] = tokens.join(" ");
|
1201
|
+
}
|
1202
|
+
reindex();
|
1203
|
+
}
|
1204
|
+
};
|
1205
|
+
|
1206
|
+
that.remove = function () {
|
1207
|
+
preop.apply(that, args = arguments);
|
1208
|
+
|
1209
|
+
/** Build a hash of token names to compare against when recollecting our token list. */
|
1210
|
+
for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
|
1211
|
+
ignore[args[i]] = true;
|
1212
|
+
delete tokenMap[args[i]];
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
/** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
|
1216
|
+
for (i = 0; i < tokens.length; ++i)
|
1217
|
+
if (!ignore[tokens[i]]) t.push(tokens[i]);
|
1218
|
+
|
1219
|
+
tokens = t;
|
1220
|
+
length = t.length >>> 0;
|
1221
|
+
|
1222
|
+
/** Update the targeted attribute of the attached element. */
|
1223
|
+
if (typeof el[prop] === "object") {
|
1224
|
+
el[prop].baseVal = tokens.join(" ");
|
1225
|
+
} else {
|
1226
|
+
el[prop] = tokens.join(" ");
|
1227
|
+
}
|
1228
|
+
reindex();
|
1229
|
+
};
|
1230
|
+
|
1231
|
+
that.toggle = function (token, force) {
|
1232
|
+
preop.apply(that, [token]);
|
1233
|
+
|
1234
|
+
/** Token state's being forced. */
|
1235
|
+
if (undefined !== force) {
|
1236
|
+
if (force) {
|
1237
|
+
that.add(token);
|
1238
|
+
return true;
|
1239
|
+
} else {
|
1240
|
+
that.remove(token);
|
1241
|
+
return false;
|
1242
|
+
}
|
1243
|
+
}
|
1244
|
+
|
1245
|
+
/** Token already exists in tokenList. Remove it, and return FALSE. */
|
1246
|
+
if (tokenMap[token]) {
|
1247
|
+
that.remove(token);
|
1248
|
+
return false;
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
/** Otherwise, add the token and return TRUE. */
|
1252
|
+
that.add(token);
|
1253
|
+
return true;
|
1254
|
+
};
|
1255
|
+
|
1256
|
+
return that;
|
1257
|
+
};
|
1258
|
+
|
1259
|
+
return _DOMTokenList;
|
1260
|
+
}());
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
// Add second argument to native DOMTokenList.toggle() if necessary
|
1264
|
+
(function () {
|
1265
|
+
var e = document.createElement('span');
|
1266
|
+
if (!('classList' in e)) return;
|
1267
|
+
e.classList.toggle('x', false);
|
1268
|
+
if (!e.classList.contains('x')) return;
|
1269
|
+
e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
|
1270
|
+
var force = arguments[1];
|
1271
|
+
if (force === undefined) {
|
1272
|
+
var add = !this.contains(token);
|
1273
|
+
this[add ? 'add' : 'remove'](token);
|
1274
|
+
return add;
|
1275
|
+
}
|
1276
|
+
force = !!force;
|
1277
|
+
this[force ? 'add' : 'remove'](token);
|
1278
|
+
return force;
|
1279
|
+
};
|
1280
|
+
}());
|
1281
|
+
|
1282
|
+
// Add multiple arguments to native DOMTokenList.add() if necessary
|
1283
|
+
(function () {
|
1284
|
+
var e = document.createElement('span');
|
1285
|
+
if (!('classList' in e)) return;
|
1286
|
+
e.classList.add('a', 'b');
|
1287
|
+
if (e.classList.contains('b')) return;
|
1288
|
+
var native = e.classList.constructor.prototype.add;
|
1289
|
+
e.classList.constructor.prototype.add = function () {
|
1290
|
+
var args = arguments;
|
1291
|
+
var l = arguments.length;
|
1292
|
+
for (var i = 0; i < l; i++) {
|
1293
|
+
native.call(this, args[i]);
|
1294
|
+
}
|
1295
|
+
};
|
1296
|
+
}());
|
1297
|
+
|
1298
|
+
// Add multiple arguments to native DOMTokenList.remove() if necessary
|
1299
|
+
(function () {
|
1300
|
+
var e = document.createElement('span');
|
1301
|
+
if (!('classList' in e)) return;
|
1302
|
+
e.classList.add('a');
|
1303
|
+
e.classList.add('b');
|
1304
|
+
e.classList.remove('a', 'b');
|
1305
|
+
if (!e.classList.contains('b')) return;
|
1306
|
+
var native = e.classList.constructor.prototype.remove;
|
1307
|
+
e.classList.constructor.prototype.remove = function () {
|
1308
|
+
var args = arguments;
|
1309
|
+
var l = arguments.length;
|
1310
|
+
for (var i = 0; i < l; i++) {
|
1311
|
+
native.call(this, args[i]);
|
1312
|
+
}
|
1313
|
+
};
|
1314
|
+
}());
|
1315
|
+
|
1316
|
+
}(this));
|
1317
|
+
|
1318
|
+
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
1319
|
+
|
1320
|
+
(function(undefined) {
|
1321
|
+
|
1322
|
+
// Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
|
1323
|
+
var detect = (
|
1324
|
+
'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () {
|
1325
|
+
var e = document.createElement('span');
|
1326
|
+
e.classList.add('a', 'b');
|
1327
|
+
return e.classList.contains('b');
|
1328
|
+
}())
|
1329
|
+
);
|
1330
|
+
|
1331
|
+
if (detect) return
|
1332
|
+
|
1333
|
+
// Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/polyfill.js
|
1334
|
+
(function (global) {
|
1335
|
+
var dpSupport = true;
|
1336
|
+
var defineGetter = function (object, name, fn, configurable) {
|
1337
|
+
if (Object.defineProperty)
|
1338
|
+
Object.defineProperty(object, name, {
|
1339
|
+
configurable: false === dpSupport ? true : !!configurable,
|
1340
|
+
get: fn
|
1341
|
+
});
|
1342
|
+
|
1343
|
+
else object.__defineGetter__(name, fn);
|
1344
|
+
};
|
1345
|
+
/** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
|
1346
|
+
try {
|
1347
|
+
defineGetter({}, "support");
|
1348
|
+
}
|
1349
|
+
catch (e) {
|
1350
|
+
dpSupport = false;
|
1351
|
+
}
|
1352
|
+
/** Polyfills a property with a DOMTokenList */
|
1353
|
+
var addProp = function (o, name, attr) {
|
1354
|
+
|
1355
|
+
defineGetter(o.prototype, name, function () {
|
1356
|
+
var tokenList;
|
1357
|
+
|
1358
|
+
var THIS = this,
|
1359
|
+
|
1360
|
+
/** Prevent this from firing twice for some reason. What the hell, IE. */
|
1361
|
+
gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
|
1362
|
+
if(THIS[gibberishProperty]) return tokenList;
|
1363
|
+
THIS[gibberishProperty] = true;
|
1364
|
+
|
1365
|
+
/**
|
1366
|
+
* IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
|
1367
|
+
*
|
1368
|
+
* What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
|
1369
|
+
* that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
|
1370
|
+
* element instead, this would conflict with element types which use indexed properties (such as forms and
|
1371
|
+
* select lists).
|
1372
|
+
*/
|
1373
|
+
if (false === dpSupport) {
|
1374
|
+
|
1375
|
+
var visage;
|
1376
|
+
var mirror = addProp.mirror || document.createElement("div");
|
1377
|
+
var reflections = mirror.childNodes;
|
1378
|
+
var l = reflections.length;
|
1379
|
+
|
1380
|
+
for (var i = 0; i < l; ++i)
|
1381
|
+
if (reflections[i]._R === THIS) {
|
1382
|
+
visage = reflections[i];
|
1383
|
+
break;
|
1384
|
+
}
|
1385
|
+
|
1386
|
+
/** Couldn't find an element's reflection inside the mirror. Materialise one. */
|
1387
|
+
visage || (visage = mirror.appendChild(document.createElement("div")));
|
1388
|
+
|
1389
|
+
tokenList = DOMTokenList.call(visage, THIS, attr);
|
1390
|
+
} else tokenList = new DOMTokenList(THIS, attr);
|
1391
|
+
|
1392
|
+
defineGetter(THIS, name, function () {
|
1393
|
+
return tokenList;
|
1394
|
+
});
|
1395
|
+
delete THIS[gibberishProperty];
|
1396
|
+
|
1397
|
+
return tokenList;
|
1398
|
+
}, true);
|
1399
|
+
};
|
1400
|
+
|
1401
|
+
addProp(global.Element, "classList", "className");
|
1402
|
+
addProp(global.HTMLElement, "classList", "className");
|
1403
|
+
addProp(global.HTMLLinkElement, "relList", "rel");
|
1404
|
+
addProp(global.HTMLAnchorElement, "relList", "rel");
|
1405
|
+
addProp(global.HTMLAreaElement, "relList", "rel");
|
1406
|
+
}(this));
|
1407
|
+
|
1408
|
+
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
1409
|
+
|
1410
|
+
function Tabs ($module) {
|
1411
|
+
this.$module = $module;
|
1412
|
+
this.$tabs = $module.querySelectorAll('.govuk-tabs__tab');
|
1413
|
+
|
1414
|
+
this.keys = { left: 37, right: 39, up: 38, down: 40 };
|
1415
|
+
this.jsHiddenClass = 'js-hidden';
|
1416
|
+
}
|
1417
|
+
|
1418
|
+
Tabs.prototype.init = function () {
|
1419
|
+
if (typeof window.matchMedia === 'function') {
|
1420
|
+
this.setupResponsiveChecks();
|
1421
|
+
} else {
|
1422
|
+
this.setup();
|
1423
|
+
}
|
1424
|
+
};
|
1425
|
+
|
1426
|
+
Tabs.prototype.setupResponsiveChecks = function () {
|
1427
|
+
this.mql = window.matchMedia('(min-width: 40.0625em)');
|
1428
|
+
this.mql.addListener(this.checkMode.bind(this));
|
1429
|
+
this.checkMode();
|
1430
|
+
};
|
1431
|
+
|
1432
|
+
Tabs.prototype.checkMode = function () {
|
1433
|
+
if (this.mql.matches) {
|
1434
|
+
this.setup();
|
1435
|
+
} else {
|
1436
|
+
this.teardown();
|
1437
|
+
}
|
1438
|
+
};
|
1439
|
+
|
1440
|
+
Tabs.prototype.setup = function () {
|
1441
|
+
var $module = this.$module;
|
1442
|
+
var $tabs = this.$tabs;
|
1443
|
+
var $tabList = $module.querySelector('.govuk-tabs__list');
|
1444
|
+
var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
|
1445
|
+
|
1446
|
+
if (!$tabs || !$tabList || !$tabListItems) {
|
1447
|
+
return
|
1448
|
+
}
|
1449
|
+
|
1450
|
+
$tabList.setAttribute('role', 'tablist');
|
1451
|
+
|
1452
|
+
nodeListForEach($tabListItems, function ($item) {
|
1453
|
+
$item.setAttribute('role', 'presentation');
|
1454
|
+
});
|
1455
|
+
|
1456
|
+
nodeListForEach($tabs, function ($tab) {
|
1457
|
+
// Set HTML attributes
|
1458
|
+
this.setAttributes($tab);
|
1459
|
+
|
1460
|
+
// Save bounded functions to use when removing event listeners during teardown
|
1461
|
+
$tab.boundTabClick = this.onTabClick.bind(this);
|
1462
|
+
$tab.boundTabKeydown = this.onTabKeydown.bind(this);
|
1463
|
+
|
1464
|
+
// Handle events
|
1465
|
+
$tab.addEventListener('click', $tab.boundTabClick, true);
|
1466
|
+
$tab.addEventListener('keydown', $tab.boundTabKeydown, true);
|
1467
|
+
|
1468
|
+
// Remove old active panels
|
1469
|
+
this.hideTab($tab);
|
1470
|
+
}.bind(this));
|
1471
|
+
|
1472
|
+
// Show either the active tab according to the URL's hash or the first tab
|
1473
|
+
var $activeTab = this.getTab(window.location.hash) || this.$tabs[0];
|
1474
|
+
this.showTab($activeTab);
|
1475
|
+
|
1476
|
+
// Handle hashchange events
|
1477
|
+
$module.boundOnHashChange = this.onHashChange.bind(this);
|
1478
|
+
window.addEventListener('hashchange', $module.boundOnHashChange, true);
|
1479
|
+
};
|
1480
|
+
|
1481
|
+
Tabs.prototype.teardown = function () {
|
1482
|
+
var $module = this.$module;
|
1483
|
+
var $tabs = this.$tabs;
|
1484
|
+
var $tabList = $module.querySelector('.govuk-tabs__list');
|
1485
|
+
var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
|
1486
|
+
|
1487
|
+
if (!$tabs || !$tabList || !$tabListItems) {
|
1488
|
+
return
|
1489
|
+
}
|
1490
|
+
|
1491
|
+
$tabList.removeAttribute('role');
|
1492
|
+
|
1493
|
+
nodeListForEach($tabListItems, function ($item) {
|
1494
|
+
$item.removeAttribute('role', 'presentation');
|
1495
|
+
});
|
1496
|
+
|
1497
|
+
nodeListForEach($tabs, function ($tab) {
|
1498
|
+
// Remove events
|
1499
|
+
$tab.removeEventListener('click', $tab.boundTabClick, true);
|
1500
|
+
$tab.removeEventListener('keydown', $tab.boundTabKeydown, true);
|
1501
|
+
|
1502
|
+
// Unset HTML attributes
|
1503
|
+
this.unsetAttributes($tab);
|
1504
|
+
}.bind(this));
|
1505
|
+
|
1506
|
+
// Remove hashchange event handler
|
1507
|
+
window.removeEventListener('hashchange', $module.boundOnHashChange, true);
|
1508
|
+
};
|
1509
|
+
|
1510
|
+
Tabs.prototype.onHashChange = function (e) {
|
1511
|
+
var hash = window.location.hash;
|
1512
|
+
if (!this.hasTab(hash)) {
|
1513
|
+
return
|
1514
|
+
}
|
1515
|
+
// Prevent changing the hash
|
1516
|
+
if (this.changingHash) {
|
1517
|
+
this.changingHash = false;
|
1518
|
+
return
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
// Show either the active tab according to the URL's hash or the first tab
|
1522
|
+
var $previousTab = this.getCurrentTab();
|
1523
|
+
var $activeTab = this.getTab(hash) || this.$tabs[0];
|
1524
|
+
|
1525
|
+
this.hideTab($previousTab);
|
1526
|
+
this.showTab($activeTab);
|
1527
|
+
$activeTab.focus();
|
1528
|
+
};
|
1529
|
+
|
1530
|
+
Tabs.prototype.hasTab = function (hash) {
|
1531
|
+
return this.$module.querySelector(hash)
|
1532
|
+
};
|
1533
|
+
|
1534
|
+
Tabs.prototype.hideTab = function ($tab) {
|
1535
|
+
this.unhighlightTab($tab);
|
1536
|
+
this.hidePanel($tab);
|
1537
|
+
};
|
1538
|
+
|
1539
|
+
Tabs.prototype.showTab = function ($tab) {
|
1540
|
+
this.highlightTab($tab);
|
1541
|
+
this.showPanel($tab);
|
1542
|
+
};
|
1543
|
+
|
1544
|
+
Tabs.prototype.getTab = function (hash) {
|
1545
|
+
return this.$module.querySelector('a[role="tab"][href="' + hash + '"]')
|
1546
|
+
};
|
1547
|
+
|
1548
|
+
Tabs.prototype.setAttributes = function ($tab) {
|
1549
|
+
// set tab attributes
|
1550
|
+
var panelId = this.getHref($tab).slice(1);
|
1551
|
+
$tab.setAttribute('id', 'tab_' + panelId);
|
1552
|
+
$tab.setAttribute('role', 'tab');
|
1553
|
+
$tab.setAttribute('aria-controls', panelId);
|
1554
|
+
$tab.setAttribute('tabindex', '-1');
|
1555
|
+
|
1556
|
+
// set panel attributes
|
1557
|
+
var $panel = this.getPanel($tab);
|
1558
|
+
$panel.setAttribute('role', 'tabpanel');
|
1559
|
+
$panel.setAttribute('aria-labelledby', $tab.id);
|
1560
|
+
$panel.classList.add(this.jsHiddenClass);
|
1561
|
+
};
|
1562
|
+
|
1563
|
+
Tabs.prototype.unsetAttributes = function ($tab) {
|
1564
|
+
// unset tab attributes
|
1565
|
+
$tab.removeAttribute('id');
|
1566
|
+
$tab.removeAttribute('role');
|
1567
|
+
$tab.removeAttribute('aria-controls');
|
1568
|
+
$tab.removeAttribute('tabindex');
|
1569
|
+
|
1570
|
+
// unset panel attributes
|
1571
|
+
var $panel = this.getPanel($tab);
|
1572
|
+
$panel.removeAttribute('role');
|
1573
|
+
$panel.removeAttribute('aria-labelledby');
|
1574
|
+
$panel.classList.remove(this.jsHiddenClass);
|
1575
|
+
};
|
1576
|
+
|
1577
|
+
Tabs.prototype.onTabClick = function (e) {
|
1578
|
+
e.preventDefault();
|
1579
|
+
var $newTab = e.target;
|
1580
|
+
var $currentTab = this.getCurrentTab();
|
1581
|
+
this.hideTab($currentTab);
|
1582
|
+
this.showTab($newTab);
|
1583
|
+
this.createHistoryEntry($newTab);
|
1584
|
+
};
|
1585
|
+
|
1586
|
+
Tabs.prototype.createHistoryEntry = function ($tab) {
|
1587
|
+
var $panel = this.getPanel($tab);
|
1588
|
+
|
1589
|
+
// Save and restore the id
|
1590
|
+
// so the page doesn't jump when a user clicks a tab (which changes the hash)
|
1591
|
+
var id = $panel.id;
|
1592
|
+
$panel.id = '';
|
1593
|
+
this.changingHash = true;
|
1594
|
+
window.location.hash = this.getHref($tab).slice(1);
|
1595
|
+
$panel.id = id;
|
1596
|
+
};
|
1597
|
+
|
1598
|
+
Tabs.prototype.onTabKeydown = function (e) {
|
1599
|
+
switch (e.keyCode) {
|
1600
|
+
case this.keys.left:
|
1601
|
+
case this.keys.up:
|
1602
|
+
this.activatePreviousTab();
|
1603
|
+
e.preventDefault();
|
1604
|
+
break
|
1605
|
+
case this.keys.right:
|
1606
|
+
case this.keys.down:
|
1607
|
+
this.activateNextTab();
|
1608
|
+
e.preventDefault();
|
1609
|
+
break
|
1610
|
+
}
|
1611
|
+
};
|
1612
|
+
|
1613
|
+
Tabs.prototype.activateNextTab = function () {
|
1614
|
+
var currentTab = this.getCurrentTab();
|
1615
|
+
var nextTabListItem = currentTab.parentNode.nextElementSibling;
|
1616
|
+
if (nextTabListItem) {
|
1617
|
+
var nextTab = nextTabListItem.firstElementChild;
|
1618
|
+
}
|
1619
|
+
if (nextTab) {
|
1620
|
+
this.hideTab(currentTab);
|
1621
|
+
this.showTab(nextTab);
|
1622
|
+
nextTab.focus();
|
1623
|
+
this.createHistoryEntry(nextTab);
|
1624
|
+
}
|
1625
|
+
};
|
1626
|
+
|
1627
|
+
Tabs.prototype.activatePreviousTab = function () {
|
1628
|
+
var currentTab = this.getCurrentTab();
|
1629
|
+
var previousTabListItem = currentTab.parentNode.previousElementSibling;
|
1630
|
+
if (previousTabListItem) {
|
1631
|
+
var previousTab = previousTabListItem.firstElementChild;
|
1632
|
+
}
|
1633
|
+
if (previousTab) {
|
1634
|
+
this.hideTab(currentTab);
|
1635
|
+
this.showTab(previousTab);
|
1636
|
+
previousTab.focus();
|
1637
|
+
this.createHistoryEntry(previousTab);
|
1638
|
+
}
|
1639
|
+
};
|
1640
|
+
|
1641
|
+
Tabs.prototype.getPanel = function ($tab) {
|
1642
|
+
var $panel = this.$module.querySelector(this.getHref($tab));
|
1643
|
+
return $panel
|
1644
|
+
};
|
1645
|
+
|
1646
|
+
Tabs.prototype.showPanel = function ($tab) {
|
1647
|
+
var $panel = this.getPanel($tab);
|
1648
|
+
$panel.classList.remove(this.jsHiddenClass);
|
1649
|
+
};
|
1650
|
+
|
1651
|
+
Tabs.prototype.hidePanel = function (tab) {
|
1652
|
+
var $panel = this.getPanel(tab);
|
1653
|
+
$panel.classList.add(this.jsHiddenClass);
|
1654
|
+
};
|
1655
|
+
|
1656
|
+
Tabs.prototype.unhighlightTab = function ($tab) {
|
1657
|
+
$tab.setAttribute('aria-selected', 'false');
|
1658
|
+
$tab.setAttribute('tabindex', '-1');
|
1659
|
+
};
|
1660
|
+
|
1661
|
+
Tabs.prototype.highlightTab = function ($tab) {
|
1662
|
+
$tab.setAttribute('aria-selected', 'true');
|
1663
|
+
$tab.setAttribute('tabindex', '0');
|
1664
|
+
};
|
1665
|
+
|
1666
|
+
Tabs.prototype.getCurrentTab = function () {
|
1667
|
+
return this.$module.querySelector('[role=tab][aria-selected=true]')
|
1668
|
+
};
|
1669
|
+
|
1670
|
+
// this is because IE doesn't always return the actual value but a relative full path
|
1671
|
+
// should be a utility function most prob
|
1672
|
+
// http://labs.thesedays.com/blog/2010/01/08/getting-the-href-value-with-jquery-in-ie/
|
1673
|
+
Tabs.prototype.getHref = function ($tab) {
|
1674
|
+
var href = $tab.getAttribute('href');
|
1675
|
+
var hash = href.slice(href.indexOf('#'), href.length);
|
1676
|
+
return hash
|
1677
|
+
};
|
1678
|
+
|
1679
|
+
function initAll () {
|
1680
|
+
new Button(document).init();
|
1681
|
+
|
1682
|
+
var $details = document.querySelectorAll('details');
|
1683
|
+
nodeListForEach($details, function ($detail) {
|
1684
|
+
new Details($detail).init();
|
1685
|
+
});
|
1686
|
+
|
1687
|
+
var $checkboxes = document.querySelectorAll('[data-module="checkboxes"]');
|
1688
|
+
nodeListForEach($checkboxes, function ($checkbox) {
|
1689
|
+
new Checkboxes($checkbox).init();
|
1690
|
+
});
|
1691
|
+
|
1692
|
+
// Find first Error Summary module to enhance.
|
1693
|
+
var $errorSummary = document.querySelector('[data-module="error-summary"]');
|
1694
|
+
new ErrorSummary($errorSummary).init();
|
1695
|
+
|
1696
|
+
// Find first header module to enhance.
|
1697
|
+
var $toggleButton = document.querySelector('[data-module="header"]');
|
1698
|
+
new Header($toggleButton).init();
|
1699
|
+
|
1700
|
+
var $radios = document.querySelectorAll('[data-module="radios"]');
|
1701
|
+
nodeListForEach($radios, function ($radio) {
|
1702
|
+
new Radios($radio).init();
|
1703
|
+
});
|
1704
|
+
|
1705
|
+
var $tabs = document.querySelectorAll('[data-module="tabs"]');
|
1706
|
+
nodeListForEach($tabs, function ($tabs) {
|
1707
|
+
new Tabs($tabs).init();
|
1708
|
+
});
|
1709
|
+
}
|
1710
|
+
|
1711
|
+
exports.initAll = initAll;
|
1712
|
+
exports.Button = Button;
|
1713
|
+
exports.Details = Details;
|
1714
|
+
exports.Checkboxes = Checkboxes;
|
1715
|
+
exports.ErrorSummary = ErrorSummary;
|
1716
|
+
exports.Header = Header;
|
1717
|
+
exports.Radios = Radios;
|
1718
|
+
exports.Tabs = Tabs;
|
1719
|
+
|
1720
|
+
})));
|