govuk_publishing_components 21.59.0 → 21.61.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -6
  3. data/app/assets/javascripts/component_guide/accessibility-test.js +21 -21
  4. data/app/assets/javascripts/component_guide/filter-components.js +19 -19
  5. data/app/assets/javascripts/component_guide/visual-regression.js +38 -37
  6. data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +102 -73
  7. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +4 -4
  8. data/app/assets/javascripts/govuk_publishing_components/ie.js +2 -0
  9. data/app/assets/javascripts/govuk_publishing_components/lib/auto-track-event.js +31 -0
  10. data/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +24 -24
  11. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +17 -17
  12. data/app/assets/javascripts/govuk_publishing_components/vendor/html5shiv-printshiv.js +4 -0
  13. data/app/assets/javascripts/govuk_publishing_components/vendor/json2.js +487 -0
  14. data/app/assets/stylesheets/component_guide/application.scss +19 -15
  15. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  16. data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +0 -8
  17. data/app/assets/stylesheets/govuk_publishing_components/components/_breadcrumbs.scss +1 -1
  18. data/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss +4 -0
  19. data/app/assets/stylesheets/govuk_publishing_components/components/_cookie-banner.scss +1 -8
  20. data/app/assets/stylesheets/govuk_publishing_components/components/_feedback.scss +0 -1
  21. data/app/assets/stylesheets/govuk_publishing_components/components/_govspeak-html-publication.scss +4 -5
  22. data/app/assets/stylesheets/govuk_publishing_components/components/_heading.scss +3 -8
  23. data/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +1 -1
  24. data/app/assets/stylesheets/govuk_publishing_components/components/_input.scss +1 -1
  25. data/app/assets/stylesheets/govuk_publishing_components/components/_inverse-header.scss +5 -8
  26. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-footer.scss +8 -0
  27. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-for-public.scss +4 -0
  28. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss +87 -1
  29. data/app/assets/stylesheets/govuk_publishing_components/components/_radio.scss +4 -0
  30. data/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +2 -2
  31. data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +46 -1
  32. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss +0 -5
  33. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss +1 -4
  34. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +8 -12
  35. data/app/assets/stylesheets/govuk_publishing_components/components/_table.scss +21 -24
  36. data/app/assets/stylesheets/govuk_publishing_components/components/_tabs.scss +4 -8
  37. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss +2 -0
  38. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_button.scss +1 -4
  39. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_charts.scss +6 -6
  40. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss +2 -0
  41. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_footnotes.scss +2 -0
  42. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_highlight-answer.scss +2 -0
  43. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_place.scss +1 -1
  44. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_typography.scss +2 -0
  45. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +1 -1
  46. data/app/assets/stylesheets/govuk_publishing_components/components/print/_govspeak.scss +2 -0
  47. data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav-header.scss +0 -4
  48. data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav.scss +2 -10
  49. data/app/controllers/govuk_publishing_components/audit_controller.rb +2 -2
  50. data/app/controllers/govuk_publishing_components/component_guide_controller.rb +2 -2
  51. data/app/models/govuk_publishing_components/audit_applications.rb +45 -27
  52. data/app/models/govuk_publishing_components/audit_comparer.rb +77 -51
  53. data/app/models/govuk_publishing_components/audit_components.rb +25 -6
  54. data/app/models/govuk_publishing_components/component_example.rb +4 -0
  55. data/app/views/govuk_publishing_components/audit/show.html.erb +227 -190
  56. data/app/views/govuk_publishing_components/component_guide/component_doc/_component.html.erb +1 -0
  57. data/app/views/govuk_publishing_components/component_guide/index.html.erb +3 -1
  58. data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +1 -1
  59. data/app/views/govuk_publishing_components/components/_image_card.html.erb +1 -1
  60. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +32 -21
  61. data/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +76 -0
  62. data/app/views/govuk_publishing_components/components/_layout_header.html.erb +39 -51
  63. data/app/views/govuk_publishing_components/components/_machine_readable_metadata.html.erb +1 -1
  64. data/app/views/govuk_publishing_components/components/_radio.html.erb +13 -5
  65. data/app/views/govuk_publishing_components/components/_search.html.erb +10 -5
  66. data/app/views/govuk_publishing_components/components/_share_links.html.erb +9 -9
  67. data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +2 -2
  68. data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +4 -0
  69. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +45 -0
  70. data/app/views/govuk_publishing_components/components/docs/heading.yml +6 -3
  71. data/app/views/govuk_publishing_components/components/docs/image_card.yml +13 -1
  72. data/app/views/govuk_publishing_components/components/docs/layout_footer.yml +17 -0
  73. data/app/views/govuk_publishing_components/components/docs/layout_for_admin.yml +5 -1
  74. data/app/views/govuk_publishing_components/components/docs/layout_for_public.yml +29 -0
  75. data/app/views/govuk_publishing_components/components/docs/layout_header.yml +34 -0
  76. data/app/views/govuk_publishing_components/components/docs/radio.yml +4 -0
  77. data/app/views/govuk_publishing_components/components/docs/search.yml +6 -0
  78. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +23 -0
  79. data/app/views/govuk_publishing_components/components/layout_header/_navigation_items.html.erb +17 -0
  80. data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +9 -0
  81. data/config/initializers/assets.rb +8 -0
  82. data/lib/govuk_publishing_components.rb +1 -0
  83. data/lib/govuk_publishing_components/presenters/checkboxes_helper.rb +15 -7
  84. data/lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_priority.rb +1 -0
  85. data/lib/govuk_publishing_components/presenters/heading_helper.rb +21 -1
  86. data/lib/govuk_publishing_components/presenters/image_card_helper.rb +3 -2
  87. data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +380 -0
  88. data/lib/govuk_publishing_components/version.rb +1 -1
  89. data/node_modules/axe-core/package.json +145 -220
  90. data/node_modules/govuk-frontend/govuk/all.js +160 -57
  91. data/node_modules/govuk-frontend/govuk/components/character-count/_index.scss +0 -4
  92. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +16 -8
  93. data/node_modules/govuk-frontend/govuk/components/character-count/macro-options.json +6 -0
  94. data/node_modules/govuk-frontend/govuk/components/character-count/template.njk +1 -0
  95. data/node_modules/govuk-frontend/govuk/components/checkboxes/_index.scss +6 -5
  96. data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +68 -21
  97. data/node_modules/govuk-frontend/govuk/components/date-input/macro-options.json +1 -1
  98. data/node_modules/govuk-frontend/govuk/components/file-upload/_index.scss +0 -27
  99. data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +0 -3
  100. data/node_modules/govuk-frontend/govuk/components/footer/template.njk +1 -1
  101. data/node_modules/govuk-frontend/govuk/components/header/template.njk +1 -1
  102. data/node_modules/govuk-frontend/govuk/components/hint/_index.scss +2 -2
  103. data/node_modules/govuk-frontend/govuk/components/hint/template.njk +2 -2
  104. data/node_modules/govuk-frontend/govuk/components/input/_index.scss +0 -3
  105. data/node_modules/govuk-frontend/govuk/components/input/macro-options.json +6 -0
  106. data/node_modules/govuk-frontend/govuk/components/input/template.njk +1 -0
  107. data/node_modules/govuk-frontend/govuk/components/radios/radios.js +76 -28
  108. data/node_modules/govuk-frontend/govuk/components/select/_index.scss +0 -3
  109. data/node_modules/govuk-frontend/govuk/components/skip-link/_index.scss +1 -0
  110. data/node_modules/govuk-frontend/govuk/components/textarea/_index.scss +0 -3
  111. data/node_modules/govuk-frontend/govuk/components/textarea/macro-options.json +6 -0
  112. data/node_modules/govuk-frontend/govuk/components/textarea/template.njk +1 -0
  113. data/node_modules/govuk-frontend/govuk/components/warning-text/_index.scss +4 -2
  114. data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +1 -1
  115. data/node_modules/govuk-frontend/govuk/settings/_colours-applied.scss +2 -2
  116. data/node_modules/govuk-frontend/govuk/settings/_colours-palette.scss +33 -33
  117. data/node_modules/govuk-frontend/govuk/settings/_measurements.scss +4 -1
  118. data/node_modules/govuk-frontend/package.json +14 -81
  119. data/node_modules/jquery/package.json +44 -116
  120. metadata +34 -66
  121. data/Rakefile +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d31d1f48a5d3491e568c0412fdbbcfaf2e1a98a71aaf84ff703556e83a19b6b
4
- data.tar.gz: 45ecc8d0b068dd621f3a5a4fb2b4add39f542cfe14ba22f5a2e9828ae9638438
3
+ metadata.gz: f4c9abac7ca4bd7fddce284eb7db5799cf1c199bf9d43f8c31ee4782819b2b47
4
+ data.tar.gz: 2c575f2e706736d81d753319b8e62166e1bcb4cc88e79db347b3db525e830ba9
5
5
  SHA512:
6
- metadata.gz: 89fd3c928d07a3cda0079255ea980e7731bda3eb1b9033eeba53131f85f05c12a9073334b17a04b86c050ddd5329fcef28be3ced3373137b6c4385cefb1070aa
7
- data.tar.gz: 82d9e99c1d65f4441404f8a76c18ccc11a3357250ac579bdd6844e8f0b57c63d41dfca449cb848b3f86e37576c7e5dcd6eb3e373860c5d1814882ac52a6d3052
6
+ metadata.gz: 508bb0c589fedfe9131f2a9967b6a1d1622d11b1081d412efc0ecec97fa82225576e708f265db1325840db853a6a24ffc775eeb703642256188c251742e1673a
7
+ data.tar.gz: 9b5670401480fd7bd8cc49805729151487802bb8ec3c2d189822b3f4b595f048fa0521a82bc3f9c489d244ae22756b69f9fb2b84621979a37d8cb45dc7ec7f23
data/README.md CHANGED
@@ -35,7 +35,7 @@ There are 2 types of helper classes in this app:
35
35
 
36
36
  ## Relationship with GOV.UK Design System
37
37
 
38
- GOV.UK Publishing Components also makes [GOV.UK Design System](https://design-system.service.gov.uk/) styles and components available to GOV.UK's frontend applications. This gem consumes [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend) via [NPM](https://www.npmjs.com/).
38
+ GOV.UK Publishing Components also makes [GOV.UK Design System](https://design-system.service.gov.uk/) styles and components available to GOV.UK's frontend applications. This gem consumes [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend) via [Yarn](https://classic.yarnpkg.com/).
39
39
 
40
40
  ## Browser and assistive technology support
41
41
  GOV.UK Publishing Components shares the same standards in terms of browser and assistive technology support with [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend#browser-and-assistive-technology-support).
@@ -44,20 +44,27 @@ GOV.UK Publishing Components shares the same standards in terms of browser and a
44
44
 
45
45
  [See the rubydoc.info documentation](http://www.rubydoc.info/gems/govuk_publishing_components)
46
46
 
47
- Run the documentation locally with:
47
+
48
+ ## Working locally
49
+
50
+ ### Install dependencies
51
+
52
+ As well as the Ruby, you will also need the [Yarn package manager](https://classic.yarnpkg.com/en/docs/install/) to allow installing [npm](https://npmjs.com) dependencies.
53
+
54
+ Install the application's dependencies with:
48
55
 
49
56
  ```sh
50
- bundle exec yard server --reload
57
+ bundle install
58
+ yarn install
51
59
  ```
52
60
 
53
- ## Running tests
61
+ ### Running tests
54
62
 
55
- The default rake task runs all tests:
63
+ The default rake task runs all the linting and test tasks:
56
64
 
57
65
  ```sh
58
66
  bin/rake
59
67
  ```
60
-
61
68
  Javascript is tested using Jasmine and the [Jasmine gem](https://github.com/pivotal/jasmine-gem). Tests can be run either in the browser or on the command line via the dummy app’s tasks:
62
69
 
63
70
  ```sh
@@ -68,6 +75,24 @@ bin/rake app:jasmine
68
75
  bin/rake app:jasmine:ci
69
76
  ```
70
77
 
78
+ ### Viewing the component guide
79
+
80
+ View the component guide in your browser with:
81
+
82
+ ```sh
83
+ ./startup.sh
84
+ ```
85
+
86
+ The guide should be available at http://localhost:3212
87
+
88
+ ### View documentation
89
+
90
+ Preview documentation in your browser with:
91
+
92
+ ```sh
93
+ bundle exec yard server --reload
94
+ ```
95
+
71
96
  ## Licence
72
97
 
73
98
  [MIT Licence](LICENCE.md)
@@ -31,23 +31,23 @@
31
31
 
32
32
  axe.run(selector, axeOptions, function (err, results) {
33
33
  if (err) {
34
- return callback('aXe Error: ' + err)
34
+ return callback(new Error('aXe Error: ' + err))
35
35
  }
36
36
 
37
- if (typeof results === "undefined") {
38
- return callback('aXe Error: Expected results but none returned')
37
+ if (typeof results === 'undefined') {
38
+ return callback(new Error('aXe Error: Expected results but none returned'))
39
39
  }
40
40
 
41
41
  var consoleErrorText = _consoleErrorText(results.violations, results.url)
42
- var bodyClass = results.violations.length === 0 ? "js-test-a11y-success" : "js-test-a11y-failed"
43
- document.body.classList.add(bodyClass);
44
- document.body.classList.add("js-test-a11y-finished");
42
+ var bodyClass = results.violations.length === 0 ? 'js-test-a11y-success' : 'js-test-a11y-failed'
43
+ document.body.classList.add(bodyClass)
44
+ document.body.classList.add('js-test-a11y-finished')
45
45
 
46
46
  callback(undefined, consoleErrorText, _processAxeResultsForPage(results))
47
47
  })
48
48
  }
49
49
 
50
- var _consoleErrorText = function(violations, url) {
50
+ var _consoleErrorText = function (violations, url) {
51
51
  if (violations.length !== 0) {
52
52
  return (
53
53
  '\n' + 'Accessibility issues at ' +
@@ -69,28 +69,28 @@
69
69
  }
70
70
  }
71
71
 
72
- var _processAxeResultsForPage = function(results) {
72
+ var _processAxeResultsForPage = function (results) {
73
73
  return {
74
74
  violations: _mapSummaryAndCause(results.violations),
75
75
  incompleteWarnings: _mapSummaryAndCause(results.incomplete)
76
76
  }
77
77
  }
78
78
 
79
- var _mapSummaryAndCause = function(resultsArray) {
79
+ var _mapSummaryAndCause = function (resultsArray) {
80
80
  return resultsArray.map(function (result) {
81
81
  var cssSelector = result.nodes.map(function (node) {
82
- return {
83
- 'selector': node.target,
84
- 'reasons': node.any.map(function(item) {
85
- return item.message
86
- })
87
- }
88
- })
82
+ return {
83
+ selector: node.target,
84
+ reasons: node.any.map(function (item) {
85
+ return item.message
86
+ })
87
+ }
88
+ })
89
89
  return {
90
- 'id': result.id,
91
- 'summary': result.help,
92
- 'selectors': cssSelector,
93
- 'url': result.helpUrl
90
+ id: result.id,
91
+ summary: result.help,
92
+ selectors: cssSelector,
93
+ url: result.helpUrl
94
94
  }
95
95
  })
96
96
  }
@@ -127,7 +127,7 @@
127
127
  // Section to announce the overall problem.
128
128
  var headerNodeLink = document.createElement('a')
129
129
  headerNodeLink.href = result.url
130
- headerNodeLink.textContent = "(see guidance)"
130
+ headerNodeLink.textContent = '(see guidance)'
131
131
 
132
132
  var headerNode = document.createElement('h3')
133
133
  headerNode.textContent = result.summary + ' (' + result.id + ') '
@@ -1,35 +1,35 @@
1
- (function() {
2
- window.GOVUK = window.GOVUK || {};
1
+ (function () {
2
+ window.GOVUK = window.GOVUK || {}
3
3
 
4
- window.GOVUK.FilterComponents = function filterList(searchTerm) {
5
- var itemsToFilter = document.querySelectorAll('.component-list li');
4
+ window.GOVUK.FilterComponents = function filterList (searchTerm) {
5
+ var itemsToFilter = document.querySelectorAll('.component-list li')
6
6
 
7
- for (var i = 0; i < itemsToFilter.length; i++ ) {
8
- var currentComponent = itemsToFilter[i];
9
- var componentText = currentComponent.innerText.toLowerCase();
7
+ for (var i = 0; i < itemsToFilter.length; i++) {
8
+ var currentComponent = itemsToFilter[i]
9
+ var componentText = currentComponent.innerText.toLowerCase()
10
10
 
11
11
  if (componentText.includes(searchTerm.toLowerCase())) {
12
- currentComponent.classList.remove('component-guide-hidden');
12
+ currentComponent.classList.remove('component-guide-hidden')
13
13
  } else {
14
- currentComponent.classList.add('component-guide-hidden');
14
+ currentComponent.classList.add('component-guide-hidden')
15
15
  }
16
16
  }
17
- };
17
+ }
18
18
 
19
- var formElement = document.querySelector('[data-module=filter-components]');
19
+ var formElement = document.querySelector('[data-module=filter-components]')
20
20
 
21
21
  if (formElement) {
22
- var searchField = formElement.querySelector('input');
22
+ var searchField = formElement.querySelector('input')
23
23
 
24
24
  // We don't want the form to submit/refresh the page on enter key
25
- formElement.addEventListener('submit', function(e) { e.preventDefault(); });
25
+ formElement.addEventListener('submit', function (e) { e.preventDefault() })
26
26
 
27
- searchField.addEventListener('input', function(e) {
28
- var searchTerm = searchField.value;
29
- window.GOVUK.FilterComponents(searchTerm);
30
- });
27
+ searchField.addEventListener('input', function (e) {
28
+ var searchTerm = searchField.value
29
+ window.GOVUK.FilterComponents(searchTerm)
30
+ })
31
31
 
32
32
  // trigger search if search query exists in query string on page load
33
- window.GOVUK.FilterComponents(searchField.value);
33
+ window.GOVUK.FilterComponents(searchField.value)
34
34
  }
35
- })();
35
+ })()
@@ -2,69 +2,70 @@
2
2
  window.GOVUK = window.GOVUK || {}
3
3
 
4
4
  window.GOVUK.VisualDiffTool = function (currentWindowLocation) {
5
- var visualDiffSelector = 'visual-diff';
6
- var existingIframe = document.getElementById(visualDiffSelector);
7
- var windowLocation = currentWindowLocation || window.location;
5
+ var visualDiffSelector = 'visual-diff'
6
+ var existingIframe = document.getElementById(visualDiffSelector)
7
+ var windowLocation = currentWindowLocation || window.location
8
8
 
9
9
  if (existingIframe) {
10
- existingIframe.parentNode.removeChild(existingIframe);
11
- document.body.style.filter = null;
10
+ existingIframe.parentNode.removeChild(existingIframe)
11
+ document.body.style.filter = null
12
12
  } else {
13
- var iframe = document.createElement('iframe');
14
- iframe.id = visualDiffSelector;
15
- iframe.setAttribute('scrolling', 'no');
13
+ var iframe = document.createElement('iframe')
14
+ iframe.id = visualDiffSelector
15
+ iframe.setAttribute('scrolling', 'no')
16
16
  _setElementStyles(iframe, {
17
- 'width': '100%',
18
- 'height': document.body.scrollHeight + 'px',
19
- 'position': 'absolute',
20
- 'top': '0',
17
+ width: '100%',
18
+ height: document.body.scrollHeight + 'px',
19
+ position: 'absolute',
20
+ top: '0',
21
21
  'pointer-events': 'none',
22
- 'border': '0'
23
- });
24
- iframe.style.setProperty('z-index', '999','important');
22
+ border: '0'
23
+ })
24
+ iframe.style.setProperty('z-index', '999', 'important')
25
25
 
26
26
  // For browsers that support it, do mix-blend-mode diff
27
27
  if ('mix-blend-mode' in document.body.style) {
28
- _setElementStyles(iframe, {'mix-blend-mode': 'difference'});
29
- document.body.style.filter = 'invert(100%)';
28
+ _setElementStyles(iframe, { 'mix-blend-mode': 'difference' })
29
+ document.body.style.filter = 'invert(100%)'
30
30
  } else {
31
31
  // Else do a simple overlay of the live page for comparison (IE and Edge)
32
- _setElementStyles(iframe, {'opacity': '0.7'});
32
+ _setElementStyles(iframe, { opacity: '0.7' })
33
33
  }
34
34
 
35
- iframe.src = _processComparisonURL(windowLocation);
35
+ iframe.src = _processComparisonURL(windowLocation)
36
36
 
37
37
  if (iframe.src) {
38
- document.body.appendChild(iframe);
39
- console.log("comparing to " + iframe.src);
38
+ document.body.appendChild(iframe)
39
+ console.log('comparing to ' + iframe.src)
40
40
  }
41
41
  }
42
- };
42
+ }
43
43
 
44
44
  var _processComparisonURL = function (url) {
45
- var href = url.href;
46
- var host = url.host;
45
+ var appName
46
+ var href = url.href
47
+ var host = url.host
47
48
 
48
49
  if (href.includes('dev.gov.uk/component-guide')) {
49
- var appName = host.split('.')[0];
50
- return _forceHTTPS(href.replace(host, appName + '.herokuapp.com'));
50
+ appName = host.split('.')[0]
51
+ return _forceHTTPS(href.replace(host, appName + '.herokuapp.com'))
51
52
  } else if (href.includes('dev.gov.uk')) {
52
- return _forceHTTPS(href.replace(host, 'www.gov.uk'));
53
+ return _forceHTTPS(href.replace(host, 'www.gov.uk'))
53
54
  } else if (href.includes('-pr-')) {
54
- var appName = host.split('-pr')[0];
55
- return _forceHTTPS(href.replace(host, appName + '.herokuapp.com'));
55
+ appName = host.split('-pr')[0]
56
+ return _forceHTTPS(href.replace(host, appName + '.herokuapp.com'))
56
57
  } else {
57
- throw new Error('Visual Diff Tool: You need to run this tool against a page running on your local dev environment');
58
+ throw new Error('Visual Diff Tool: You need to run this tool against a page running on your local dev environment')
58
59
  }
59
- };
60
+ }
60
61
 
61
- var _forceHTTPS = function(href) {
62
- return href.replace('http://', 'https://');
62
+ var _forceHTTPS = function (href) {
63
+ return href.replace('http://', 'https://')
63
64
  }
64
65
 
65
- var _setElementStyles = function(element, styles) {
66
+ var _setElementStyles = function (element, styles) {
66
67
  for (var style in styles) {
67
- element.style[style] = styles[style];
68
+ element.style[style] = styles[style]
68
69
  }
69
- };
70
- })(window, document);
70
+ }
71
+ })(window, document)
@@ -1,94 +1,123 @@
1
1
  /* eslint-env jquery */
2
+ // = require govuk/vendor/polyfills/Element/prototype/closest.js
2
3
  // = require govuk/components/checkboxes/checkboxes.js
3
4
  window.GOVUK = window.GOVUK || {}
4
5
  window.GOVUK.Modules = window.GOVUK.Modules || {}
5
6
  window.GOVUK.Modules.Checkboxes = window.GOVUKFrontend;
6
7
 
7
8
  (function (Modules) {
8
- 'use strict'
9
-
10
- Modules.GovukCheckboxes = function () {
11
- this.start = function (scope) {
12
- var _this = this
13
- this.applyAriaControlsAttributes(scope)
14
-
15
- $(scope).on('change', '[data-nested=true] input[type=checkbox]', function (e) {
16
- var checkbox = e.target
17
- var isNested = $(checkbox).closest('.govuk-checkboxes--nested')
18
- var hasNested = $('.govuk-checkboxes--nested[data-parent=' + checkbox.id + ']')
19
-
20
- if (hasNested.length) {
21
- _this.toggleNestedCheckboxes(hasNested, checkbox)
22
- } else if (isNested.length) {
23
- _this.toggleParentCheckbox(isNested, checkbox)
24
- }
25
- })
26
-
27
- $(scope).on('change', 'input[type=checkbox]', function (e) {
28
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
29
- // where checkboxes are manipulated externally in finders, suppressAnalytics
30
- // is passed to prevent duplicate GA events
31
- if (typeof e.suppressAnalytics === 'undefined' || e.suppressAnalytics !== true) {
32
- var $checkbox = $(e.target)
33
- var category = $checkbox.data('track-category')
34
- if (typeof category !== 'undefined') {
35
- var isChecked = $checkbox.is(':checked')
36
- var uncheckTrackCategory = $checkbox.data('uncheck-track-category')
37
- if (!isChecked && typeof uncheckTrackCategory !== 'undefined') {
38
- category = uncheckTrackCategory
39
- }
40
- var action = $checkbox.data('track-action')
41
- var options = $checkbox.data('track-options')
42
- if (typeof options !== 'object' || options === null) {
43
- options = {}
44
- }
45
- options['value'] = $checkbox.data('track-value')
46
- options['label'] = $checkbox.data('track-label')
47
- window.GOVUK.analytics.trackEvent(category, action, options)
48
- }
9
+ function GovukCheckboxes () { }
10
+
11
+ GovukCheckboxes.prototype.start = function ($module) {
12
+ this.$module = $module[0]
13
+ this.$checkboxes = this.$module.querySelectorAll('input[type=checkbox]')
14
+ this.$nestedCheckboxes = this.$module.querySelectorAll('[data-nested=true] input[type=checkbox]')
15
+ this.$exclusiveCheckboxes = this.$module.querySelectorAll('[data-exclusive=true] input[type=checkbox]')
16
+
17
+ this.applyAriaControlsAttributes(this.$module)
18
+
19
+ for (var i = 0; i < this.$checkboxes.length; i++) {
20
+ this.$checkboxes[i].addEventListener('change', this.handleCheckboxChange)
21
+ }
22
+
23
+ for (i = 0; i < this.$nestedCheckboxes.length; i++) {
24
+ this.$nestedCheckboxes[i].addEventListener('change', this.handleNestedCheckboxChange.bind(this))
25
+ }
26
+
27
+ for (i = 0; i < this.$exclusiveCheckboxes.length; i++) {
28
+ this.$exclusiveCheckboxes[i].addEventListener('change', this.handleExclusiveCheckboxChange)
29
+ }
30
+ }
31
+
32
+ GovukCheckboxes.prototype.handleCheckboxChange = function (event) {
33
+ if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
34
+ // Where checkboxes are manipulated externally in finders, `suppressAnalytics`
35
+ // is passed to prevent duplicate GA events.
36
+ if (!event.detail || (event.detail && event.detail.suppressAnalytics !== true)) {
37
+ var $checkbox = event.target
38
+ var category = $checkbox.getAttribute('data-track-category')
39
+ if (category) {
40
+ var uncheckTrackCategory = $checkbox.getAttribute('data-uncheck-track-category')
41
+ if (!$checkbox.checked && uncheckTrackCategory) {
42
+ category = uncheckTrackCategory
49
43
  }
44
+ var action = $checkbox.getAttribute('data-track-action')
45
+ var options = $checkbox.getAttribute('data-track-options')
46
+ if (options) {
47
+ options = JSON.parse(options)
48
+ } else {
49
+ options = {}
50
+ }
51
+ options.value = $checkbox.getAttribute('data-track-value')
52
+ options.label = $checkbox.getAttribute('data-track-label')
53
+ window.GOVUK.analytics.trackEvent(category, action, options)
50
54
  }
51
- })
52
-
53
- $(scope).on('change', '[data-exclusive=true] input[type=checkbox]', function (e) {
54
- var currentCheckbox = e.target
55
- var checkboxes = currentCheckbox.closest('.govuk-checkboxes')
56
- var exclusiveOption = $(checkboxes).find('input[type=checkbox][data-exclusive]')
57
- var nonExclusiveOptions = $(checkboxes).find('input[type=checkbox]:not([data-exclusive])')
58
-
59
- if (currentCheckbox.dataset.exclusive === 'true' && currentCheckbox.checked === true) {
60
- nonExclusiveOptions.each(function () {
61
- $(this).prop('checked', false)
62
- })
63
- } else if (currentCheckbox.dataset.exclusive !== 'true' && currentCheckbox.checked === true) {
64
- exclusiveOption.prop('checked', false)
65
- }
66
- })
55
+ }
67
56
  }
57
+ }
68
58
 
69
- this.toggleNestedCheckboxes = function (scope, checkbox) {
70
- if (checkbox.checked) {
71
- scope.find('input[type=checkbox]').prop('checked', true)
72
- } else {
73
- scope.find('input[type=checkbox]').prop('checked', false)
59
+ GovukCheckboxes.prototype.handleNestedCheckboxChange = function (event) {
60
+ var $checkbox = event.target
61
+ var $isNested = $checkbox.closest('.govuk-checkboxes--nested')
62
+ var $hasNested = this.$module.querySelector('.govuk-checkboxes--nested[data-parent=' + $checkbox.id + ']')
63
+
64
+ if ($hasNested) {
65
+ this.toggleNestedCheckboxes($hasNested, $checkbox)
66
+ } else if ($isNested) {
67
+ this.toggleParentCheckbox($isNested, $checkbox)
68
+ }
69
+ }
70
+
71
+ GovukCheckboxes.prototype.toggleNestedCheckboxes = function ($scope, $checkbox) {
72
+ var $nestedCheckboxes = $scope.querySelectorAll('input[type=checkbox]')
73
+ if ($checkbox.checked) {
74
+ for (var i = 0; i < $nestedCheckboxes.length; i++) {
75
+ $nestedCheckboxes[i].checked = true
74
76
  }
77
+ } else {
78
+ for (i = 0; i < $nestedCheckboxes.length; i++) {
79
+ $nestedCheckboxes[i].checked = false
80
+ }
81
+ }
82
+ }
83
+
84
+ GovukCheckboxes.prototype.toggleParentCheckbox = function ($scope, $checkbox) {
85
+ var $inputs = $scope.querySelectorAll('input')
86
+ var $checkedInputs = $scope.querySelectorAll('input:checked')
87
+ var parentId = $scope.getAttribute('data-parent')
88
+ var $parent = document.getElementById(parentId)
89
+
90
+ if ($checkbox.checked && $inputs.length === $checkedInputs.length) {
91
+ $parent.checked = true
92
+ } else {
93
+ $parent.checked = false
75
94
  }
95
+ }
76
96
 
77
- this.toggleParentCheckbox = function (scope, checkbox) {
78
- var siblings = $(checkbox).closest('.govuk-checkboxes__item').siblings()
79
- var parentId = scope.data('parent')
97
+ GovukCheckboxes.prototype.handleExclusiveCheckboxChange = function (event) {
98
+ var $currentCheckbox = event.target
99
+ var $checkboxes = $currentCheckbox.closest('.govuk-checkboxes')
100
+ var $exclusiveOption = $checkboxes.querySelector('input[type=checkbox][data-exclusive]')
101
+ var $nonExclusiveOptions = $checkboxes.querySelectorAll('input[type=checkbox]:not([data-exclusive])')
80
102
 
81
- if (checkbox.checked && siblings.length === siblings.find(':checked').length) {
82
- $('#' + parentId).prop('checked', true)
83
- } else {
84
- $('#' + parentId).prop('checked', false)
103
+ if ($currentCheckbox.dataset.exclusive === 'true' && $currentCheckbox.checked === true) {
104
+ for (var i = 0; i < $nonExclusiveOptions.length; i++) {
105
+ $nonExclusiveOptions[i].checked = false
106
+ }
107
+ } else if ($currentCheckbox.dataset.exclusive !== 'true' && $currentCheckbox.checked === true) {
108
+ if ($exclusiveOption) {
109
+ $exclusiveOption.checked = false
85
110
  }
86
111
  }
112
+ }
113
+
114
+ GovukCheckboxes.prototype.applyAriaControlsAttributes = function ($scope) {
115
+ var $inputs = $scope.querySelectorAll('[data-controls]')
87
116
 
88
- this.applyAriaControlsAttributes = function (scope) {
89
- $(scope).find('[data-controls]').each(function () {
90
- $(this).attr('aria-controls', $(this).attr('data-controls'))
91
- })
117
+ for (var i = 0; i < $inputs.length; i++) {
118
+ $inputs[i].setAttribute('aria-controls', $inputs[i].getAttribute('data-controls'))
92
119
  }
93
120
  }
121
+
122
+ Modules.GovukCheckboxes = GovukCheckboxes
94
123
  })(window.GOVUK.Modules)