@qualweb/act-rules
Version:
ACT rules module for qualweb web accessibility evaluator
61 lines (60 loc) • 2.76 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_ACT_R73 = void 0;
const applicability_1 = require("@qualweb/util/applicability");
const evaluation_1 = require("@qualweb/core/evaluation");
const AtomicRule_object_1 = require("../lib/AtomicRule.object");
class QW_ACT_R73 extends AtomicRule_object_1.AtomicRule {
execute(element) {
var _a;
const test = new evaluation_1.Test();
let hasLinks = false;
const links = element.getElements('a');
if (links) {
const host = location.hostname;
for (const link of links) {
if (link.elementHasAttribute('href')) {
const href = (_a = link.getElementAttribute('href')) === null || _a === void 0 ? void 0 : _a.trim();
if (href &&
!this.checkDestination(href) &&
(href.startsWith('/') || href.startsWith('.') || href.startsWith(host))) {
test.verdict = evaluation_1.Verdict.WARNING;
test.resultCode = 'W1';
hasLinks = true;
break;
}
}
}
}
if (!hasLinks) {
test.verdict = evaluation_1.Verdict.PASSED;
test.resultCode = 'P1';
}
test.addElement(element, false);
this.addTestResult(test);
}
checkDestination(destination) {
const url = window.qwPage.getURL();
return (destination.startsWith('#') ||
destination.startsWith('/#') ||
destination.startsWith(url + '#') ||
destination.startsWith(url + '/#'));
}
}
exports.QW_ACT_R73 = QW_ACT_R73;
__decorate([
applicability_1.ElementExists,
applicability_1.IsHTMLDocument,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Function]),
__metadata("design:returntype", void 0)
], QW_ACT_R73.prototype, "execute", null);