govuk_publishing_components 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af16bdb3cf4e7f4353eb49094b958b1ad1eab6f6
4
- data.tar.gz: 211f3d355a205409e8217c7bdb088ddda67a0a08
3
+ metadata.gz: 6d096d826f4036a0b4d935adcb65e7046e30c036
4
+ data.tar.gz: 73166cb75dbfdda9d960f790c6f4f0833ffdc800
5
5
  SHA512:
6
- metadata.gz: 48333dcb9f5ca4f68cce6b8ef536a8c01640450cf27892b784f455900cb6fbb58cfa072e785a8b816be068c0f1db1e07d35562b25fa1925523f465daf868fd65
7
- data.tar.gz: cc2659ab75afb0723c95c6f100c8dbb49be917cf6b849e478e4fb8d812306dbcc1a011c0bb52f8f6693bea134d91aa518a70755bb8aa52d5ac925024952d3e17
6
+ metadata.gz: 0f40af4038b72fb80da00abb67fc9fb944495df6006a5b4609e650819717a291f30c8cb17908d17298fbdc0740c891e1d36a9fc9f13438520553040472e412ca
7
+ data.tar.gz: 35d8bb1bc8d0812eb6bfe580c0edf05c015bf40eb980d64d015d0f99fbe5a161bb073922b72261f5c202f7236dc51bca8711419d4fdda2bc5e262dc8e0659843
@@ -21,14 +21,24 @@
21
21
  }
22
22
 
23
23
  var violations = (typeof results === 'undefined') ? [] : results.violations
24
+ var incompleteWarnings = (typeof results === 'undefined') ? [] : results.incomplete
24
25
 
25
- if (violations.length === 0) {
26
+ if (violations.length === 0 && incompleteWarnings.length === 0) {
26
27
  return callback('No accessibility issues found')
27
28
  }
28
29
 
29
- var errorText = (
30
+ var incompleteWarningsObj = _processIncompleteWarnings(incompleteWarnings)
31
+ var errorText = _processViolations(violations, results.url)
32
+
33
+ callback(undefined, errorText, incompleteWarningsObj)
34
+ })
35
+ }
36
+
37
+ var _processViolations = function(violations, url) {
38
+ if (violations.length !== 0) {
39
+ return (
30
40
  '\n' + 'Accessibility issues at ' +
31
- results.url + '\n\n' +
41
+ url + '\n\n' +
32
42
  violations.map(function (violation) {
33
43
  var help = 'Problem: ' + violation.help
34
44
  var helpUrl = 'Try fixing it with this help: ' + _formatHelpUrl(violation.helpUrl)
@@ -41,8 +51,33 @@
41
51
  ].join('\n\n\n')
42
52
  }).join('\n\n- - -\n\n')
43
53
  )
44
- callback(undefined, errorText)
45
- })
54
+ }
55
+ else {
56
+ console.info("aXe: No accessibility errors found")
57
+ }
58
+ }
59
+
60
+ var _processIncompleteWarnings = function(incompleteWarnings) {
61
+ return (
62
+ incompleteWarnings.map(function (incomplete) {
63
+ var help = incomplete.help
64
+ var helpUrl = _formatHelpUrl(incomplete.helpUrl)
65
+ var cssSelector = incomplete.nodes.map(function (node) {
66
+ return {
67
+ 'selector': node.target,
68
+ 'reason': node.any.map(function(item) {
69
+ return item.message
70
+ })
71
+ }
72
+ })
73
+
74
+ return {
75
+ 'summary': help,
76
+ 'selectors': cssSelector,
77
+ 'url': helpUrl
78
+ }
79
+ })
80
+ )
46
81
  }
47
82
 
48
83
  var _formatHelpUrl = function (helpUrl) {
@@ -62,6 +97,36 @@
62
97
  )
63
98
  }
64
99
 
100
+ var _findParent = function (element, selector) {
101
+ while (element.tagName !== 'HTML') {
102
+ if (element.matches(selector)) {
103
+ return element
104
+ }
105
+ element = element.parentNode
106
+ }
107
+ }
108
+
109
+ var _renderIncompleteWarnings = function (incompleteWarnings) {
110
+ incompleteWarnings.forEach(function (warning) {
111
+ warning.selectors.forEach(function (selectorObj) {
112
+ var activeEl = document.querySelector(selectorObj.selector)
113
+ var activeElParent = _findParent(activeEl, '[data-module="test-a11y"]')
114
+ var warningWrapper = activeElParent.querySelector('[data-module="test-a11y-warning"]')
115
+
116
+ if (warningWrapper) {
117
+ // Add warning to warnings box
118
+ var warningsHTML = '<h3>' + warning.summary + ' <a href="' + warning.url + '">(see guidance)</a></h3>' +
119
+ '<p>Reason: ' + selectorObj.reason + '</p>' +
120
+ '<p>Element can be found using the following CSS selector: <span class="selector">' +
121
+ selectorObj.selector +
122
+ '</span></p>'
123
+
124
+ warningWrapper.insertAdjacentHTML('beforeend', warningsHTML)
125
+ }
126
+ })
127
+ })
128
+ }
129
+
65
130
  var _throwUncaughtError = function (error) {
66
131
  // aXe swallows throw errors so we pass it through a setTimeout
67
132
  // so that it's not in aXe's context
@@ -76,11 +141,12 @@
76
141
  // http://responsivenews.co.uk/post/18948466399/cutting-the-mustard
77
142
  if (document.addEventListener) {
78
143
  document.addEventListener('DOMContentLoaded', function () {
79
- AccessibilityTest('[data-module="test-a11y"]', function (err, results) {
144
+ AccessibilityTest('[data-module="test-a11y"]', function (err, violations, incompleteWarnings) {
80
145
  if (err) {
81
146
  return
82
147
  }
83
- _throwUncaughtError(results)
148
+ if (incompleteWarnings) _renderIncompleteWarnings(incompleteWarnings)
149
+ if (violations) _throwUncaughtError(violations)
84
150
  })
85
151
  })
86
152
  }
@@ -116,13 +116,14 @@ $border-color: #ccc;
116
116
 
117
117
  &:before {
118
118
  @include core-14;
119
- content: "EXAMPLE";
119
+ content: attr(data-content);
120
120
  position: absolute;
121
121
  top: 0;
122
122
  left: 0;
123
123
  padding: 0.21053em 0.78947em;
124
124
  background: $border-colour;
125
- color: $white;
125
+ color: $black;
126
+ font-weight: bold;
126
127
  }
127
128
 
128
129
  div[class^="govuk-"] {
@@ -133,6 +134,40 @@ $border-color: #ccc;
133
134
  }
134
135
  }
135
136
 
137
+ .component-guide-preview--simple {
138
+ border: 0;
139
+ padding: 0;
140
+
141
+ &:before {
142
+ display: none;
143
+ }
144
+ }
145
+
146
+ .component-guide-preview--warning {
147
+ margin-top: $gutter-half;
148
+ border-color: $yellow;
149
+
150
+ &:empty {
151
+ display: none;
152
+ }
153
+
154
+ &:before {
155
+ background-color: $yellow;
156
+ }
157
+
158
+ h3 {
159
+ @include bold-16;
160
+ }
161
+
162
+ h3:not(:first-child) {
163
+ margin-top: $gutter;
164
+ }
165
+
166
+ .selector {
167
+ font-style: italic;
168
+ }
169
+ }
170
+
136
171
  .examples {
137
172
  .component-example {
138
173
  margin: 0 0 $gutter * 1.5;
@@ -0,0 +1,5 @@
1
+ <div class="component-guide-preview
2
+ <% if example.right_to_left? %>direction-rtl<% end %>
3
+ <% if preview_page %>component-guide-preview--simple<% end %>" data-content="EXAMPLE">
4
+ <%= render component_doc.partial_path, example.html_safe_data %>
5
+ </div>
@@ -1,3 +1,4 @@
1
- <div data-module="test-a11y" class="component-guide-preview <% if example.right_to_left? %>direction-rtl<% end %>">
2
- <%= render component_doc.partial_path, example.html_safe_data %>
1
+ <div data-module="test-a11y">
2
+ <%= render "govuk_publishing_components/component_guide/component_doc/component", component_doc: @component_doc, example: example, preview_page: false %>
3
+ <div class="component-guide-preview component-guide-preview--warning" data-module="test-a11y-warning" data-content="Potential Accessibility Issues: Need Manual Check"></div>
3
4
  </div>
@@ -3,6 +3,8 @@
3
3
  <% if @component_examples.length > 1 %>
4
4
  <h2 class="preview-title"><a href="<%= component_example_path(@component_doc.id, example.id) %>"><%= example.name %></a></h2>
5
5
  <% end %>
6
- <%= render "govuk_publishing_components/component_guide/component_doc/preview", component_doc: @component_doc, example: example %>
6
+ <div data-module="test-a11y">
7
+ <%= render "govuk_publishing_components/component_guide/component_doc/component", component_doc: @component_doc, example: example, preview_page: true %>
8
+ </div>
7
9
  </div>
8
10
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-31 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -187,6 +187,7 @@ files:
187
187
  - app/models/govuk_publishing_components/component_doc_resolver.rb
188
188
  - app/models/govuk_publishing_components/component_example.rb
189
189
  - app/views/govuk_publishing_components/component_guide/component_doc/_call.html.erb
190
+ - app/views/govuk_publishing_components/component_guide/component_doc/_component.html.erb
190
191
  - app/views/govuk_publishing_components/component_guide/component_doc/_preview.html.erb
191
192
  - app/views/govuk_publishing_components/component_guide/example.html.erb
192
193
  - app/views/govuk_publishing_components/component_guide/index.html.erb