@qualweb/wcag-techniques
Version:
Implementation of the WCAG 2.1 techniques
51 lines (50 loc) • 2.26 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QW_WCAG_T35 = void 0;
const applicability_1 = require("@qualweb/util/applicability");
const evaluation_1 = require("@qualweb/core/evaluation");
const Technique_object_1 = require("../lib/Technique.object");
class QW_WCAG_T35 extends Technique_object_1.Technique {
constructor() {
super(...arguments);
this.idMap = new Map();
}
execute(element) {
const test = new evaluation_1.Test();
const id = element.getElementAttribute('id');
if (id && !this.idMap.get(id)) {
try {
const elementsWithSameId = window.qwPage.getElements(`[id="${id}"]`, element);
if (elementsWithSameId.length > 1) {
test.verdict = evaluation_1.Verdict.FAILED;
test.resultCode = 'F1';
}
else {
test.verdict = evaluation_1.Verdict.PASSED;
test.resultCode = 'P1';
}
test.addElements(elementsWithSameId);
this.addTestResult(test);
}
finally {
this.idMap.set(id, true);
}
}
}
}
exports.QW_WCAG_T35 = QW_WCAG_T35;
__decorate([
applicability_1.ElementExists,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Function]),
__metadata("design:returntype", void 0)
], QW_WCAG_T35.prototype, "execute", null);