1
- export function scanForProblems ( context , logError , options ) {
1
+ export function scanForProblems ( context , errorCallback , options ) {
2
+ const errors = { }
3
+
4
+ function logError ( err ) {
5
+ const { name} = err
6
+
7
+ errors [ name ] = errors [ name ] || [ ]
8
+ errors [ name ] . push ( err )
9
+
10
+ errorCallback ( err )
11
+ }
12
+
2
13
for ( const img of context . querySelectorAll ( 'img' ) ) {
3
14
if ( ! img . hasAttribute ( 'alt' ) ) {
4
15
logError ( new ImageWithoutAltAttributeError ( img ) )
@@ -31,9 +42,13 @@ export function scanForProblems(context, logError, options) {
31
42
}
32
43
}
33
44
34
- for ( const input of context . querySelectorAll ( 'input[type=text], input[type=url], input[type=search], input[type=number], textarea' ) ) {
45
+ for ( const input of context . querySelectorAll (
46
+ 'input[type=text], input[type=url], input[type=search], input[type=number], textarea'
47
+ ) ) {
35
48
// In case input.labels isn't supported by browser, find the control manually (IE)
36
- const inputLabel = input . labels ? input . labels [ 0 ] : input . closest ( 'label' ) || document . querySelector ( `label[for="${ input . id } "]` )
49
+ const inputLabel = input . labels
50
+ ? input . labels [ 0 ]
51
+ : input . closest ( 'label' ) || document . querySelector ( `label[for="${ input . id } "]` )
37
52
if ( ! inputLabel && ! elementIsHidden ( input ) && ! input . hasAttribute ( 'aria-label' ) ) {
38
53
logError ( new InputMissingLabelError ( input ) )
39
54
}
@@ -47,7 +62,7 @@ export function scanForProblems(context, logError, options) {
47
62
48
63
if ( options && options [ 'ariaPairs' ] ) {
49
64
for ( const selector in options [ 'ariaPairs' ] ) {
50
- const ARIAAttrsRequired = options [ 'ariaPairs' ] [ selector ]
65
+ const ARIAAttrsRequired = options [ 'ariaPairs' ] [ selector ]
51
66
for ( const target of context . querySelectorAll ( selector ) ) {
52
67
const missingAttrs = [ ]
53
68
@@ -61,6 +76,8 @@ export function scanForProblems(context, logError, options) {
61
76
}
62
77
}
63
78
}
79
+
80
+ return errors
64
81
}
65
82
66
83
function errorSubclass ( fn ) {
@@ -157,7 +174,12 @@ function isText(value) {
157
174
function accessibleText ( node ) {
158
175
switch ( node . nodeType ) {
159
176
case Node . ELEMENT_NODE :
160
- if ( isText ( node . getAttribute ( 'alt' ) ) || isText ( node . getAttribute ( 'aria-label' ) ) || isText ( node . getAttribute ( 'title' ) ) ) return true
177
+ if (
178
+ isText ( node . getAttribute ( 'alt' ) ) ||
179
+ isText ( node . getAttribute ( 'aria-label' ) ) ||
180
+ isText ( node . getAttribute ( 'title' ) )
181
+ )
182
+ return true
161
183
for ( let i = 0 ; i < node . childNodes . length ; i ++ ) {
162
184
if ( accessibleText ( node . childNodes [ i ] ) ) return true
163
185
}
0 commit comments