6
6
incompleteData
7
7
} from '../../commons/color' ;
8
8
9
+ import { distinguishableLinkEvaluate } from '../../../../a11y-engine-core/lib/commons/distinguishable-link' ;
10
+
9
11
function getContrast ( color1 , color2 ) {
10
12
var c1lum = color1 . getRelativeLuminance ( ) ;
11
13
var c2lum = color2 . getRelativeLuminance ( ) ;
@@ -26,6 +28,7 @@ function isBlock(elm) {
26
28
}
27
29
28
30
function linkInTextBlockEvaluate ( node ) {
31
+ var options = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
29
32
if ( isBlock ( node ) ) {
30
33
return false ;
31
34
}
@@ -37,29 +40,47 @@ function linkInTextBlockEvaluate(node) {
37
40
38
41
this . relatedNodes ( [ parentBlock ] ) ;
39
42
43
+ if ( options . a11yRule ) {
44
+ return distinguishableLinkEvaluate ( node , parentBlock ) ;
45
+ }
46
+
40
47
// TODO: Check the :visited state of the link
41
48
if ( elementIsDistinct ( node , parentBlock ) ) {
42
49
return true ;
43
50
} else {
44
- // Check if contrast of foreground is sufficient
45
- var nodeColor , parentColor ;
46
- nodeColor = getForegroundColor ( node ) ;
47
- parentColor = getForegroundColor ( parentBlock ) ;
51
+ // TODO: We should check the focus / hover style too
52
+ return checkContrast ( node , parentBlock ) ;
53
+ }
54
+ }
48
55
49
- if ( ! nodeColor || ! parentColor ) {
50
- return undefined ;
51
- }
56
+ function getColorContrast ( node , parentBlock ) {
57
+ // Check if contrast of foreground is sufficient
58
+ var nodeColor , parentColor ;
59
+ nodeColor = getForegroundColor ( node ) ;
60
+ parentColor = getForegroundColor ( parentBlock ) ;
52
61
53
- var contrast = getContrast ( nodeColor , parentColor ) ;
54
- if ( contrast === 1 ) {
55
- return true ;
56
- } else if ( contrast >= 3.0 ) {
57
- incompleteData . set ( 'fgColor' , 'bgContrast' ) ;
58
- this . data ( {
59
- messageKey : incompleteData . get ( 'fgColor' )
60
- } ) ;
61
- incompleteData . clear ( ) ;
62
- // User needs to check whether there is a hover and a focus style
62
+ if ( ! nodeColor || ! parentColor ) {
63
+ return undefined ;
64
+ }
65
+
66
+ return getContrast ( nodeColor , parentColor ) ;
67
+ }
68
+
69
+ function checkContrast ( node , parentBlock ) {
70
+ var contrast = getColorContrast ( node , parentBlock ) ;
71
+ if ( contrast !== undefined ) {
72
+ if ( contrast === 1 ) {
73
+ return true ;
74
+ } else if ( contrast >= 3.0 ) {
75
+ incompleteData . set ( 'fgColor' , 'bgContrast' ) ;
76
+ this . data ( {
77
+ messageKey : incompleteData . get ( 'fgColor' )
78
+ } ) ;
79
+ incompleteData . clear ( ) ;
80
+ // User needs to check whether there is a hover and a focus style
81
+ return undefined ;
82
+ }
83
+ } else {
63
84
return undefined ;
64
85
}
65
86
@@ -85,10 +106,7 @@ function linkInTextBlockEvaluate(node) {
85
106
incompleteData . clear ( ) ;
86
107
return undefined ;
87
108
}
88
- }
89
-
90
- // TODO: We should check the focus / hover style too
91
- return false ;
92
109
}
93
110
94
111
export default linkInTextBlockEvaluate ;
112
+ export { getColorContrast , getContrast }
0 commit comments