OAA HEADING_10: The content of the headings of the same level within the same section should be unique.
Rulesets
- WCAG 2.0 Requirement 2.4.6 Headings and Labels
- Status: Accepted
- Severity: Recommendation
- Priority: Priority 1
- IITAA 1.0 1.4 Use headings to introduce sections and sub-sections, and use them in the correct order.
- Type:
- Severity: Violation
- Priority: Priority 1
- Status: Accepted
Markup References
Validation Code
Message
The content of the headings of the same level within the same section should be unique.
Dependencies
None
Context
document
Parameters
None
Code
function (ruleContext) {
var loadArray = new Array();
var xpathResult = ruleContext.evaluate("//h1|//h2|//h3|//h4|//h5|//h6", ruleContext, util.defaultNSResolver, XPathResult.ANY_TYPE, null);
var r = xpathResult.iterateNext();
while (r) {
loadArray[loadArray.length] = {node: r, text: util.getNodeTextRecursively(r).toLowerCase(), level: r.tagName.charAt(1), siblingDupName: false};
r = xpathResult.iterateNext();
} // endwhile
for (var i=0, j=0, n=loadArray.length; i<n; i++) {
for (j=i+1; j<n; j++) {
if (loadArray[i].level == loadArray[j].level) {
if (loadArray[i].text==loadArray[j].text) {
//determine if siblings
var sibs = true;
for (var k=j; k > i && sibs; k--) {
if (loadArray[j].level != loadArray[k].level) { sibs = false;}
} // endfor
if (sibs) {
loadArray[i].siblingDupName=loadArray[j].siblingDupName=true;
} // endif
} // endif
} // endif
} // endfor
} // endfor
var sibDupArray = new Array();
for (var i=0; i<loadArray.length; i++) {
if (loadArray[i].siblingDupName) {
sibDupArray.push(loadArray[i].node);
} // endif
} // endfor
var passed = (sibDupArray.length==0);
return new ValidationResult(passed, sibDupArray, [], '', []);
} // endfunction
>
var loadArray = new Array();
var xpathResult = ruleContext.evaluate("//h1|//h2|//h3|//h4|//h5|//h6", ruleContext, util.defaultNSResolver, XPathResult.ANY_TYPE, null);
var r = xpathResult.iterateNext();
while (r) {
loadArray[loadArray.length] = {node: r, text: util.getNodeTextRecursively(r).toLowerCase(), level: r.tagName.charAt(1), siblingDupName: false};
r = xpathResult.iterateNext();
} // endwhile
for (var i=0, j=0, n=loadArray.length; i<n; i++) {
for (j=i+1; j<n; j++) {
if (loadArray[i].level == loadArray[j].level) {
if (loadArray[i].text==loadArray[j].text) {
//determine if siblings
var sibs = true;
for (var k=j; k > i && sibs; k--) {
if (loadArray[j].level != loadArray[k].level) { sibs = false;}
} // endfor
if (sibs) {
loadArray[i].siblingDupName=loadArray[j].siblingDupName=true;
} // endif
} // endif
} // endif
} // endfor
} // endfor
var sibDupArray = new Array();
for (var i=0; i<loadArray.length; i++) {
if (loadArray[i].siblingDupName) {
sibDupArray.push(loadArray[i].node);
} // endif
} // endfor
var passed = (sibDupArray.length==0);
return new ValidationResult(passed, sibDupArray, [], '', []);
} // endfunction
>