Skip to content

Commit bcfcd6a

Browse files
Implement PR feedback
1 parent 4925f28 commit bcfcd6a

File tree

5 files changed

+137
-124
lines changed

5 files changed

+137
-124
lines changed

HTMLCS.Util.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,5 +1312,59 @@ _global.HTMLCS.util = function() {
13121312
return nextNode;
13131313
};
13141314

1315+
1316+
/**
1317+
* Get the text content of a DOM node.
1318+
*
1319+
* @param {DOMNode} element Element to process.
1320+
*
1321+
* @returns {String} The text content.
1322+
*/
1323+
self.getTextContent = function(element) {
1324+
if (element.textContent !== undefined) {
1325+
return element.textContent;
1326+
} else {
1327+
return element.innerText;
1328+
}
1329+
}
1330+
1331+
1332+
/**
1333+
* Get the accessible name.
1334+
*
1335+
* @param {DOMNode} element Element to process.
1336+
*
1337+
* @returns {String} The accessible name.
1338+
*/
1339+
self.getAccessibleName = function(element) {
1340+
// See https://www.w3.org/TR/accname-1.1/#terminology
1341+
if (self.isVisuallyHidden(element)) {
1342+
return '';
1343+
}
1344+
else if (element.getAttribute("aria-labelledby")) {
1345+
var nameParts = [];
1346+
var parts = element.getAttribute("aria-labelledby").split(" ");
1347+
for (var i = 0; i < parts.length; i++) {
1348+
var x = parts[i];
1349+
var nameElement = top.getElementById(x);
1350+
if (nameElement) {
1351+
nameParts.push(nameElement.textContent);
1352+
}
1353+
}
1354+
return nameParts.join(" ");
1355+
} else if (element.getAttribute("aria-label")) {
1356+
return element.getAttribute("aria-label");
1357+
} else if (element.getAttribute("title")) {
1358+
if (
1359+
element.getAttribute("role") !== "presentation" &&
1360+
element.getAttribute("role") !== "none"
1361+
) {
1362+
return element.getAttribute("aria-label");
1363+
}
1364+
}
1365+
// Give up - we only test the 3 most obvious cases.
1366+
return "";
1367+
}
1368+
13151369
return self;
13161370
}();

Standards/WCAG2AAA/Sniffs/Principle2/Guideline2_5/2_5_2.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle2_Guideline2_5_2_5_2 = {
3434
HTMLCS.addMessage(
3535
HTMLCS.NOTICE,
3636
top,
37-
"Check that for functionality that can be operated using a single pointer, at least one of the following is true: \
38-
<ul> \
39-
<li>No Down-Event: The down-event of the pointer is not used to execute any part of the function;</li> \
40-
<li>Abort or Undo: Completion of the function is on the up-event, and a mechanism is available to abort the function before completion or to undo the function after completion;</li> \
41-
<li>Up Reversal: The up-event reverses any outcome of the preceding down-event;</li> \
42-
<li>Essential: Completing the function on the down-event is essential.</li> \
43-
</ul>",
37+
_global.HTMLCS.getTranslation("2_5_2.SinglePointer_Check"),
4438
""
4539
);
4640

Standards/WCAG2AAA/Sniffs/Principle2/Guideline2_5/2_5_3.js

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,6 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle2_Guideline2_5_2_5_3 = {
3131
* @param {DOMNode} top The top element of the tested code.
3232
*/
3333
process: function(element, top) {
34-
function getTextContent(el) {
35-
if (el.textContent !== undefined) {
36-
return el.textContent;
37-
} else {
38-
return el.innerText;
39-
}
40-
}
41-
function getAccessibleName(el) {
42-
// See https://www.w3.org/TR/accname-1.1/#terminology
43-
if (el.getAttribute('hidden')) {
44-
return '';
45-
}
46-
else if (el.getAttribute("aria-labelledby")) {
47-
var nameParts = [];
48-
var parts = el.getAttribute("aria-labelledby").split(" ");
49-
for (var i = 0; i < parts.length; i++) {
50-
var x = parts[i];
51-
var nameEl = top.getElementById(x);
52-
if (nameEl) {
53-
nameParts.push(nameEl.textContent);
54-
}
55-
}
56-
return nameParts.join(" ");
57-
} else if (el.getAttribute("aria-label")) {
58-
return el.getAttribute("aria-label");
59-
} else if (el.getAttribute("title")) {
60-
if (
61-
el.getAttribute("role") !== "presentation" &&
62-
el.getAttribute("role") !== "none"
63-
) {
64-
return el.getAttribute("aria-label");
65-
}
66-
}
67-
// Give up - we only test the 3 most obvious cases.
68-
return "";
69-
}
70-
7134
if (element == top) {
7235
HTMLCS.addMessage(
7336
HTMLCS.NOTICE,
@@ -82,30 +45,30 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle2_Guideline2_5_2_5_3 = {
8245
var accessibleName = "";
8346
switch (nodeName) {
8447
case "a":
85-
visibleLabel = getTextContent(element);
86-
accessibleName = getAccessibleName(element);
48+
visibleLabel = HTMLCS.util.getTextContent(element);
49+
accessibleName = HTMLCS.util.getAccessibleName(element);
8750
break;
8851
case "button":
89-
visibleLabel = getTextContent(element);
90-
accessibleName = getAccessibleName(element);
52+
visibleLabel = HTMLCS.util.getTextContent(element);
53+
accessibleName = HTMLCS.util.getAccessibleName(element);
9154
break;
9255
case "label":
93-
visibleLabel = getTextContent(element);
56+
visibleLabel = HTMLCS.util.getTextContent(element);
9457
var labelFor = element.getAttribute("for");
9558
if (labelFor) {
9659
if (top.ownerDocument) {
9760
var refNode = top.ownerDocument.getElementById(labelFor);
9861
} else {
9962
var refNode = top.getElementById(labelFor);
10063
}
101-
accessibleName = getAccessibleName(refNode);
64+
accessibleName = HTMLCS.util.getAccessibleName(refNode);
10265
}
10366
break;
10467
case "input":
10568
if (element.getAttribute("type") === "submit") {
10669
visibleLabel = element.getAttribute("value");
10770
}
108-
accessibleName = getAccessibleName(element);
71+
accessibleName = HTMLCS.util.getAccessibleName(element);
10972
break;
11073
}
11174
if (!!visibleLabel && !!accessibleName) {

Standards/WCAG2AAA/ruleset.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -533,40 +533,46 @@ _global.HTMLCS_WCAG2AAA = {
533533
var techniques = msgCodeParts[4].split(',');
534534
var techniquesStr = [];
535535
function getPrefix(x) {
536-
if (x.startsWith('ARIA')) {
536+
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
537+
function startsWith(str, search, rawPos) {
538+
var pos = rawPos > 0 ? rawPos|0 : 0;
539+
return str.substring(pos, pos + search.length) === search;
540+
}
541+
542+
if (startsWith(x, 'ARIA')) {
537543
return 'aria/';
538544
}
539-
if (x.startsWith('SCR')) {
545+
if (startsWith(x, 'SCR')) {
540546
return 'client-side-script/';
541547
}
542-
if (x.startsWith('C')) {
548+
if (startsWith(x, 'C')) {
543549
return 'css/';
544550
}
545-
if (x.startsWith('FLASH')) {
551+
if (startsWith(x, 'FLASH')) {
546552
return 'flash/';
547553
}
548-
if (x.startsWith('F')) {
554+
if (startsWith(x, 'F')) {
549555
return 'failures/';
550556
}
551-
if (x.startsWith('G')) {
557+
if (startsWith(x, 'G')) {
552558
return 'general/';
553559
}
554-
if (x.startsWith('H')) {
560+
if (startsWith(x, 'H')) {
555561
return 'html/';
556562
}
557-
if (x.startsWith('PDF')) {
563+
if (startsWith(x, 'PDF')) {
558564
return 'pdf/';
559565
}
560-
if (x.startsWith('SVR')) {
566+
if (startsWith(x, 'SVR')) {
561567
return 'server-side-script/';
562568
}
563-
if (x.startsWith('SL')) {
569+
if (startsWith(x, 'SL')) {
564570
return 'silverlight/';
565571
}
566-
if (x.startsWith('SM')) {
572+
if (startsWith(x, 'SM')) {
567573
return 'smil/';
568574
}
569-
if (x.startsWith('T')) {
575+
if (startsWith(x, 'T')) {
570576
return 'text/';
571577
}
572578
return '';

0 commit comments

Comments
 (0)