-
Notifications
You must be signed in to change notification settings - Fork 3
/
2_4_12_FocusAppearanceEnhanced(AAA).js
executable file
·197 lines (188 loc) · 9.22 KB
/
2_4_12_FocusAppearanceEnhanced(AAA).js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
setTimeout(() => {
FocusAppearanceEnhanced()
}, 15000);
function FocusAppearanceEnhanced() {
$.fn.log = function () {
console.log.apply(console, this);
return this;
};
$(document).ready(function () {
$('*').each(function () {
if ($(this).prop("tagName") != "HTML" &&
$(this).prop("tagName") != "BODY" &&
$(this).prop("tagName") != "LINK" &&
$(this).prop("tagName") != "SCRIPT" &&
$(this).prop("tagName") != "STYLE" &&
$(this).prop("tagName") != "XML" &&
$(this).prop("tagName") != "HEAD" &&
$(this).prop("tagName") != "TITLE" &&
$(this).prop("tagName") != "NOSCRIPT" &&
$(this).prop("tagName") != "META") {
var outW1 = $(this).css("outlineWidth")
outW1 = parseInt(outW1.toString().split("px")[0])
var outW2 = $(this).focus().css("outlineWidth")
outW2 = parseInt(outW1.toString().split("px")[0])
var clientPerimeter = 2 * 2 * (this.clientHeight + this.clientWidth)
var offsetPerimeter = 2 * (this.offsetWidth + this.offsetHeight)
offsetPerimeter = offsetPerimeter * outW2
var color1 = $(this).focus().css("outline-color")
var color2 = $(this).css("outline-color")
var color3 = $(this).css("backgroundColor")
color1 = color1.toString().split(")")[0].split("(")[1].split(",")
color2 = color2.toString().split(")")[0].split("(")[1].split(",")
color3 = color3.toString().split(")")[0].split("(")[1].split(",")
var contrast1 = contrast(color1, color2)
var contrast2 = contrast(color1, color3)
var contrastGained = contrast1
if (contrastGained < contrast2) {
contrastGained = contrast2
}
if (contrastGained < 4.5) {
console.log("%cRule:%cWCAG 2.4.12 (2.2,AAA)",
`color: #FFF;
background-color: #333;
border-radius: 5px 0px 0px 5px;
padding: 5px 10px;
font-size: 0.8rem;
display: inline;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`,
`color: #FFF;
display: inline;
font-size: 0.8rem;
background-color: #809FFF;
border-radius: 0px 5px 5px 0px;
padding: 5px 10px;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`)
console.log("%cError:%cContrast ratio between colors in focused and unfocused states is less than 4.5",
`color: #FFF;
background-color: #333;
border-radius: 5px 0px 0px 5px;
padding: 5px 10px;
font-size: 0.8rem;
display: inline;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`,
`color: #FFF;
display: inline;
font-size: 0.8rem;
background-color: #EB5177;
border-radius: 0px 5px 5px 0px;
padding: 5px 10px;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`)
console.log("%cCode Snippet:",
`color: #FFF;
background-color: #333;
border-radius: 5px;
padding: 5px 10px;
font-size: 0.8rem;
display: inline;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`)
$(this).log()
console.log("%cFix:%cIncrease contrast ratio atleast to 4.5:1 between colors in focused and unfocused states",
`color: #FFF;
background-color: #333;
border-radius: 5px 0px 0px 5px;
padding: 5px 10px;
font-size: 0.8rem;
display: inline;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`,
`color: #FFF;
display: inline;
font-size: 0.8rem;
background-color: #007075;
border-radius: 0px 5px 5px 0px;
padding: 5px 10px;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`)
console.log("%c-----------------------------------------------------------------------------",
`color: #FFF;
background-color: #293543;
font-weight: bolder;
border-radius: 5px;
padding: 5px 10px;
font-size: 1rem;
display: inline;`)
}
if (offsetPerimeter < clientPerimeter) {
console.log("%cRule:%cWCAG 2.4.12 (2.2,AAA)",
`color: #FFF;
background-color: #333;
border-radius: 5px 0px 0px 5px;
padding: 5px 10px;
font-size: 0.8rem;
display: inline;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`,
`color: #FFF;
display: inline;
font-size: 0.8rem;
background-color: #809FFF;
border-radius: 0px 5px 5px 0px;
padding: 5px 10px;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`)
console.log("%cError:%cThe focus indication area should be greater than or equal to a 2 CSS pixel solid border around the control",
`color: #FFF;
background-color: #333;
border-radius: 5px 0px 0px 5px;
padding: 5px 10px;
font-size: 0.8rem;
display: inline;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`,
`color: #FFF;
display: inline;
font-size: 0.8rem;
background-color: #EB5177;
border-radius: 0px 5px 5px 0px;
padding: 5px 10px;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`)
console.log("%cCode Snippet:",
`color: #FFF;
background-color: #333;
border-radius: 5px;
padding: 5px 10px;
font-size: 0.8rem;
display: inline;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`)
$(this).log()
console.log("%cFix:%cIncrease the focus indication area around the control to atleast a 2 CSS pixel border",
`color: #FFF;
background-color: #333;
border-radius: 5px 0px 0px 5px;
padding: 5px 10px;
font-size: 0.8rem;
display: inline;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`,
`color: #FFF;
display: inline;
font-size: 0.8rem;
background-color: #007075;
border-radius: 0px 5px 5px 0px;
padding: 5px 10px;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);`)
console.log("%c-----------------------------------------------------------------------------",
`color: #FFF;
background-color: #293543;
font-weight: bolder;
border-radius: 5px;
padding: 5px 10px;
font-size: 1rem;
display: inline;`)
}
}
})
})
}
function luminance(r, g, b) {
var a = [r, g, b].map(function (v) {
v /= 255;
return v <= 0.03928
? v / 12.92
: Math.pow((v + 0.055) / 1.055, 2.4);
});
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
}
function contrast(rgb1, rgb2) {
var lum1 = luminance(parseInt(rgb1[0]), parseInt(rgb1[1]), parseInt(rgb1[2]));
var lum2 = luminance(parseInt(rgb2[0]), parseInt(rgb2[1]), parseInt(rgb2[2]));
var brightest = Math.max(lum1, lum2);
var darkest = Math.min(lum1, lum2);
return (brightest + 0.05)
/ (darkest + 0.05);
}