1- < html >
2- < script src ="math.js "> </ script >
3- < script src ="conversions.js "> </ script >
4- < script src ="utilities.js "> </ script >
5- < script >
6- // read the foreground abd background colors
7- // then use the contrast() utility function
8- // to compute WCAG contrast.
9-
10- var back , fore , bgcol , fgcol ;
11- window . addEventListener ( "load" , startup , false ) ;
12-
13- function startup ( ) {
14- back = document . querySelector ( #fg) ;
15- fore = document . querySelector ( #bg) ;
16- back . addEventListener ( "input" , watchpickers , false ) ;
17- fore . addEventListener ( "input" , watchpickers , false ) ;
18- }
19-
20- function watchpickers ( event ) {
21- // if either picker changes, update the two colors
22- // and output the contrast ratio
23-
24- var contrast = document . querySelector ( "result>span" ) ;
25- bgcol = event . target . value ;
26- fgcol =
27- }
28- </ script >
29- < style >
30- body {background-color : rgb (46.6346021727084% , 46.6346021727084% , 46.6346021727084% ); padding : 20px ;}
31- h2 {color : rgb (243 , 235 , 166 );}
32- </ style >
33- < h2 > Contrast ratio of two colors</ h2 >
34- < p > Pick a foreground and background color</ p >
35- < input type ="color " id ="fg " value ="#B7C9A3 ">
36- < label for ="fg "> Foreground</ label >
37- < input type ="color " id ="fg " value ="#104425 ">
38- < label for ="fg "> Background</ label >
39-
40- < div id ="result ">
41- Contrast ratio < span > </ span > .
42- </ div >
1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+
5+ < script src ="math.js "> </ script >
6+ < script src ="conversions.js "> </ script >
7+ < script src ="utilities.js "> </ script >
8+
9+ < style >
10+ body {background-color : rgb (46.6346021727084% , 46.6346021727084% , 46.6346021727084% ); padding : 20px ;}
11+ h2 {color : rgb (243 , 235 , 166 );}
12+ </ style >
13+
14+ </ head >
15+ < body >
16+
17+ < h2 > Contrast ratio of two colors</ h2 >
18+ < p > Pick a foreground and background color</ p >
19+
20+ < input type ="color " id ="fg " value ="#B7C9A3 ">
21+ < label for ="fg "> Foreground</ label >
22+ < input type ="color " id ="bg " value ="#104425 ">
23+ < label for ="bg "> Background</ label >
24+
25+ < div id ="result ">
26+ Contrast ratio < output id ="contrastResult "> </ output > .
27+ </ div >
28+
29+
30+ < script >
31+ // read the foreground and background colors
32+ // then use the contrast() utility function
33+ // to compute WCAG contrast.
34+
35+ var fgInput = document . querySelector ( "#fg" ) ;
36+ var bgInput = document . querySelector ( "#bg" ) ;
37+ var contrastOutput = document . querySelector ( "#contrastResult" ) ;
38+ var bgColor , fgColor ;
39+
40+ // if any picker changes, update the color
41+ // and output the contrast ratio
42+ ( fgInput . oninput = bgInput . oninput = function ( event ) {
43+ bgColor = hexToArray ( bgInput . value ) ;
44+ fgColor = hexToArray ( fgInput . value ) ;
45+ console . log ( "watch" , bgColor , fgColor ) ;
46+ contrastOutput . value = contrast ( bgColor , fgColor ) ;
47+ // convert from string to array of number
48+ // compute contrast
49+ // update span
50+ } ) ( ) ;
51+
52+
53+
54+ function hexToArray ( hex ) {
55+ return hex . match ( / [ \d A - F ] { 2 } / ig) . map ( x => parseInt ( x , 16 ) / 255 ) ;
56+ }
57+
58+ </ script >
59+
60+ </ body >
4361
4462</ html >
0 commit comments