-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha11y.js
1 lines (1 loc) · 4.23 KB
/
a11y.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("a11yChecker",[],t):"object"==typeof exports?exports.a11yChecker=t():e.a11yChecker=t()}(window,function(){return function(e){var t={};function i(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(n,o,function(t){return e[t]}.bind(null,o));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="/dist/",i(i.s=0)}([function(e,t,i){"use strict";i.r(t);const n=e=>console.warn(e),o=e=>""===e.trim(),r=e=>document.querySelectorAll(e),a=(e,t)=>e.hasAttribute(t),l=(e,t)=>e.getAttribute(t),s=document.doctype,u=document.title,d=e=>a(e,"aria-label")||a(e,"aria-labelledby"),c=e=>0===e.textTracks.length,m=()=>{const e=(e=>document.querySelector(e))("html");if(a(e,"lang")){const t=l(e,"lang");o(t)&&n('Language value is missing in HTML element. Fix: Add lang="LANGUAGE VALUE" to <html>')}else n('Language is missing in HTML element. Fix: Add lang="LANGUAGE VALUE" to <html>')};t.default=(()=>{s||n("Doctype is missing. Fix: Add <!DOCTYPE html>"),o(u)&&n("Title is missing. Fix: <title>WELL DESCRIBED TITLE</title>"),m(),[...r("meta")].some(e=>a(e,"charset"))||n('Document encoding is missing. Fix: Add <meta charset="utf-8"/>'),[...r("meta")].some(e=>"no"===l(e,"user-scalable"))&&n("Document must not use the user-scalable=no. Fix: Remove user-scalable=no from <meta name=viewport>"),r("h1").length>1&&n("Page has Multi <h1> tag. Fix: use only one <h1> in the page."),(()=>{const e=[...r("img")].filter(e=>!a(e,"alt"));e.length,e.forEach(e=>n(`Image Alt is missing. Fix: Add alt="IMAGE WELL DESCRIBED" to ${e.outerHTML}`))})(),(()=>{const e=[...r("a")],t=e.filter(e=>o(e.textContent)&&!d(e));t.length,t.forEach(e=>n(`Link text is missing. Fix: DESCRIBE PURPOSE OF LINK to ${e.outerHTML}`))})(),(()=>{const e=[...r("a")].filter(e=>(!a(e,"href")||o(l(e,"href")))&&!a(e,"role"));e.length,e.forEach(e=>n(`Link Href is missing. Fix: Add href="LINK URL" to ${e.outerHTML}`))})(),(()=>{const e=[...r("a")],t=e.filter(e=>"_blank"===l(e,"target")&&!a(e,"aria-describedby"));t.length,t.forEach(e=>n(`Hint message is missing. Should add hint message to recognize this link will open in new tab. Fix: Add aria-describedby="ELEMENT ID" to ${e.outerHTML}`))})(),(()=>{const e=[...r("button")],t=e.filter(e=>o(e.textContent)&&!d(e));t.length,t.forEach(e=>n(`Button text or aria-label is missing. Fix: Add aria-label="VALUE" or <button>VALUE</button> to ${e.outerHTML}`))})(),[...r("SVG")].some(e=>"true"!==l(e,"aria-hidden")&&!a(e,"role")&&!l(e,"id"))&&n('SVG Role is missing. Fix: Add role="img" or (aria-hidden="true" if you need to hide element from SR).'),[...r("iframe")].some(e=>!a(e,"title"))&&n('Title is missing in iframe. Fix: Add title="DESCRIBE CONTENT OF FRAME" to <iframe>'),[...r("form")].some(e=>!d(e))&&n("Forms Label is missing. Fix: Add aria-label, aria-labelledby to <form>"),[...r("label")].forEach(e=>{a(e,"for")&&!o(l(e,"for"))||n(`For is missing in label. Fix: Add for="INPUT ID" to ${e.outerHTML}`)}),[...r("video")].some(c)&&n("Video track is missing. Fix: Add <track> element with subtitles, captions to >video>"),[...r("audio")].some(c)&&n("Audio track is missing. Fix: Add <track> element with subtitles, captions to <audio>"),[...r("*")].filter(e=>l(e,"tabindex")>0).length>0&&n('Avoid using positive integer values for tabindex. Fix: Remove/Replace tabindex=">0" '),(()=>{const e=[...r("*")].map(e=>l(e,"id")).filter(e=>!(e=>null===e)(e)),t=[...new Set(e)];e.length>t.length&&n("Avoid duplicate ids, ID must be unique. Fix: Remove/Replace duplicate id")})()})}])});