66 incompleteData
77} from '../../commons/color' ;
88
9+ import a11y_engine_commons from '../../commons/a11y-engine-index' ;
10+
911function getContrast ( color1 , color2 ) {
1012 var c1lum = color1 . getRelativeLuminance ( ) ;
1113 var c2lum = color2 . getRelativeLuminance ( ) ;
@@ -26,6 +28,7 @@ function isBlock(elm) {
2628}
2729
2830function linkInTextBlockEvaluate ( node ) {
31+ var options = arguments . length > 1 && arguments [ 1 ] ? arguments [ 1 ] : { } ;
2932 if ( isBlock ( node ) ) {
3033 return false ;
3134 }
@@ -37,29 +40,47 @@ function linkInTextBlockEvaluate(node) {
3740
3841 this . relatedNodes ( [ parentBlock ] ) ;
3942
43+ if ( options . a11yRule ) {
44+ return a11y_engine_commons . distinguishableLinkEvaluate ( node , parentBlock ) ;
45+ }
46+
4047 // TODO: Check the :visited state of the link
4148 if ( elementIsDistinct ( node , parentBlock ) ) {
4249 return true ;
4350 } 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+ }
4855
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 ) ;
5261
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 {
6384 return undefined ;
6485 }
6586
@@ -85,10 +106,7 @@ function linkInTextBlockEvaluate(node) {
85106 incompleteData . clear ( ) ;
86107 return undefined ;
87108 }
88- }
89-
90- // TODO: We should check the focus / hover style too
91- return false ;
92109}
93110
94111export default linkInTextBlockEvaluate ;
112+ export { getColorContrast , getContrast }
0 commit comments