UNPKG

@qualweb/wcag-techniques

Version:
61 lines (60 loc) 2.66 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_WCAG_T10 = 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_T10 extends Technique_object_1.Technique { execute(element) { const test = new evaluation_1.Test(); const images = element.getElements('img'); const text = element.getElementText(); const hasImage = images.length > 0; let hasNonEmptyAlt = false; let hasAlt = false; let equalAltText = false; for (const img of images || []) { if (img.elementHasAttribute('alt') && !hasNonEmptyAlt && !equalAltText) { hasAlt = true; const alt = img.getElementAttribute('alt'); if (alt !== null) { hasNonEmptyAlt = alt.trim() !== ''; equalAltText = !!text && alt.trim() === text.trim(); } } } if (!hasImage || !hasAlt || !text || text.trim() === '') { return; } else if (!hasNonEmptyAlt) { test.verdict = evaluation_1.Verdict.PASSED; test.resultCode = 'P1'; } else if (equalAltText) { test.verdict = evaluation_1.Verdict.FAILED; test.resultCode = 'F1'; } else { test.verdict = evaluation_1.Verdict.WARNING; test.resultCode = 'W1'; } test.addElement(element); this.addTestResult(test); } } exports.QW_WCAG_T10 = QW_WCAG_T10; __decorate([ applicability_1.ElementExists, __metadata("design:type", Function), __metadata("design:paramtypes", [Function]), __metadata("design:returntype", void 0) ], QW_WCAG_T10.prototype, "execute", null);