UNPKG

@qualweb/act-rules

Version:

ACT rules module for qualweb web accessibility evaluator

81 lines (80 loc) 3.61 kB
"use strict"; 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_R74 = 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_R74 extends AtomicRule_object_1.AtomicRule { execute(element) { var _a, _b; const test = new evaluation_1.Test(); let hasLinks = false; const links = window.qwPage.getElements('a'); if (links) { const host = location.hostname; const linksWithAnchors = new Array(); 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)) { linksWithAnchors.push(link); } else if (href && (href.startsWith('/') || href.startsWith('.') || href.startsWith(host))) { hasLinks = true; } } } if (hasLinks) { let nSkipLinks = 0; for (const anchor of linksWithAnchors) { const href = (_b = anchor.getElementAttribute('href')) === null || _b === void 0 ? void 0 : _b.trim(); if (href) { const id = href.split('#')[1]; if (window.qwPage.getElementByID(id)) { nSkipLinks++; } } } if (nSkipLinks > 0) { test.verdict = evaluation_1.Verdict.WARNING; test.resultCode = 'W1'; } else { test.verdict = evaluation_1.Verdict.WARNING; test.resultCode = 'W2'; } } } 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_R74 = QW_ACT_R74; __decorate([ applicability_1.ElementExists, applicability_1.IsHTMLDocument, applicability_1.IsInMainContext, __metadata("design:type", Function), __metadata("design:paramtypes", [Function]), __metadata("design:returntype", void 0) ], QW_ACT_R74.prototype, "execute", null);